Skip to content

Commit

Permalink
update admin page to check admin permissions & show no permission-states
Browse files Browse the repository at this point in the history
  • Loading branch information
datadanne committed Sep 19, 2023
1 parent 070581c commit c0b447c
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions garage/src/pages/Admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
Th,
Tbody,
HStack,
Spinner,
Text,
} from "@chakra-ui/react";
import { Link } from "react-router-dom";
import { Database } from "@tableland/sdk";
Expand All @@ -33,6 +35,7 @@ import { CreateProposalModal } from "../../components/CreateProposalModal";
import { useProposals } from "../../hooks/useProposals";
import { useAdminMisisons } from "../../hooks/useMissions";
import { secondaryChain, deployment } from "../../env";
import { useIsAdmin } from "../../hooks/useIsAdmin";

const { ftRewardsTable } = deployment;

Expand Down Expand Up @@ -274,7 +277,24 @@ const ListMissionsForm = (props: React.ComponentProps<typeof Box>) => {
);
};

const NoPermissionsForm = ({
title,
body,
...props
}: { title: string; body: string } & React.ComponentProps<typeof Box>) => {
return (
<Box {...props}>
<Heading>{title}</Heading>
<Text variant="emptyState" mt={4}>
{body}
</Text>
</Box>
);
};

export const Admin = () => {
const { isLoading, data } = useIsAdmin();

return (
<>
<Flex
Expand All @@ -295,9 +315,31 @@ export const Admin = () => {
minHeight={`calc(100vh - ${TOPBAR_HEIGHT})`}
>
<Flex direction="column" gap={GRID_GAP} align="stretch" width="100%">
<GiveFtRewardForm {...MODULE_PROPS} />
<ListProposalsForm {...MODULE_PROPS} />
<ListMissionsForm {...MODULE_PROPS} />
{isLoading || !data ? (
<Spinner />
) : (
<>
<GiveFtRewardForm {...MODULE_PROPS} />
{data.votingAdmin ? (
<ListProposalsForm {...MODULE_PROPS} />
) : (
<NoPermissionsForm
title="Proposals"
body="You don't have the right permissions to manage proposals."
{...MODULE_PROPS}
/>
)}
{data.missionsAdin ? (
<ListMissionsForm {...MODULE_PROPS} />
) : (
<NoPermissionsForm
title="Missions"
body="You don't have the right permissions to manage missions."
{...MODULE_PROPS}
/>
)}
</>
)}
</Flex>
</Flex>
</Flex>
Expand Down

0 comments on commit c0b447c

Please sign in to comment.