diff --git a/src/app/[locale]/pages/staff-management/page.tsx b/src/app/[locale]/pages/staff-management/page.tsx index 1db05da..b9ef54d 100644 --- a/src/app/[locale]/pages/staff-management/page.tsx +++ b/src/app/[locale]/pages/staff-management/page.tsx @@ -2,12 +2,20 @@ import TanstakStuffTable from '@/app/ui/staff-management/tanstak-stuff-table'; import { CreateStaffForm } from '@/app/ui/forms/create-staff-form'; +import { useEmployeInfo } from '@/app/hooks/react-query/useEmployeInfo'; export default function Page() { + const { getPermissionLevel } = useEmployeInfo(); + const staffPermissionLevel = getPermissionLevel('staff'); + return (
- - + {staffPermissionLevel === 3 && ( + + )} + {staffPermissionLevel > 0 && ( + + )}
) } \ No newline at end of file diff --git a/src/app/ui/staff-management/tanstak-stuff-table.tsx b/src/app/ui/staff-management/tanstak-stuff-table.tsx index bcee119..4736e92 100644 --- a/src/app/ui/staff-management/tanstak-stuff-table.tsx +++ b/src/app/ui/staff-management/tanstak-stuff-table.tsx @@ -49,7 +49,7 @@ export interface StaffMember { }; } -export default function TanstakStuffTable() { +export default function TanstakStuffTable({ permission }: { permission: 0 | 1 | 3 }) { // Состояния const [sorting, setSorting] = useState([]); const [columnFilters, setColumnFilters] = useState([]); @@ -140,9 +140,9 @@ export default function TanstakStuffTable() { } }); - // Определение колонок для сотрудников - const columns = useMemo[]>( - () => [ + // Определение колонок + const columns = useMemo[]>(() => { + const allColumns: ColumnDef[] = [ { accessorKey: 'id', header: ({ column }) => ( @@ -282,7 +282,10 @@ export default function TanstakStuffTable() { ) }, }, - { + ] + + if (permission === 3) { + allColumns.push({ id: 'actions', header: () => { return ( @@ -320,10 +323,11 @@ export default function TanstakStuffTable() { ), enableSorting: false, enableColumnFilter: false, - }, - ], - [t] - ); + },); + } + + return allColumns; + }, [permission]); const handleView = (staff: StaffMember) => { setSelectedStaff(staff); diff --git a/src/app/ui/users/tanstak-users-table.tsx b/src/app/ui/users/tanstak-users-table.tsx index cd93ae8..9c76a0c 100644 --- a/src/app/ui/users/tanstak-users-table.tsx +++ b/src/app/ui/users/tanstak-users-table.tsx @@ -128,8 +128,8 @@ export default function TanstakUsersTable({ permission }: { permission: number } const queryClient = useQueryClient(); // Определение колонок - const columns = useMemo[]>( - () => [ + const columns = useMemo[]>(() => { + const allColumns: ColumnDef[] = [ { accessorKey: 'id', header: ({ column }) => ( @@ -383,16 +383,13 @@ export default function TanstakUsersTable({ permission }: { permission: number } ) }, - }, - { + } + ] + + if (permission === 3) { + allColumns.push({ id: 'actions', - header: () => { - return ( -
- {t('actions')} -
- ) - }, + header: () =>
{t('actions')}
, cell: ({ row }) => (
@@ -407,10 +404,11 @@ export default function TanstakUsersTable({ permission }: { permission: number } ), enableSorting: false, enableColumnFilter: false, - }, - ], - [] - ); + }); + } + + return allColumns; + }, [permission]); const handleView = async (useId: number) => { let userInfo = await fetchUsesInfo(useId);