Added permissions to filter out the user update

This commit is contained in:
Joao Ramos
2024-07-25 11:23:11 +01:00
parent 923319051c
commit 45df9837e7
4 changed files with 104 additions and 22 deletions

View File

@@ -4,6 +4,7 @@ import {
CorporateUser,
EMPLOYMENT_STATUS,
User,
Type,
} from "@/interfaces/user";
import { groupBySession, averageScore } from "@/utils/stats";
import { RadioGroup } from "@headlessui/react";
@@ -32,6 +33,8 @@ import { USER_TYPE_LABELS } from "@/resources/user";
import { CURRENCIES } from "@/resources/paypal";
import useCodes from "@/hooks/useCodes";
import { checkAccess, getTypesOfUser } from "@/utils/permissions";
import { PERMISSIONS } from "@/constants/userPermissions";
import { PermissionType } from "@/interfaces/permissions";
const expirationDateColor = (date: Date) => {
const momentDate = moment(date);
@@ -261,6 +264,10 @@ const UserCard = ({
]
: [];
const updateUserPermission = PERMISSIONS.updateUser[user.type] as {
list: Type[];
perm: PermissionType;
};
return (
<>
<ProfileSummary
@@ -817,7 +824,14 @@ const UserCard = ({
Close
</Button>
<Button
disabled={disabled}
disabled={
disabled ||
!checkAccess(
loggedInUser,
updateUserPermission.list,
updateUserPermission.perm
)
}
onClick={updateUser}
className="w-full max-w-[200px]"
>