Skip to content

Commit

Permalink
feat: allow logout on pending page
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Aug 19, 2023
1 parent 8ae798d commit ae1f4b6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 53 deletions.
99 changes: 51 additions & 48 deletions apps/client/src/components/shared/nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -89,56 +90,58 @@ export function Nav({ maxWidth }: Props) {
</a>
</h1>

<div
role="list"
className={classNames(
"nav:flex",
menuOpen
? "grid place-content-center fixed top-[3.6rem] left-0 bg-white dark:bg-tertiary w-screen space-y-2 py-3 animate-enter"
: "hidden nav:flex-row space-x-1 items-center",
)}
>
<CitizenDropdown />

{hasPermissions([Permissions.ViewTowCalls, Permissions.ManageTowCalls]) && TOW ? (
<TowDropdown />
) : null}

{hasPermissions(defaultPermissions.defaultLeoPermissions) ? (
<OfficerDropdown />
) : null}

{hasPermissions([Permissions.EmsFd]) ? <EmsFdDropdown /> : null}

{hasPermissions([Permissions.LiveMap, Permissions.Dispatch]) ? (
<DispatchDropdown />
) : null}

{user && COURTHOUSE ? (
<Link
role="listitem"
href="/courthouse"
className={classNames(
"p-1 nav:px-2 text-gray-700 dark:text-gray-200 transition duration-300",
isActive("/courthouse") && "font-semibold",
)}
>
{t("courthouse")}
</Link>
) : null}

{hasPermissions([
...defaultPermissions.allDefaultAdminPermissions,
...defaultPermissions.defaultCourthousePermissions,
Permissions.ManageAwardsAndQualifications,
]) ? (
<AdminLink />
) : null}
</div>
{isAccountPending ? null : (
<div
role="list"
className={classNames(
"nav:flex",
menuOpen
? "grid place-content-center fixed top-[3.6rem] left-0 bg-white dark:bg-tertiary w-screen space-y-2 py-3 animate-enter"
: "hidden nav:flex-row space-x-1 items-center",
)}
>
<CitizenDropdown />

{hasPermissions([Permissions.ViewTowCalls, Permissions.ManageTowCalls]) && TOW ? (
<TowDropdown />
) : null}

{hasPermissions(defaultPermissions.defaultLeoPermissions) ? (
<OfficerDropdown />
) : null}

{hasPermissions([Permissions.EmsFd]) ? <EmsFdDropdown /> : null}

{hasPermissions([Permissions.LiveMap, Permissions.Dispatch]) ? (
<DispatchDropdown />
) : null}

{user && COURTHOUSE ? (
<Link
role="listitem"
href="/courthouse"
className={classNames(
"p-1 nav:px-2 text-gray-700 dark:text-gray-200 transition duration-300",
isActive("/courthouse") && "font-semibold",
)}
>
{t("courthouse")}
</Link>
) : null}

{hasPermissions([
...defaultPermissions.allDefaultAdminPermissions,
...defaultPermissions.defaultCourthousePermissions,
Permissions.ManageAwardsAndQualifications,
]) ? (
<AdminLink />
) : null}
</div>
)}
</div>

<div>
<AccountDropdown />
<AccountDropdown isAccountPending={isAccountPending} />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -55,8 +59,12 @@ export function AccountDropdown() {
</DropdownMenuTrigger>

<DropdownMenuContent className="mt-2.5" side="left">
<DropdownMenuLinkItem href="/account">{t("account")}</DropdownMenuLinkItem>
<hr className="my-2 mx-2 border-t border-secondary dark:border-quinary" />
{props.isAccountPending ? null : (
<>
<DropdownMenuLinkItem href="/account">{t("account")}</DropdownMenuLinkItem>
<hr className="my-2 mx-2 border-t border-secondary dark:border-quinary" />
</>
)}
<DropdownMenuItem onClick={handleLogout}>{t("logout")}</DropdownMenuItem>
<hr className="my-2 mx-2 border-t border-secondary dark:border-quinary" />

Expand Down
13 changes: 11 additions & 2 deletions apps/client/src/pages/auth/pending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 <main className="flex justify-center pt-20">This account is not pending access.</main>;
const isAccountPending =
user?.rank !== Rank.OWNER && user?.whitelistStatus === WhitelistStatus.PENDING;
if (!isAccountPending) {
return (
<main className="flex justify-center pt-20 dark:text-white">
This account is not pending access.
</main>
);
}

const rawSuccessMessage = router.query.success as string | undefined;
Expand Down Expand Up @@ -52,6 +59,8 @@ export default function AccountPendingPage() {

return (
<>
<Nav isAccountPending={isAccountPending} />

<Title renderLayoutTitle={false}>{t("accountPending")}</Title>

<main className="flex flex-col items-center justify-center pt-20">
Expand Down

0 comments on commit ae1f4b6

Please sign in to comment.