Skip to content

Commit f1ca44f

Browse files
Fix admin modal submit and gate init when Clerk auth
1 parent 76a8e22 commit f1ca44f

3 files changed

Lines changed: 43 additions & 13 deletions

File tree

src/frontend/src/modals/userManagementModal/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ export default function UserManagementModal({
360360
</Button>
361361

362362
<Form.Submit asChild>
363-
<Button className="mt-8">{confirmationText}</Button>
363+
<Button className="mt-8" type="submit">
364+
{confirmationText}
365+
</Button>
364366
</Form.Submit>
365367
</div>
366368
</Form.Root>

src/frontend/src/pages/AppInitPage/index.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import useAuthStore from "@/stores/authStore";
2020
export function AppInitPage() {
2121
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
2222
const { pathname } = useLocation();
23+
const isClerkAuth = IS_CLERK_AUTH;
2324

2425
const refreshStars = useDarkStore((state) => state.refreshStars);
2526
const refreshDiscordCount = useDarkStore((state) => state.refreshDiscordCount);
@@ -35,27 +36,28 @@ export function AppInitPage() {
3536

3637
// Skip the initialization queries when unauthenticated visitors load the
3738
// unauthenticated marketing landing page rendered at the root route.
38-
const skipAppInit = !isAuthenticated && pathname === "/";
39+
const skipAppInit = !isAuthenticated && pathname === "/";
40+
const waitForClerkAuth = isClerkAuth && !isAuthenticated;
3941

40-
const shouldSkipAutoLogin = IS_CLERK_AUTH;
42+
const shouldSkipAutoLogin = isClerkAuth;
4143

4244
const { isFetched: isAutoLoginFetched, refetch: refetchAutoLogin } = useGetAutoLogin({
43-
enabled: !shouldSkipAutoLogin && isLoaded && !shouldSkip && !skipAppInit,
45+
enabled: !shouldSkipAutoLogin && isLoaded && !shouldSkip && !skipAppInit && !waitForClerkAuth,
4446
});
4547

4648
const isFetched = shouldSkipAutoLogin ? true : isAutoLoginFetched;
4749

4850
const { isFetched: isConfigFetched } = useGetConfig({
49-
enabled: isFetched && !shouldSkip && !skipAppInit,
51+
enabled: isFetched && !shouldSkip && !skipAppInit && !waitForClerkAuth,
5052
});
5153

52-
useGetVersionQuery({ enabled: isFetched && !shouldSkip && !skipAppInit });
53-
useGetGlobalVariables({ enabled: isFetched && !shouldSkip && !skipAppInit });
54-
useGetTagsQuery({ enabled: isFetched && !shouldSkip && !skipAppInit });
55-
useGetFoldersQuery({ enabled: isFetched && !shouldSkip && !skipAppInit });
54+
useGetVersionQuery({ enabled: isFetched && !shouldSkip && !skipAppInit && !waitForClerkAuth });
55+
useGetGlobalVariables({ enabled: isFetched && !shouldSkip && !skipAppInit && !waitForClerkAuth });
56+
useGetTagsQuery({ enabled: isFetched && !shouldSkip && !skipAppInit && !waitForClerkAuth });
57+
useGetFoldersQuery({ enabled: isFetched && !shouldSkip && !skipAppInit && !waitForClerkAuth });
5658

5759
const { isFetched: isExamplesFetched, refetch: refetchExamples } = useGetBasicExamplesQuery({
58-
enabled: !shouldSkip && !skipAppInit,
60+
enabled: !shouldSkip && !skipAppInit && !waitForClerkAuth,
5961
});
6062

6163
useEffect(() => {
@@ -67,16 +69,22 @@ export function AppInitPage() {
6769
refreshDiscordCount();
6870
}
6971

70-
if (isConfigFetched && !shouldSkip) {
71-
refetchAutoLogin();
72+
if (isConfigFetched && !shouldSkip && !waitForClerkAuth) {
73+
if (!shouldSkipAutoLogin) {
74+
refetchAutoLogin();
75+
}
7276
refetchExamples();
7377
}
74-
}, [isFetched, isConfigFetched, shouldSkip, skipAppInit]);
78+
}, [isFetched, isConfigFetched, shouldSkip, skipAppInit, waitForClerkAuth]);
7579

7680
if (skipAppInit) {
7781
return <Outlet />;
7882
}
7983

84+
if (waitForClerkAuth) {
85+
return <CustomLoadingPage />;
86+
}
87+
8088
return (
8189
//need parent component with width and height
8290
<>

src/frontend/src/pages/SettingsPage/index.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,26 @@ const SettingsPageWithClerk = () => {
176176
};
177177

178178
const SettingsPageWithoutClerk = () => <SettingsPageBase />;
179+
const SettingsPageWithoutClerk = () => {
180+
const isAdmin = useAuthStore((state) => state.isAdmin);
181+
182+
const additionalNavItems: SidebarNavItem[] = isAdmin
183+
? [
184+
{
185+
title: "Admin",
186+
href: "/admin",
187+
icon: (
188+
<ForwardedIconComponent
189+
name="Shield"
190+
className="w-4 flex-shrink-0 justify-start stroke-[1.5]"
191+
/>
192+
),
193+
},
194+
]
195+
: [];
196+
197+
return <SettingsPageBase additionalNavItems={additionalNavItems} />;
198+
};
179199

180200
export default function SettingsPage(): JSX.Element {
181201
if (IS_CLERK_AUTH) {

0 commit comments

Comments
 (0)