Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): wait until project-id gets loaded #2307

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions agenta-web/src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {ThemeProvider} from "react-jss"
import {JSSTheme, StyleProps as MainStyleProps} from "@/lib/Types"
import {Lightning} from "@phosphor-icons/react"
import packageJsonData from "../../../package.json"
import {useProjectData} from "@/contexts/project.context"

const {Content, Footer} = Layout
const {Text} = Typography
Expand Down Expand Up @@ -85,6 +86,7 @@ const App: React.FC<LayoutProps> = ({children}) => {
const {appTheme} = useAppTheme()
const {currentApp} = useAppsData()
const [footerRef, {height: footerHeight}] = useElementSize()
const {isProjectId} = useProjectData()
const classes = useStyles({themeMode: appTheme, footerHeight} as StyleProps)
const router = useRouter()
const appId = router.query.app_id as string
Expand Down Expand Up @@ -161,19 +163,22 @@ const App: React.FC<LayoutProps> = ({children}) => {
// wait unitl we have the app id, if its an app route
if (isAppRoute && (!appId || !currentApp)) return null

const isAuthRoute =
router.pathname.includes("/auth") || router.pathname.includes("/post-signup")

return (
<NoSSRWrapper>
{typeof window === "undefined" ? null : (
<ThemeProvider theme={{...token, isDark: isDarkTheme}}>
{router.pathname.includes("/auth") ||
router.pathname.includes("/post-signup") ? (
{isAuthRoute || !isProjectId ? (
<Layout className={classes.layout}>
<ErrorBoundary FallbackComponent={ErrorFallback}>
{children}
{contextHolder}
</ErrorBoundary>
</Layout>
) : (
// !isAuthRoute && isProjectId
<Layout hasSider className={classes.layout}>
<Sidebar />
<Layout className={classes.layout}>
Expand Down
6 changes: 3 additions & 3 deletions agenta-web/src/contexts/project.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getCurrentProject = () => projectContextValues
const ProjectContextProvider: React.FC<PropsWithChildren> = ({children}) => {
const [project, setProject] = useStateCallback<Project | null>(null)
const [useOrgData, setUseOrgData] = useState<Function>(() => () => "")
const [isLoading, setIsLoading] = useState(false)
const [isLoading, setIsLoading] = useState(true)
const {doesSessionExist} = useSession()

useEffect(() => {
Expand All @@ -57,7 +57,7 @@ const ProjectContextProvider: React.FC<PropsWithChildren> = ({children}) => {

const workspaceId: string = selectedOrg?.default_workspace.id || DEFAULT_UUID

const isProjectId = !isLoading && Boolean(project?.project_id)
const isProjectId = !isLoading && !!project?.project_id
const projectId = (project?.project_id as string) || DEFAULT_UUID

const fetcher = async (onSuccess?: () => void) => {
Expand Down Expand Up @@ -103,7 +103,7 @@ const ProjectContextProvider: React.FC<PropsWithChildren> = ({children}) => {
refetch: fetcher,
}}
>
{children}
{isProjectId ? children : null}
</ProjectContext.Provider>
)
}
Expand Down
Loading