Skip to content

Commit

Permalink
feat: PlatformAdminOnly component
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jul 11, 2024
1 parent b8da414 commit bbb83fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions editor.planx.uk/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
LINE_HEIGHT_BASE,
} from "theme";
import { ApplicationPath } from "types";
import { PlatformAdminOnly } from "ui/editor/permissions/PlatformAdminOnly";
import Reset from "ui/icons/Reset";

import { useStore } from "../pages/FlowEditor/lib/store";
Expand Down Expand Up @@ -531,14 +532,14 @@ const EditorToolbar: React.FC<{
</ListItemText>
</MenuItem>
)}
{!user.isPlatformAdmin && (
<PlatformAdminOnly>
<MenuItem disabled divider>
<ListItemIcon>
<Visibility />
</ListItemIcon>
<ListItemText>All teams</ListItemText>
</MenuItem>
)}
</PlatformAdminOnly>

{/* Only show team settings link if inside a team route */}
{isTeamSettingsVisible && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { AxiosError } from "axios";
import { formatLastPublishMessage } from "pages/FlowEditor/utils";
import React, { useState } from "react";
import { useAsync } from "react-use";
import { PlatformAdminOnly } from "ui/editor/permissions/PlatformAdminOnly";
import Input from "ui/shared/Input";

import Questions from "../../../Preview/Questions";
Expand Down Expand Up @@ -163,7 +164,6 @@ const Sidebar: React.FC<{
lastPublisher,
validateAndDiffFlow,
isFlowPublished,
isPlatformAdmin,
] = useStore((state) => [
state.id,
state.flowAnalyticsLink,
Expand All @@ -173,7 +173,6 @@ const Sidebar: React.FC<{
state.lastPublisher,
state.validateAndDiffFlow,
state.isFlowPublished,
state.user?.isPlatformAdmin,
]);
const [key, setKey] = useState<boolean>(false);
const [lastPublishedTitle, setLastPublishedTitle] = useState<string>(
Expand Down Expand Up @@ -297,7 +296,7 @@ const Sidebar: React.FC<{
</Tooltip>
)}

{isPlatformAdmin && (
<PlatformAdminOnly>
<Tooltip arrow title="Open draft service">
<Link
href={props.url.replace("/published", "/draft")}
Expand All @@ -308,7 +307,7 @@ const Sidebar: React.FC<{
<OpenInNewOffIcon />
</Link>
</Tooltip>
)}
</PlatformAdminOnly>

<Tooltip arrow title="Open preview of changes to publish">
<Link
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useStore } from "pages/FlowEditor/lib/store";
import React, { PropsWithChildren } from "react";

export const PlatformAdminOnly: React.FC<PropsWithChildren> = ({
children,
}) => {
const isPlatformAdmin = useStore((state) => state.user?.isPlatformAdmin);
return isPlatformAdmin ? children : null;
};

0 comments on commit bbb83fb

Please sign in to comment.