From f6dd2207522b1d3dd7a3ee3e3346e392287bc1cf Mon Sep 17 00:00:00 2001 From: zant Date: Thu, 8 Aug 2024 14:48:51 +0200 Subject: [PATCH] feat: protect ui based on roles --- src/components/list/CityList.tsx | 36 +++++++++++++++++------ src/components/list/FilteredDataTable.tsx | 16 ++-------- src/components/list/RoleList.tsx | 19 +++++++++++- 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/components/list/CityList.tsx b/src/components/list/CityList.tsx index 9c05b0a..ad14c8c 100644 --- a/src/components/list/CityList.tsx +++ b/src/components/list/CityList.tsx @@ -9,6 +9,8 @@ import { HeadCell } from '../../themed/table/DataTable'; import FilteredDataTable from './FilteredDataTable'; import useStateContext from '@/hooks/useStateContext'; import { IUser } from '@/schemas/auth'; +import ProtectedView from '@/layout/ProtectedView'; +import { CITIES_CREATE, CITIES_EDIT } from '@/constants/permissions'; const headCells: HeadCell[] = [ { @@ -45,14 +47,30 @@ export default function RoleList() { const actions = (row: City, loading?: boolean) => (
-
+ ); + + const create = () => ( +
+ +
); @@ -67,7 +85,7 @@ export default function RoleList() { headCells={headCells} title={t('menu.cities')} subtitle={t('menu.descriptions.cities')} - onCreate={() => setOpenDialog(true)} + create={create} actions={actions} updateControl={updateControl} /> diff --git a/src/components/list/FilteredDataTable.tsx b/src/components/list/FilteredDataTable.tsx index f36688c..afb7868 100644 --- a/src/components/list/FilteredDataTable.tsx +++ b/src/components/list/FilteredDataTable.tsx @@ -31,7 +31,7 @@ interface FilteredDataTableProps extends Omit, 'rows'> { defaultFilter?: string; updateControl?: number; actions?: (row: T, loading?: boolean) => JSX.Element; - onCreate?: () => void; + create?: () => JSX.Element; } interface FilterOptionsObject { @@ -48,7 +48,7 @@ export default function FilteredDataTable({ defaultFilter, updateControl, actions, - onCreate, + create, ...otherDataTableProps }: FilteredDataTableProps) { const { t } = useTranslation('translation'); @@ -243,17 +243,7 @@ export default function FilteredDataTable({ onClick={handleSearch} /> - {onCreate && ( - -