Skip to content

Commit

Permalink
Hide non admin dropdown options
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogasp committed Nov 19, 2024
1 parent 6fd045b commit b96b6f0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
39 changes: 15 additions & 24 deletions src/app/(pages)/users/[user]/components/Info/OptionsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { RequestAUPSignature } from "./RequestAUPSignature";
type OptionsDropdownProps = {
user: User;
isAdmin?: boolean;
isMe?: boolean;
};

type ModalsState = {
Expand Down Expand Up @@ -95,7 +96,7 @@ function reducer(state: ModalsState, action: Action) {
}

export default function OptionsDropdown(props: Readonly<OptionsDropdownProps>) {
const { user, isAdmin } = props;
const { user, isAdmin, isMe } = props;
const [state, dispatch] = useReducer(reducer, initialState);
const indigoUser = user["urn:indigo-dc:scim:schemas:IndigoUser"];
const hasRoleAdmin = indigoUser?.authorities?.includes("ROLE_ADMIN");
Expand Down Expand Up @@ -163,16 +164,7 @@ export default function OptionsDropdown(props: Readonly<OptionsDropdownProps>) {
Change membership end time
</button>
</MenuItem>
<MenuItem>
<button
type="button"
className="flex gap-2"
onClick={() => dispatch({ type: "openSignAUP" })}
>
<DocumentTextIcon className="w-5" />
Sign AUP on behalf of this user
</button>
</MenuItem>

<MenuItem>
<button
type="button"
Expand All @@ -184,19 +176,17 @@ export default function OptionsDropdown(props: Readonly<OptionsDropdownProps>) {
</button>
</MenuItem>
</>
) : (
<MenuItem>
<button
type="button"
className="flex gap-2"
onClick={() => console.log("to implement")}
>
<DocumentTextIcon className="w-5" />
Sign AUP
</button>
</MenuItem>
)}

) : null}
<MenuItem>
<button
type="button"
className="flex gap-2"
onClick={() => dispatch({ type: "openSignAUP" })}
>
<DocumentTextIcon className="w-5" />
{isMe ? "Sign AUP" : "Sign AUP on behalf of this user"}
</button>
</MenuItem>
<MenuItem>
<button
type="button"
Expand Down Expand Up @@ -236,6 +226,7 @@ export default function OptionsDropdown(props: Readonly<OptionsDropdownProps>) {
<SignAUPModal
user={user}
show={state.showSignAUP}
isMe={isMe}
onClose={() => dispatch({ type: "closeSignAUP" })}
/>
<RequestAUPSignature
Expand Down
15 changes: 11 additions & 4 deletions src/app/(pages)/users/[user]/components/Info/SignAUP/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { signAUP } from "@/services/users";

interface SignAUPProps extends ModalProps {
user: User;
isMe?: boolean;
}

export function SignAUPModal(props: Readonly<SignAUPProps>) {
const { user } = props;
const { user, isMe } = props;
const action = async () => {
signAUP(user.id);
props.onClose();
Expand All @@ -17,11 +18,17 @@ export function SignAUPModal(props: Readonly<SignAUPProps>) {
return (
<ConfirmModal
{...props}
title="Sign AUP in behalf of the user"
title={isMe ? "Resign AUP" : "Sign AUP in behalf of the user"}
onConfirm={action}
>
Are you sure you want to sign the AUP on behalf of the user{" "}
<b>{user.displayName}</b>?
{isMe ? (
<p>Are you sure you want to resign the AUP?</p>
) : (
<p>
Are you sure you want to sign the AUP on behalf of the user{" "}
<b>{user.displayName}</b>?
</p>
)}
</ConfirmModal>
);
}
5 changes: 3 additions & 2 deletions src/app/(pages)/users/[user]/components/Info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ const ActiveStatus = (props: { active: boolean }) => {

type UserInfoProps = {
user: User;
isMe?: boolean;
};
export default async function UserInfo(props: Readonly<UserInfoProps>) {
const { user } = props;
const { user, isMe } = props;
const session = await auth();
const indigoUser = user["urn:indigo-dc:scim:schemas:IndigoUser"];
const created = user.meta?.created
Expand Down Expand Up @@ -55,7 +56,7 @@ export default async function UserInfo(props: Readonly<UserInfoProps>) {
<div className="flex">
<InfoTable data={data} />
<div className="mb-auto ml-auto mr-0 mt-0">
<OptionsDropdown user={user} isAdmin={session?.is_admin} />
<OptionsDropdown user={user} isAdmin={session?.is_admin} isMe={isMe} />
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/(pages)/users/[user]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async function UserPage(props: Readonly<UserPageProps>) {
<Page title={user.name?.formatted}>
<Panel>
<Section title="General">
<UserInfo user={user} />
<UserInfo user={user} isMe={isMe} />
</Section>
<Section title="Groups">
<Groups user={user} isAdmin={isAdmin} />
Expand Down

0 comments on commit b96b6f0

Please sign in to comment.