diff --git a/app/admin/administration/area/component/index.tsx b/app/admin/administration/area/component/index.tsx index 87f47a8..e35a34d 100644 --- a/app/admin/administration/area/component/index.tsx +++ b/app/admin/administration/area/component/index.tsx @@ -17,9 +17,10 @@ import { IArea } from './type'; type Props = { data: IArea[] + actions: string[] }; -const ComponentAreaPage: FC = ({ data }) => { +const ComponentAreaPage: FC = ({ data, actions }) => { const [filterData, setFilterData] = useState([]) const [selectedData, setSelectedData] = useState(undefined) const [showFormDialog, setShowFormDialog] = useState(false) @@ -32,7 +33,7 @@ const ComponentAreaPage: FC = ({ data }) => { } }, [data]) - const handleDelete = (areaId: string | number) => { + const handleDelete = async (areaId: string | number) => { return axios.delete(`/area/${areaId}`).then(res => res.data) } @@ -114,7 +115,7 @@ const ComponentAreaPage: FC = ({ data }) => { { title: 'Action', key: 'action', - render: (_, record) => ( + render: (_, record) => actions.includes('UPDATE') || actions.includes('DELETE') && ( @@ -124,10 +125,14 @@ const ComponentAreaPage: FC = ({ data }) => { - { setShowFormDialog(true); setSelectedData(record) }} >Edit - - Delete - + {actions.includes('UPDATE') && + { setShowFormDialog(true); setSelectedData(record) }} >Edit + } + {actions.includes('DELETE') && + + Delete + + } = ({ data }) => {
- +
- + {actions.includes('CREATE') && + + }
import('./component')); - export const metadata: Metadata = { title: "Admin | Area", } -async function getData() { - const { BASE_URL_API } = process.env - const session = await getServerSession(authOptions) - - const res = await fetch(BASE_URL_API + '/area', { - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${session?.user.access_token}`, - }, - cache: 'no-cache', - next: { - tags: ['area'] - } - }) - - const data: ResponseData = await res.json() - - // Recommendation: handle errors - if (!res.ok) { - // This will activate the closest `error.js` Error Boundary - throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`) - } - - return data.data -} - - export default async function AreaPage() { - const data = await getData() + const actions = await getAccessPagePermission('/administration/area') + const data = await fetchData('/area', 'no-cache', { tags: ['area'] }) return ( <> @@ -54,15 +26,15 @@ export default async function AreaPage() { AreaHere's a list of areas that have been registered! -
- -
+ {actions.includes('EXPORT') && +
+ +
+ } }> - + diff --git a/app/admin/administration/company/component/index.tsx b/app/admin/administration/company/component/index.tsx index af26b79..1477cdc 100644 --- a/app/admin/administration/company/component/index.tsx +++ b/app/admin/administration/company/component/index.tsx @@ -5,7 +5,7 @@ import { useSession } from 'next-auth/react'; import { MoreHorizontalIcon } from 'lucide-react'; import { Table } from 'antd'; import { TableProps, type ColumnsType } from 'antd/es/table'; -import { MixerHorizontalIcon, PlusCircledIcon } from '@radix-ui/react-icons'; +import { PlusCircledIcon } from '@radix-ui/react-icons'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; import { Button } from '@/components/ui/button'; import { AlertDialog, AlertDialogTrigger } from '@/components/ui/alert-dialog'; @@ -17,9 +17,10 @@ import { type ICompany } from './type'; type Props = { data: ICompany[] + actions: String[] }; -const ComponentCompanyPage: FC = ({ data }) => { +const ComponentCompanyPage: FC = ({ data, actions }) => { const [filterData, setFilterData] = useState([]) const [selectedData, setSelectedData] = useState(undefined) const [showFormDialog, setShowFormDialog] = useState(false) @@ -33,7 +34,7 @@ const ComponentCompanyPage: FC = ({ data }) => { } }, [data]) - const handleDelete = (companyId: string | number) => { + const handleDelete = async (companyId: string | number) => { // return new Promise((resolve, reject) => { // if (Math.random() > 0.5) { // setTimeout(() => { @@ -128,7 +129,7 @@ const ComponentCompanyPage: FC = ({ data }) => { { title: 'Action', key: 'action', - render: (_, record) => ( + render: (_, record) => actions.includes('EDIT') || actions.includes('DELETE') && ( @@ -138,10 +139,14 @@ const ComponentCompanyPage: FC = ({ data }) => { - { setShowFormDialog(true); setSelectedData(record) }} >Edit - - Delete - + {actions.includes('EDIT') && + { setShowFormDialog(true); setSelectedData(record) }} >Edit + } + {actions.includes('DELETE') && + + Delete + + } = ({ data }) => {
- +
- + {actions.includes('CREATE') ? + : null + }
import('./component')); @@ -15,35 +14,9 @@ export const metadata: Metadata = { title: "Admin | Company", } -async function getData() { - const { BASE_URL_API } = process.env - const session = await getServerSession(authOptions) - - const res = await fetch(BASE_URL_API + '/company', { - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${session?.user.access_token}`, - }, - cache: 'no-cache', - next: { - tags: ['company'] - } - }) - - const data: ResponseData = await res.json() - - // Recommendation: handle errors - if (!res.ok) { - // This will activate the closest `error.js` Error Boundary - throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`) - } - - return data.data -} - - export default async function CompanyPage() { - const data = await getData() + const actions = await getAccessPagePermission('/administration/company') + const data = await fetchData('/company', 'no-cache', { tags: ['company'] }) return ( <> @@ -60,9 +33,7 @@ export default async function CompanyPage() { }> - + diff --git a/app/admin/administration/division/component/index.tsx b/app/admin/administration/division/component/index.tsx index 46c1e0f..5a74cd0 100644 --- a/app/admin/administration/division/component/index.tsx +++ b/app/admin/administration/division/component/index.tsx @@ -17,9 +17,10 @@ import useAxiosAuth from '@/lib/axios/useAxiosAuth'; type Props = { data: IDivision[] + actions: string[] }; -const ComponentPage: FC = ({ data }) => { +const ComponentPage: FC = ({ data, actions }) => { const [filterData, setFilterData] = useState([]) const [selectedData, setSelectedData] = useState(undefined) const [showFormDialog, setShowFormDialog] = useState(false) @@ -32,7 +33,7 @@ const ComponentPage: FC = ({ data }) => { } }, [data]) - const handleDelete = (divisionId: string | number) => { + const handleDelete = async (divisionId: string | number) => { return axios.delete(`/division/${divisionId}`).then(res => res.data) } @@ -111,7 +112,7 @@ const ComponentPage: FC = ({ data }) => { { title: 'Action', key: 'action', - render: (_, record) => ( + render: (_, record) => actions.includes('UPDATE') || actions.includes('DELETE') && ( @@ -121,10 +122,14 @@ const ComponentPage: FC = ({ data }) => { - { setShowFormDialog(true); setSelectedData(record) }} >Edit - - Delete - + {actions.includes('UPDATE') && + { setShowFormDialog(true); setSelectedData(record) }} >Edit + } + {actions.includes('DELETE') && + + Delete + + } = ({ data }) => {
- +
- + {actions.includes('CREATE') ? + : null + }
import('./component')); @@ -15,35 +14,9 @@ export const metadata: Metadata = { title: "Admin | Division", } -async function getData() { - const { BASE_URL_API } = process.env - const session = await getServerSession(authOptions) - - const res = await fetch(BASE_URL_API + '/division', { - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${session?.user.access_token}`, - }, - cache: 'no-cache', - next: { - tags: ['division'] - } - }) - - const data: ResponseData = await res.json() - - // Recommendation: handle errors - if (!res.ok) { - // This will activate the closest `error.js` Error Boundary - throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`) - } - - return data.data -} - - export default async function DivisionPage() { - const data = await getData() + const actions = await getAccessPagePermission('/administration/division') + const data = await fetchData('/division', 'no-cache', { tags: ['division'] }) return ( <> @@ -60,9 +33,7 @@ export default async function DivisionPage() { }> - + diff --git a/app/admin/administration/user/[id]/page.tsx b/app/admin/administration/user/[id]/page.tsx index 1fea95a..a528583 100644 --- a/app/admin/administration/user/[id]/page.tsx +++ b/app/admin/administration/user/[id]/page.tsx @@ -6,6 +6,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com import fetchData from '@/lib/fetchData'; import { Button } from '@/components/ui/button'; import { type IUser } from '../component/type'; +import { getAccessPagePermission } from '@/lib/get-access-data'; export const metadata: Metadata = { title: "Admin | User Detail", @@ -16,8 +17,9 @@ type Props = { }; const UserDetailPage: FC = async ({ params }) => { - const id = (await params).id + const actions = await getAccessPagePermission('/administration/user', 'VIEW') + const id = (await params).id const data: IUser = await fetchData(`/user/${id}`) return ( @@ -35,7 +37,7 @@ const UserDetailPage: FC = async ({ params }) => { Detail of user id {id} - {data.status.code === 'A' && + {actions.includes('UPDATE') && data.status.code === 'A' && - + {actions.includes('CREATE') && + + + + }
import('./component/Export')); const ComponentPage = lazy(() => import('./component')); - export const metadata: Metadata = { title: "Admin | User", } -async function getData() { - const { BASE_URL_API } = process.env - const session = await getServerSession(authOptions) - console.log("SESSION ADMIN USER PAGE :", session) - - const res = await fetch(BASE_URL_API + '/user', { - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${session?.user.access_token}`, - }, - cache: 'no-cache', - next: { - tags: ['user'] - } - }) - - const data: ResponseData = await res.json() - - // Recommendation: handle errors - if (!res.ok) { - // This will activate the closest `error.js` Error Boundary - throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`) - } - - return data.data -} export default async function UserPage() { - const data = await getData() + const actions = await getAccessPagePermission('/administration/user', 'VIEW') - console.log("DATA USER LENGTH :", data?.user) + const data = await fetchData('/user', 'no-cache', { tags: ['user'] }) return ( <> @@ -55,13 +27,15 @@ export default async function UserPage() { UserHere's a list of employees that have been registered! - + {actions.includes('EXPORT') && + }> + + + } }> - + diff --git a/app/admin/components/Sidebar.tsx b/app/admin/components/Sidebar.tsx index 77fb04b..35bad08 100644 --- a/app/admin/components/Sidebar.tsx +++ b/app/admin/components/Sidebar.tsx @@ -16,7 +16,7 @@ import { Skeleton } from '@/components/ui/skeleton'; const SidebarItem = dynamic(() => import("./SidebarItem"), { - loading: () => , + loading: () => , ssr: false }) diff --git a/app/admin/manual/manual-presence/page.tsx b/app/admin/manual/manual-presence/page.tsx index 0a7d20d..41e3635 100644 --- a/app/admin/manual/manual-presence/page.tsx +++ b/app/admin/manual/manual-presence/page.tsx @@ -3,6 +3,7 @@ import { FC, Suspense, lazy } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import LazyLoading from '@/components/loader/LazyLoading'; import fetchData from '@/lib/fetchData'; +import { getAccessPagePermission } from '@/lib/get-access-data'; const ImportExcel = lazy(() => import('./component/ImportExcel')); const ComponentPage = lazy(() => import('./component')); @@ -14,6 +15,8 @@ export const metadata: Metadata = { type Props = {}; const ManualPresencePage: FC = async () => { + const actions = await getAccessPagePermission('/manual/manual-presence', 'CREATE') + const fetchUser = fetchData('/user') const fetchStatus = fetchData('/presence/list-status') @@ -23,18 +26,16 @@ const ManualPresencePage: FC = async () => { <>
- {/* - Manual Attendance - Only create a manual attendance if the FR system has problems ! - */}
Manual Attendance Only create a manual attendance if the FR system has problems !
- }> - - + {actions.includes('IMPORT') && + }> + + + }
}> diff --git a/app/admin/rbac/menu/component/Form.tsx b/app/admin/rbac/menu/component/Form.tsx index 795d7a2..c29fb86 100644 --- a/app/admin/rbac/menu/component/Form.tsx +++ b/app/admin/rbac/menu/component/Form.tsx @@ -285,7 +285,7 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)