From ae1f4b6da4357167e087ca05d5134f250ac09192 Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Sat, 19 Aug 2023 08:45:09 +0200 Subject: [PATCH] feat: allow logout on pending page --- apps/client/src/components/shared/nav/Nav.tsx | 99 ++++++++++--------- .../shared/nav/dropdowns/AccountDropdown.tsx | 14 ++- apps/client/src/pages/auth/pending.tsx | 13 ++- 3 files changed, 73 insertions(+), 53 deletions(-) diff --git a/apps/client/src/components/shared/nav/Nav.tsx b/apps/client/src/components/shared/nav/Nav.tsx index 34776470f..6d8472762 100644 --- a/apps/client/src/components/shared/nav/Nav.tsx +++ b/apps/client/src/components/shared/nav/Nav.tsx @@ -21,9 +21,10 @@ import { AdminLink } from "./dropdowns/admin-link"; interface Props { maxWidth?: string; + isAccountPending?: boolean; } -export function Nav({ maxWidth }: Props) { +export function Nav({ maxWidth, isAccountPending }: Props) { const [menuOpen, setMenuOpen] = React.useState(false); const { user, cad } = useAuth(); @@ -89,56 +90,58 @@ export function Nav({ maxWidth }: Props) { -
- - - {hasPermissions([Permissions.ViewTowCalls, Permissions.ManageTowCalls]) && TOW ? ( - - ) : null} - - {hasPermissions(defaultPermissions.defaultLeoPermissions) ? ( - - ) : null} - - {hasPermissions([Permissions.EmsFd]) ? : null} - - {hasPermissions([Permissions.LiveMap, Permissions.Dispatch]) ? ( - - ) : null} - - {user && COURTHOUSE ? ( - - {t("courthouse")} - - ) : null} - - {hasPermissions([ - ...defaultPermissions.allDefaultAdminPermissions, - ...defaultPermissions.defaultCourthousePermissions, - Permissions.ManageAwardsAndQualifications, - ]) ? ( - - ) : null} -
+ {isAccountPending ? null : ( +
+ + + {hasPermissions([Permissions.ViewTowCalls, Permissions.ManageTowCalls]) && TOW ? ( + + ) : null} + + {hasPermissions(defaultPermissions.defaultLeoPermissions) ? ( + + ) : null} + + {hasPermissions([Permissions.EmsFd]) ? : null} + + {hasPermissions([Permissions.LiveMap, Permissions.Dispatch]) ? ( + + ) : null} + + {user && COURTHOUSE ? ( + + {t("courthouse")} + + ) : null} + + {hasPermissions([ + ...defaultPermissions.allDefaultAdminPermissions, + ...defaultPermissions.defaultCourthousePermissions, + Permissions.ManageAwardsAndQualifications, + ]) ? ( + + ) : null} +
+ )}
- +
diff --git a/apps/client/src/components/shared/nav/dropdowns/AccountDropdown.tsx b/apps/client/src/components/shared/nav/dropdowns/AccountDropdown.tsx index 9ceb506e2..1488ee7bf 100644 --- a/apps/client/src/components/shared/nav/dropdowns/AccountDropdown.tsx +++ b/apps/client/src/components/shared/nav/dropdowns/AccountDropdown.tsx @@ -21,7 +21,11 @@ const ChangelogModal = dynamic(async () => (await import("../changelog-modal")). ssr: false, }); -export function AccountDropdown() { +interface AccountDropdownProps { + isAccountPending?: boolean; +} + +export function AccountDropdown(props: AccountDropdownProps) { const [isOpen, setOpen] = React.useState(false); const { user, setUser, cad } = useAuth(); @@ -55,8 +59,12 @@ export function AccountDropdown() { - {t("account")} -
+ {props.isAccountPending ? null : ( + <> + {t("account")} +
+ + )} {t("logout")}
diff --git a/apps/client/src/pages/auth/pending.tsx b/apps/client/src/pages/auth/pending.tsx index f3d9fe564..be5335c3e 100644 --- a/apps/client/src/pages/auth/pending.tsx +++ b/apps/client/src/pages/auth/pending.tsx @@ -13,6 +13,7 @@ import { useFeatureEnabled } from "hooks/useFeatureEnabled"; import { Discord, Steam } from "react-bootstrap-icons"; import { getAPIUrl } from "@snailycad/utils/api-url"; import { useRouter } from "next/router"; +import { Nav } from "components/shared/nav/Nav"; export default function AccountPendingPage() { const { user, cad } = useAuth(); @@ -21,8 +22,14 @@ export default function AccountPendingPage() { const t = useTranslations("Auth"); const { DISCORD_AUTH, STEAM_OAUTH } = useFeatureEnabled(); - if (user?.rank !== Rank.OWNER && user?.whitelistStatus !== WhitelistStatus.PENDING) { - return
This account is not pending access.
; + const isAccountPending = + user?.rank !== Rank.OWNER && user?.whitelistStatus === WhitelistStatus.PENDING; + if (!isAccountPending) { + return ( +
+ This account is not pending access. +
+ ); } const rawSuccessMessage = router.query.success as string | undefined; @@ -52,6 +59,8 @@ export default function AccountPendingPage() { return ( <> +