mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 22:06:28 +00:00
Apply RBAC permissions across admin and tasks
Enforce page access and action-level permissions across admin and task views, including exports and record actions. Move user creation to a client component behind server-side permission checks, standardize data fetching, and remove the deprecated user-role route.
This commit is contained in:
@@ -115,7 +115,7 @@ const ComponentAreaPage: FC<Props> = ({ data, actions }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => actions.includes('UPDATE') || actions.includes('DELETE') && (
|
||||
render: (_, record) => (actions.includes('UPDATE') || actions.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -166,7 +166,7 @@ const ComponentAreaPage: FC<Props> = ({ data, actions }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search company..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
{actions.includes('CREATE') &&
|
||||
{actions?.includes('CREATE') &&
|
||||
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Area
|
||||
|
||||
@@ -129,7 +129,7 @@ const ComponentCompanyPage: FC<Props> = ({ data, actions }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => actions.includes('EDIT') || actions.includes('DELETE') && (
|
||||
render: (_, record) => (actions.includes('EDIT') || actions.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
||||
@@ -112,7 +112,7 @@ const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => actions.includes('UPDATE') || actions.includes('DELETE') && (
|
||||
render: (_, record) => (actions.includes('UPDATE') || actions.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -163,7 +163,7 @@ const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search department..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
{actions.includes('CREATE') ?
|
||||
{actions?.includes('CREATE') ?
|
||||
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Department
|
||||
|
||||
@@ -156,16 +156,16 @@ const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
{record.status.code === 'A' ?
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem><Link href={`user/${record.id}`} className='w-full'>View</Link></DropdownMenuItem>
|
||||
{actions.includes('CHANGE_PASSWORD') &&
|
||||
{actions?.includes('CHANGE_PASSWORD') &&
|
||||
<DropdownMenuItem onClick={() => { setShowFormChangePass(true); setSelectedData(record) }}>Change password</DropdownMenuItem>
|
||||
}
|
||||
{actions.includes('RESET_PASSWORD') &&
|
||||
{actions?.includes('RESET_PASSWORD') &&
|
||||
<DropdownMenuItem onClick={() => { setShowResetPass(true), setSelectedData(record) }}>Reset Password</DropdownMenuItem>
|
||||
}
|
||||
{actions.includes('UPDATE') &&
|
||||
{actions?.includes('UPDATE') &&
|
||||
<DropdownMenuItem><Link href={`user/create?is_update=true&id=${record.id}`} className='w-full'>Edit</Link></DropdownMenuItem>
|
||||
}
|
||||
{actions.includes('DELETE') &&
|
||||
{actions?.includes('DELETE') &&
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
@@ -208,7 +208,7 @@ const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search user..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
{actions.includes('CREATE') &&
|
||||
{actions?.includes('CREATE') &&
|
||||
<Link href='user/create'>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost'>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
'use client'
|
||||
|
||||
import { FC, Suspense, useEffect, useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { DatePicker, Form, Input, Radio, Select } from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||
import useFetch from '@/hooks/useFetch';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { titleCase } from '@/lib/helper';
|
||||
import PageLoading from '@/components/loader/PageLoading';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type IUser } from '../component/type';
|
||||
import { type IRole } from '@/app/admin/information/user-role/component/type';
|
||||
import { type ICompany } from '../../company/component/type';
|
||||
import { type IArea } from '../../area/component/type';
|
||||
import { type IDivision } from '../../division/component/type';
|
||||
import { type IPosition } from '@/app/admin/information/position/component/type';
|
||||
import { type IEmployeeType } from '@/app/admin/information/employee-type/component/type';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
type Props = {};
|
||||
|
||||
const UserCreate: FC<Props> = ({ }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [isFetching, setIsFetching] = useState(false)
|
||||
const [showConfirm, setShowConfirm] = useState(false)
|
||||
|
||||
const [form] = Form.useForm();
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams();
|
||||
const axios = useAxiosAuth()
|
||||
|
||||
const isUpdate = searchParams!.get('is_update') as string || ''
|
||||
const id = searchParams!.get('id') as string || ''
|
||||
|
||||
const { data: companyList, isLoading: companyLoading } = useFetch('/company')
|
||||
const { data: areaList, isLoading: areaLoading } = useFetch('/area')
|
||||
const { data: divisionList, isLoading: divisionLoading } = useFetch('/division')
|
||||
const { data: roleList, isLoading: roleLoading } = useFetch('/role')
|
||||
const { data: positionList, isLoading: positionLoading } = useFetch('/position')
|
||||
const { data: employeeTypeList, isLoading: employeeTypeLoading } = useFetch('/employee-type')
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
setIsFetching(true)
|
||||
try {
|
||||
const res = await axios.get(`/user/${id}`)
|
||||
const data: IUser = res.data.data
|
||||
|
||||
form.setFieldsValue(data)
|
||||
|
||||
if (data.company) form.setFieldValue('company_id', data.company.id)
|
||||
if (data.area) form.setFieldValue('area_id', data.area.id)
|
||||
if (data.division) form.setFieldValue('division_id', data.division.id)
|
||||
if (data.role) form.setFieldValue('role_id', data.role.id)
|
||||
if (data.employee_type) form.setFieldValue('employee_type_id', data.employee_type.id)
|
||||
if (data.position) form.setFieldValue('position_id', data.position.id)
|
||||
|
||||
if (data.birthday) form.setFieldValue('birthday', dayjs(data.birthday))
|
||||
if (data.contract_expiration_date) form.setFieldValue('contract_expiration_date', dayjs(data.contract_expiration_date))
|
||||
if (data.hire_date) form.setFieldValue('hire_date', dayjs(data.hire_date))
|
||||
if (data.resign_date) form.setFieldValue('resign_date', dayjs(data.resign_date))
|
||||
|
||||
setIsFetching(false)
|
||||
} catch (error: any) {
|
||||
handleError(`Failed fetch data, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (isUpdate) {
|
||||
fetchData()
|
||||
} else {
|
||||
form.resetFields()
|
||||
}
|
||||
}, [isUpdate, form, id])
|
||||
|
||||
|
||||
const handleSubmit = () => {
|
||||
const payload = form.getFieldsValue()
|
||||
if (payload.fullname) payload.fullname = titleCase(payload.fullname)
|
||||
|
||||
!isUpdate ? handleCreate(payload) : handleUpdate(payload)
|
||||
}
|
||||
|
||||
const handleCreate = async (payload: IUser) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await axios.post('/user', payload)
|
||||
|
||||
handleSuccess('Data successfully created.')
|
||||
} catch (error: any) {
|
||||
handleError(`Data failed to create, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleUpdate = async (payload: IUser) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await axios.put('/user/' + id, payload)
|
||||
|
||||
handleSuccess('Data successfully updated.')
|
||||
} catch (error: any) {
|
||||
handleError(`Data failed to update, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSuccess = (message: string) => {
|
||||
toast.success(message)
|
||||
router.replace('/admin/administration/user')
|
||||
router.refresh()
|
||||
form.resetFields()
|
||||
}
|
||||
|
||||
const handleError = (message: string) => {
|
||||
toast.error(message)
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader className='flex flex-row items-center sm:space-x-5'>
|
||||
<Link href='/admin/administration/user' className='hidden sm:block'>
|
||||
<Button variant='outline' size='icon'>
|
||||
<i className="ti ti-arrow-left text-xl"></i>
|
||||
</Button>
|
||||
</Link>
|
||||
<div className='space-y-1'>
|
||||
<CardTitle>{isUpdate ? 'Update user' : 'Create new user'}</CardTitle>
|
||||
<CardDescription>{isUpdate ? 'Update user id ' + id : 'Add a new team to join to your department'}</CardDescription>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<Form form={form} onFinish={() => setShowConfirm(true)} scrollToFirstError layout="vertical" size='small'>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-0 gap-x-5 2xl:gap-x-8'>
|
||||
{/* <Label htmlFor="fullname">Fullname</Label> */}
|
||||
<Form.Item name='fullname' labelAlign="left" label='Fullname' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Input className="input" id="fullname" placeholder="John Doe" />
|
||||
</Form.Item>
|
||||
<Form.Item name='nickname' label='Nickname' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Input className="input" id="nickname" placeholder="John" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Email' name='email' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email" placeholder="john.nutech@gmail.com" />
|
||||
</Form.Item>
|
||||
{!isUpdate &&
|
||||
<Form.Item label='Password' name='password' rules={[
|
||||
{ required: true, message: 'This field is required' }, { min: 5 }
|
||||
]}>
|
||||
<Input.Password className="input" type="password" id="password" placeholder="********" />
|
||||
</Form.Item>
|
||||
}
|
||||
<Form.Item label='NIK' name='nik' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ pattern: /^\d+$/, message: 'Invalid NIK format' },
|
||||
{ len: 11 }
|
||||
]}>
|
||||
<Input className="input" id="nik" placeholder="04012345678" maxLength={11} />
|
||||
</Form.Item>
|
||||
<Form.Item label='NIKTG' name='niktg' rules={[
|
||||
{ pattern: /^\d+$/, message: 'Invalid NIKTG format' },
|
||||
]}>
|
||||
<Input className="input" id="niktg" placeholder="995500" maxLength={8} />
|
||||
</Form.Item>
|
||||
<Form.Item label='Phone Number' name='phone_number' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ pattern: /^\d+$/, message: 'Invalid phone number' },
|
||||
{ min: 10 }, { max: 13 }
|
||||
]}>
|
||||
<Input className="input" id="phone_number" placeholder="6281234567890" maxLength={13} />
|
||||
</Form.Item>
|
||||
<Form.Item label='Role' name='role_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select role' showSearch allowClear loading={roleLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{roleList?.role?.length > 0 && roleList.role.map((item: IRole, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Company' name='company_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select company' showSearch allowClear loading={companyLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{companyList?.company?.length > 0 && companyList.company.map((item: ICompany, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Area' name='area_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select area' showSearch allowClear loading={areaLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{areaList?.area?.length > 0 && areaList.area.map((item: IArea, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Department' name='division_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select division' showSearch allowClear loading={divisionLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{divisionList?.division?.length > 0 && divisionList.division.map((item: IDivision, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Position' name='position_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select position' showSearch allowClear loading={positionLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{positionList?.position?.length > 0 && positionList.position.map((item: IPosition, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Employee Type' name='employee_type_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select employee type' showSearch allowClear loading={employeeTypeLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{employeeTypeList?.employee_type?.length > 0 && employeeTypeList.employee_type.map((item: IEmployeeType, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Birthdate' name='birthday'>
|
||||
<DatePicker className='w-full' placeholder='Select date of birth' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Gender' name='gender'>
|
||||
<Radio.Group>
|
||||
<Radio value="male">Male</Radio>
|
||||
<Radio value="female">Female</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label='Hire Date' name='hire_date'>
|
||||
<DatePicker className='w-full' placeholder='Select date of hire' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Contract Expiration Date' name='contract_expiration_date'>
|
||||
<DatePicker className='w-full' placeholder='Select contract expiration date' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Extend Contract' name='is_extend_contract'>
|
||||
<Radio.Group>
|
||||
<Radio value={true}>Yes</Radio>
|
||||
<Radio value={false}>No</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label='Office Email' name='email_office' rules={[
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email_office" placeholder="john@nutech-integrasi.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Personal Email' name='email_personal' rules={[
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email_personal" placeholder="john@gmail.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Last Education' name='last_education' >
|
||||
<Input className="input" id="last_education" placeholder="S1 Teknik Informatika" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Resign Date' name='resign_date'>
|
||||
<DatePicker className='w-full' placeholder='Select resign date' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Resign Reason' name='resign_reason' >
|
||||
<Input.TextArea className="input" id="resign_reason" placeholder="Describe reason of resign" rootClassName='px-3! py-2!' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Post Company' name='post_company'>
|
||||
<Input className="input" id="post_company" placeholder="PT Tokopedia" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
<div className='flex justify-end items-center'>
|
||||
<Button type='submit'>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{isUpdate && isFetching &&
|
||||
<PageLoading />
|
||||
}
|
||||
|
||||
{showConfirm &&
|
||||
<AlertDialog open={true}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This data will be stored on our server, you can change it whenever you want later.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction disabled={isLoading} onClick={handleSubmit}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Continue
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserCreate;
|
||||
@@ -1,338 +1,28 @@
|
||||
'use client'
|
||||
|
||||
import { FC, Suspense, useEffect, useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { DatePicker, Form, Input, Radio, Select } from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||
import useFetch from '@/hooks/useFetch';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { titleCase } from '@/lib/helper';
|
||||
import PageLoading from '@/components/loader/PageLoading';
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type IUser } from '../component/type';
|
||||
import { type IRole } from '@/app/admin/information/user-role/component/type';
|
||||
import { type ICompany } from '../../company/component/type';
|
||||
import { type IArea } from '../../area/component/type';
|
||||
import { type IDivision } from '../../division/component/type';
|
||||
import { type IPosition } from '@/app/admin/information/position/component/type';
|
||||
import { type IEmployeeType } from '@/app/admin/information/employee-type/component/type';
|
||||
import { toast } from 'sonner';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
import UserCreateClient from './UserCreateClient';
|
||||
|
||||
type Props = {};
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
const UserCreate: FC<Props> = ({ }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [isFetching, setIsFetching] = useState(false)
|
||||
const [showConfirm, setShowConfirm] = useState(false)
|
||||
export const metadata: Metadata = {
|
||||
title: "Admin | User Form",
|
||||
description: "Create or update employee user information",
|
||||
};
|
||||
|
||||
const [form] = Form.useForm();
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams();
|
||||
const axios = useAxiosAuth()
|
||||
type Props = {
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
||||
};
|
||||
|
||||
const isUpdate = searchParams!.get('is_update') as string || ''
|
||||
const id = searchParams!.get('id') as string || ''
|
||||
|
||||
const { data: companyList, isLoading: companyLoading } = useFetch('/company')
|
||||
const { data: areaList, isLoading: areaLoading } = useFetch('/area')
|
||||
const { data: divisionList, isLoading: divisionLoading } = useFetch('/division')
|
||||
const { data: roleList, isLoading: roleLoading } = useFetch('/role')
|
||||
const { data: positionList, isLoading: positionLoading } = useFetch('/position')
|
||||
const { data: employeeTypeList, isLoading: employeeTypeLoading } = useFetch('/employee-type')
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
setIsFetching(true)
|
||||
try {
|
||||
const res = await axios.get(`/user/${id}`)
|
||||
const data: IUser = res.data.data
|
||||
|
||||
form.setFieldsValue(data)
|
||||
|
||||
if (data.company) form.setFieldValue('company_id', data.company.id)
|
||||
if (data.area) form.setFieldValue('area_id', data.area.id)
|
||||
if (data.division) form.setFieldValue('division_id', data.division.id)
|
||||
if (data.role) form.setFieldValue('role_id', data.role.id)
|
||||
if (data.employee_type) form.setFieldValue('employee_type_id', data.employee_type.id)
|
||||
if (data.position) form.setFieldValue('position_id', data.position.id)
|
||||
|
||||
if (data.birthday) form.setFieldValue('birthday', dayjs(data.birthday))
|
||||
if (data.contract_expiration_date) form.setFieldValue('contract_expiration_date', dayjs(data.contract_expiration_date))
|
||||
if (data.hire_date) form.setFieldValue('hire_date', dayjs(data.hire_date))
|
||||
if (data.resign_date) form.setFieldValue('resign_date', dayjs(data.resign_date))
|
||||
|
||||
setIsFetching(false)
|
||||
} catch (error: any) {
|
||||
handleError(`Failed fetch data, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (isUpdate) {
|
||||
fetchData()
|
||||
} else {
|
||||
form.resetFields()
|
||||
}
|
||||
}, [isUpdate, form, id])
|
||||
|
||||
|
||||
const handleSubmit = () => {
|
||||
const payload = form.getFieldsValue()
|
||||
if (payload.fullname) payload.fullname = titleCase(payload.fullname)
|
||||
|
||||
!isUpdate ? handleCreate(payload) : handleUpdate(payload)
|
||||
}
|
||||
|
||||
const handleCreate = async (payload: IUser) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await axios.post('/user', payload)
|
||||
|
||||
handleSuccess('Data successfully created.')
|
||||
} catch (error: any) {
|
||||
handleError(`Data failed to create, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleUpdate = async (payload: IUser) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await axios.put('/user/' + id, payload)
|
||||
|
||||
handleSuccess('Data successfully updated.')
|
||||
} catch (error: any) {
|
||||
handleError(`Data failed to update, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSuccess = (message: string) => {
|
||||
toast.success(message)
|
||||
router.replace('/admin/administration/user')
|
||||
router.refresh()
|
||||
form.resetFields()
|
||||
}
|
||||
|
||||
const handleError = (message: string) => {
|
||||
toast.error(message)
|
||||
setIsLoading(false)
|
||||
}
|
||||
export default async function UserCreatePage({ searchParams }: Props) {
|
||||
const params = await searchParams;
|
||||
const isUpdate = params?.is_update === 'true';
|
||||
await getAccessPagePermission('/administration/user', isUpdate ? 'UPDATE' : 'CREATE');
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader className='flex flex-row items-center sm:space-x-5'>
|
||||
<Link href='/admin/administration/user' className='hidden sm:block'>
|
||||
<Button variant='outline' size='icon'>
|
||||
<i className="ti ti-arrow-left text-xl"></i>
|
||||
</Button>
|
||||
</Link>
|
||||
<div className='space-y-1'>
|
||||
<CardTitle>{isUpdate ? 'Update user' : 'Create new user'}</CardTitle>
|
||||
<CardDescription>{isUpdate ? 'Update user id ' + id : 'Add a new team to join to your department'}</CardDescription>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<Form form={form} onFinish={() => setShowConfirm(true)} scrollToFirstError layout="vertical" size='small'>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-0 gap-x-5 2xl:gap-x-8'>
|
||||
{/* <Label htmlFor="fullname">Fullname</Label> */}
|
||||
<Form.Item name='fullname' labelAlign="left" label='Fullname' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Input className="input" id="fullname" placeholder="John Doe" />
|
||||
</Form.Item>
|
||||
<Form.Item name='nickname' label='Nickname' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Input className="input" id="nickname" placeholder="John" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Email' name='email' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email" placeholder="john.nutech@gmail.com" />
|
||||
</Form.Item>
|
||||
{!isUpdate &&
|
||||
<Form.Item label='Password' name='password' rules={[
|
||||
{ required: true, message: 'This field is required' }, { min: 5 }
|
||||
]}>
|
||||
<Input.Password className="input" type="password" id="password" placeholder="********" />
|
||||
</Form.Item>
|
||||
}
|
||||
<Form.Item label='NIK' name='nik' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ pattern: /^\d+$/, message: 'Invalid NIK format' },
|
||||
{ len: 11 }
|
||||
]}>
|
||||
<Input className="input" id="nik" placeholder="04012345678" maxLength={11} />
|
||||
</Form.Item>
|
||||
<Form.Item label='NIKTG' name='niktg' rules={[
|
||||
{ pattern: /^\d+$/, message: 'Invalid NIKTG format' },
|
||||
]}>
|
||||
<Input className="input" id="niktg" placeholder="995500" maxLength={8} />
|
||||
</Form.Item>
|
||||
<Form.Item label='Phone Number' name='phone_number' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ pattern: /^\d+$/, message: 'Invalid phone number' },
|
||||
{ min: 10 }, { max: 13 }
|
||||
]}>
|
||||
<Input className="input" id="phone_number" placeholder="6281234567890" maxLength={13} />
|
||||
</Form.Item>
|
||||
<Form.Item label='Role' name='role_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select role' showSearch allowClear loading={roleLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{roleList?.role?.length > 0 && roleList.role.map((item: IRole, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Company' name='company_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select company' showSearch allowClear loading={companyLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{companyList?.company?.length > 0 && companyList.company.map((item: ICompany, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Area' name='area_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select area' showSearch allowClear loading={areaLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{areaList?.area?.length > 0 && areaList.area.map((item: IArea, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Department' name='division_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select division' showSearch allowClear loading={divisionLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{divisionList?.division?.length > 0 && divisionList.division.map((item: IDivision, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Position' name='position_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select position' showSearch allowClear loading={positionLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{positionList?.position?.length > 0 && positionList.position.map((item: IPosition, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Employee Type' name='employee_type_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select employee type' showSearch allowClear loading={employeeTypeLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{employeeTypeList?.employee_type?.length > 0 && employeeTypeList.employee_type.map((item: IEmployeeType, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Birthdate' name='birthday'>
|
||||
<DatePicker className='w-full' placeholder='Select date of birth' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Gender' name='gender'>
|
||||
<Radio.Group>
|
||||
<Radio value="male">Male</Radio>
|
||||
<Radio value="female">Female</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label='Hire Date' name='hire_date'>
|
||||
<DatePicker className='w-full' placeholder='Select date of hire' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Contract Expiration Date' name='contract_expiration_date'>
|
||||
<DatePicker className='w-full' placeholder='Select contract expiration date' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Extend Contract' name='is_extend_contract'>
|
||||
<Radio.Group>
|
||||
<Radio value={true}>Yes</Radio>
|
||||
<Radio value={false}>No</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label='Office Email' name='email_office' rules={[
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email_office" placeholder="john@nutech-integrasi.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Personal Email' name='email_personal' rules={[
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email_personal" placeholder="john@gmail.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Last Education' name='last_education' >
|
||||
<Input className="input" id="last_education" placeholder="S1 Teknik Informatika" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Resign Date' name='resign_date'>
|
||||
<DatePicker className='w-full' placeholder='Select resign date' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Resign Reason' name='resign_reason' >
|
||||
<Input.TextArea className="input" id="resign_reason" placeholder="Describe reason of resign" rootClassName='px-3! py-2!' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Post Company' name='post_company'>
|
||||
<Input className="input" id="post_company" placeholder="PT Tokopedia" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
<div className='flex justify-end items-center'>
|
||||
<Button type='submit'>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{isUpdate && isFetching &&
|
||||
<PageLoading />
|
||||
}
|
||||
|
||||
{showConfirm &&
|
||||
<AlertDialog open={true}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This data will be stored on our server, you can change it whenever you want later.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction disabled={isLoading} onClick={handleSubmit}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Continue
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
}
|
||||
</>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<UserCreateClient />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserCreate;
|
||||
@@ -4,7 +4,7 @@ import { ChangeEvent, FC, useEffect, useState } from '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 useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -17,9 +17,10 @@ import { type ILogName } from './type';
|
||||
|
||||
type Props = {
|
||||
data: ILogName[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<ILogName[]>([])
|
||||
const [selectedData, setSelectedData] = useState<ILogName | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -107,7 +108,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -117,10 +118,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -164,10 +169,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search log name..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Audit
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Audit
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -1,48 +1,22 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Admin | Log Name",
|
||||
title: "Admin | Audit Trail",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/log-name', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['log-name']
|
||||
}
|
||||
})
|
||||
|
||||
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 DeviceTypePage() {
|
||||
const data = await getData()
|
||||
export default async function AuditTrailPage() {
|
||||
const actions = await getAccessPagePermission('/audit-trail')
|
||||
const data = await fetchData('/log-name', 'no-cache', { tags: ['log-name'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -53,14 +27,17 @@ export default async function DeviceTypePage() {
|
||||
<CardTitle>Log Name</CardTitle>
|
||||
<CardDescription>Here's a list of log audit name!</CardDescription>
|
||||
</div>
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
{actions.includes('EXPORT') &&
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage
|
||||
data={data.log_name}
|
||||
actions={actions}
|
||||
/>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
|
||||
@@ -18,9 +18,10 @@ import { type IDayOff } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IDayOff[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IDayOff[]>([])
|
||||
const [selectedData, setSelectedData] = useState<IDayOff | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -33,7 +34,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const handleDelete = (id: string | number) => {
|
||||
const handleDelete = async (id: string | number) => {
|
||||
return axios.delete(`/dayoff/${id}`).then(res => res.data)
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -118,10 +119,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -156,10 +161,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search log name..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { 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 ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -11,7 +12,8 @@ export const metadata: Metadata = {
|
||||
}
|
||||
|
||||
|
||||
export default async function DeviceTypePage() {
|
||||
export default async function DayOffPage() {
|
||||
const actions = await getAccessPagePermission('/day-off')
|
||||
const data = await fetchData('/dayoff')
|
||||
|
||||
return (
|
||||
@@ -26,7 +28,7 @@ export default async function DeviceTypePage() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data.day_off} />
|
||||
<ComponentPage data={data.day_off} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -17,9 +17,10 @@ import { type IDeviceType } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IDeviceType[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IDeviceType[]>([])
|
||||
const [selectedData, setSelectedData] = useState<IDeviceType | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -32,7 +33,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const handleDelete = (deviceTypeId: string | number) => {
|
||||
const handleDelete = async (deviceTypeId: string | number) => {
|
||||
return axios.delete(`/device-type/${deviceTypeId}`).then(res => res.data)
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -117,10 +118,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -162,12 +167,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search device type..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
<Input placeholder="Search device type..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Device Type
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Device Type
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -15,35 +14,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Device Type",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/device-type', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['device-type']
|
||||
}
|
||||
})
|
||||
|
||||
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 DeviceTypePage() {
|
||||
const data = await getData()
|
||||
const actions = await getAccessPagePermission('/device/device-type')
|
||||
const data = await fetchData('/device-type', 'no-cache', { tags: ['device-type'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -54,14 +27,17 @@ export default async function DeviceTypePage() {
|
||||
<CardTitle>Device Type</CardTitle>
|
||||
<CardDescription>Here's a list of device types that have been registered!</CardDescription>
|
||||
</div>
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
{actions.includes('EXPORT') &&
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage
|
||||
data={data.device_type}
|
||||
actions={actions}
|
||||
/>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
|
||||
@@ -17,9 +17,10 @@ import { IDevice } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IDevice[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IDevice[]>([])
|
||||
const [selectedData, setSelectedData] = useState<IDevice | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -32,7 +33,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const handleDelete = (deviceId: string | number) => {
|
||||
const handleDelete = async (deviceId: string | number) => {
|
||||
return axios.delete(`/device/${deviceId}`).then(res => res.data)
|
||||
|
||||
}
|
||||
@@ -117,7 +118,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -127,10 +128,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -168,10 +173,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
Filter
|
||||
</Button>
|
||||
</div>
|
||||
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Device
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Device
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -15,35 +14,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Device",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/device', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['device']
|
||||
}
|
||||
})
|
||||
|
||||
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()
|
||||
export default async function DevicePage() {
|
||||
const actions = await getAccessPagePermission('/device/device')
|
||||
const data = await fetchData('/device', 'no-cache', { tags: ['device'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -54,14 +27,17 @@ export default async function DivisionPage() {
|
||||
<CardTitle>Device</CardTitle>
|
||||
<CardDescription>Here's a list of devices that have been registered!</CardDescription>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
{actions.includes('EXPORT') &&
|
||||
<div className="flex items-center space-x-2">
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage
|
||||
data={data.device}
|
||||
actions={actions}
|
||||
/>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
|
||||
@@ -17,9 +17,10 @@ import { type IGlobalParameter } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IGlobalParameter[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IGlobalParameter[]>([])
|
||||
const [selectedData, setSelectedData] = useState<IGlobalParameter | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -32,7 +33,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const handleDelete = (id: string | number) => {
|
||||
const handleDelete = async (id: string | number) => {
|
||||
return axios.delete(`/global-parameter/${id}`).then(res => res.data)
|
||||
}
|
||||
|
||||
@@ -117,7 +118,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -127,10 +128,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -171,12 +176,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search parameters..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
<Input placeholder="Search parameters..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -15,35 +14,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Global Parameter",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/global-parameter', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['global-parameter']
|
||||
}
|
||||
})
|
||||
|
||||
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 GlobalParameterPage() {
|
||||
const data = await getData()
|
||||
const actions = await getAccessPagePermission('/global-parameter')
|
||||
const data = await fetchData('/global-parameter', 'no-cache', { tags: ['global-parameter'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -54,14 +27,17 @@ export default async function GlobalParameterPage() {
|
||||
<CardTitle>Global Parameter</CardTitle>
|
||||
<CardDescription>Here's a list of parameters that have been registered!</CardDescription>
|
||||
</div>
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
{actions.includes('EXPORT') &&
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage
|
||||
data={data.global_parameter}
|
||||
actions={actions}
|
||||
/>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { MixerHorizontalIcon } from '@radix-ui/react-icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { type IEmployeeType } from './type';
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -13,35 +12,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Master Employee Type",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/employee-type', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['employee-type']
|
||||
}
|
||||
})
|
||||
|
||||
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 page() {
|
||||
const data = await getData()
|
||||
export default async function EmployeeTypePage() {
|
||||
await getAccessPagePermission('/information/employee-type')
|
||||
const data = await fetchData('/employee-type', 'no-cache', { tags: ['employee-type'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { MixerHorizontalIcon } from '@radix-ui/react-icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { type IMasterStatus } from './type';
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -13,35 +12,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Master Status",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/status', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['status']
|
||||
}
|
||||
})
|
||||
|
||||
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 page() {
|
||||
const data = await getData()
|
||||
export default async function MasterStatusPage() {
|
||||
await getAccessPagePermission('/information/master-status')
|
||||
const data = await fetchData('/status', 'no-cache', { tags: ['status'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { MixerHorizontalIcon } from '@radix-ui/react-icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { type IPosition } from './type';
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -13,35 +12,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Master Employee Position",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/position', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['position']
|
||||
}
|
||||
})
|
||||
|
||||
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 page() {
|
||||
const data = await getData()
|
||||
export default async function PositionPage() {
|
||||
await getAccessPagePermission('/information/position')
|
||||
const data = await fetchData('/position', 'no-cache', { tags: ['position'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -50,7 +23,7 @@ export default async function page() {
|
||||
<CardHeader className='flex flex-row items-center justify-between space-y-2 sm:space-y-0'>
|
||||
<div>
|
||||
<CardTitle>Position</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of empoyee's position that have been registered!</CardDescription>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of empoyee's position that have been registered!</CardDescription>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { FC, ReactNode, useState } from 'react';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
type Props = {
|
||||
title?: string
|
||||
description?: string
|
||||
onConfirm: () => Promise<any>
|
||||
okText?: string
|
||||
cancelText?: string
|
||||
contentSuccess?: ReactNode | string
|
||||
onOkSuccess?: () => any
|
||||
};
|
||||
|
||||
const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancelText, contentSuccess, onOkSuccess }) => {
|
||||
const [isLoading, setIsloading] = useState(false)
|
||||
const router = useRouter()
|
||||
|
||||
const confirm = async () => {
|
||||
if (isLoading) return
|
||||
try {
|
||||
setIsloading(true)
|
||||
const res: ResponseData = await onConfirm()
|
||||
setIsloading(false)
|
||||
|
||||
console.log(res)
|
||||
if (!res) return
|
||||
|
||||
if (res.code === '00') {
|
||||
showSuccess()
|
||||
} else {
|
||||
showError(res.message)
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.log(error)
|
||||
setIsloading(false)
|
||||
showError(error?.message)
|
||||
}
|
||||
}
|
||||
|
||||
const showSuccess = () => {
|
||||
router.refresh()
|
||||
toast.success(contentSuccess || 'Data successfully removed.' as string)
|
||||
onOkSuccess!()
|
||||
};
|
||||
|
||||
const showError = (message?: string) => {
|
||||
toast.error(message)
|
||||
};
|
||||
|
||||
return (
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{description || 'This action cannot be undone. This will permanently delete this data and remove from our servers.'}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isLoading}>{cancelText || 'Cancel'}</AlertDialogCancel>
|
||||
<AlertDialogAction disabled={isLoading} onClick={confirm}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
{okText || 'Continue'}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
export default ConfirmAsync;
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from '@/app/admin/rbac/user-role/component/RoleForm';
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from '@/app/admin/rbac/user-role/component';
|
||||
@@ -1,4 +0,0 @@
|
||||
import { type IRole } from '@/types/rbac';
|
||||
|
||||
export type { IRole };
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
export interface IRole {
|
||||
id: number,
|
||||
name: string,
|
||||
status: {
|
||||
id: number,
|
||||
code: "A" | 'N' | 'X',
|
||||
name: "ACTIVE" | 'INACTIVE' | 'DELETED'
|
||||
},
|
||||
description: string
|
||||
allow_admin?: boolean
|
||||
privilege?: any
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
export default function DeprecatedUserRolePage() {
|
||||
redirect('/admin/rbac/user-role');
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -13,35 +12,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Master Working Status",
|
||||
}
|
||||
|
||||
async function getData(current_page?: string, limit?: string) {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/presence/list-status', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['working-status']
|
||||
}
|
||||
})
|
||||
|
||||
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 page() {
|
||||
const data = await getData()
|
||||
export default async function WorkingStatusPage() {
|
||||
await getAccessPagePermission('/information/working-status')
|
||||
const data = await fetchData('/presence/list-status', 'no-cache', { tags: ['working-status'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { forbidden } from "next/navigation";
|
||||
import { ToggleTheme } from "./components/ToggleTheme";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Notification from "./components/Notification";
|
||||
@@ -22,6 +23,10 @@ export const metadata: Metadata = {
|
||||
export default async function AdminLayout({ children }: { children: React.ReactNode }) {
|
||||
const data = await getAccessData()
|
||||
|
||||
if (!data?.allow_admin_panel) {
|
||||
forbidden()
|
||||
}
|
||||
|
||||
const cleanPath = (path: string): string => {
|
||||
if (!path || path === '/') return ''
|
||||
const sanitized = path.replace(/\/+/g, '/')
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
@@ -19,6 +20,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const ApprovalAutoCheckoutPage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/manual/approval-autocheckout')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -33,9 +36,11 @@ const ApprovalAutoCheckoutPage: FC<Props> = async ({ searchParams }) => {
|
||||
<CardTitle>Approval Auto Checkout</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of employee attendance that forgot to checkout!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
|
||||
@@ -4,6 +4,7 @@ import dayjs from 'dayjs';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
@@ -18,6 +19,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const ApprovalNonWFOPage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/manual/approval')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -32,9 +35,11 @@ const ApprovalNonWFOPage: FC<Props> = async ({ searchParams }) => {
|
||||
<CardTitle>Approval Attendance</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of approval attendance those working outside the office!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
|
||||
@@ -15,7 +15,7 @@ export const metadata: Metadata = {
|
||||
type Props = {};
|
||||
|
||||
const ManualPresencePage: FC<Props> = async () => {
|
||||
const actions = await getAccessPagePermission('/manual/manual-presence', 'CREATE')
|
||||
const actions = await getAccessPagePermission('/manual/manual-presence')
|
||||
|
||||
const fetchUser = fetchData('/user')
|
||||
const fetchStatus = fetchData('/presence/list-status')
|
||||
|
||||
@@ -5,10 +5,8 @@ import { MoreHorizontalIcon } from 'lucide-react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { PlusCircledIcon } from '@radix-ui/react-icons';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
@@ -21,9 +19,10 @@ import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInpu
|
||||
|
||||
type Props = {
|
||||
data: IClient[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IClient[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IClient>()
|
||||
@@ -133,7 +132,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
||||
@@ -143,10 +142,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem><Link href={`/task/client-detail/${record.id}`} className='w-full'>View Details</Link></DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Client</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Client
|
||||
</DropdownMenuItem>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Client</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Client
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
@@ -175,10 +178,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search data..." className="h-8 w-full sm:w-62.5" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Client
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Client
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { 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 ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
@@ -11,6 +12,7 @@ export const metadata: Metadata = {
|
||||
title: "Client - Project Assignment | Admin",
|
||||
}
|
||||
export default async function ClientPage() {
|
||||
const actions = await getAccessPagePermission('/project-assignment/client')
|
||||
const data = await fetchData('/client')
|
||||
|
||||
return (
|
||||
@@ -22,13 +24,15 @@ export default async function ClientPage() {
|
||||
<CardTitle>Client Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of clients that have been registered for project assignment!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data} />
|
||||
<ComponentPage data={data} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -18,9 +18,10 @@ import FormEndUser from '@/app/(dashboard)/task/component/FormEndUser';
|
||||
|
||||
type Props = {
|
||||
data: IEndUser[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IEndUser[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IEndUser>()
|
||||
@@ -115,7 +116,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
||||
@@ -124,10 +125,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit End User</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete End User
|
||||
</DropdownMenuItem>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit End User</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete End User
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
@@ -156,10 +161,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search data..." className="h-8 w-full sm:w-62.5" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New End User
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New End User
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { 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 ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
@@ -11,6 +12,7 @@ export const metadata: Metadata = {
|
||||
title: "End User - Project Assignment | Admin",
|
||||
}
|
||||
export default async function EndUserPage() {
|
||||
const actions = await getAccessPagePermission('/project-assignment/end-user')
|
||||
const data = await fetchData('/end-user')
|
||||
|
||||
return (
|
||||
@@ -22,13 +24,15 @@ export default async function EndUserPage() {
|
||||
<CardTitle>End User Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of end users that have been registered for project assignment!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data} />
|
||||
<ComponentPage data={data} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -17,9 +17,10 @@ import FormProject from './FormProject';
|
||||
|
||||
type Props = {
|
||||
data: IProjectAssignment[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IProjectAssignment[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IProjectAssignment>()
|
||||
@@ -135,7 +136,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
||||
@@ -144,10 +145,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Project</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Project
|
||||
</DropdownMenuItem>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Project</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Project
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
@@ -176,10 +181,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search data..." className="h-8 w-full sm:w-62.5" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Project
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Project
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { 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 ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
@@ -11,6 +12,7 @@ export const metadata: Metadata = {
|
||||
title: "Project - Project Assignment | Admin",
|
||||
}
|
||||
export default async function ProjectManagementPage() {
|
||||
const actions = await getAccessPagePermission('/project-assignment/project-management')
|
||||
const data = await fetchData('/project')
|
||||
|
||||
return (
|
||||
@@ -22,13 +24,15 @@ export default async function ProjectManagementPage() {
|
||||
<CardTitle>Project Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of projects that have been registered for project assignment!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data} />
|
||||
<ComponentPage data={data} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -19,9 +19,10 @@ import RbacBadge from '@/components/ui/rbac-badge';
|
||||
|
||||
type Props = {
|
||||
data: IPermission[];
|
||||
actions?: string[];
|
||||
};
|
||||
|
||||
const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPermissionPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IPermission[]>([]);
|
||||
const [selectedData, setSelectedData] = useState<IPermission | undefined>(undefined);
|
||||
const [showFormDialog, setShowFormDialog] = useState(false);
|
||||
@@ -97,7 +98,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
key: 'action',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE') && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -107,19 +108,23 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setSelectedData(record);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
Edit Permission
|
||||
</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Permission
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setSelectedData(record);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
Edit Permission
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Permission
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -160,18 +165,20 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
onChange={handleSearch}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
onClick={() => {
|
||||
setSelectedData(undefined);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Permission
|
||||
</Button>
|
||||
{(!actions || actions.includes('CREATE')) && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
onClick={() => {
|
||||
setSelectedData(undefined);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Permission
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Table
|
||||
|
||||
@@ -3,6 +3,7 @@ import { 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 ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -27,6 +28,7 @@ async function getPermissions() {
|
||||
}
|
||||
|
||||
export default async function PermissionPage() {
|
||||
const actions = await getAccessPagePermission(['/rbac/action-permissions', '/rbac/action-pemission']);
|
||||
const permissions = await getPermissions();
|
||||
|
||||
return (
|
||||
@@ -42,7 +44,7 @@ export default async function PermissionPage() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={permissions} />
|
||||
<ComponentPage data={permissions} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -19,6 +19,7 @@ import { useRouter } from 'next/navigation';
|
||||
|
||||
type Props = {
|
||||
data: IMenu[];
|
||||
actions?: string[];
|
||||
};
|
||||
|
||||
// Transform flat menu list into hierarchical tree for Antd Table
|
||||
@@ -61,7 +62,7 @@ function buildMenuTree(items: IMenu[]): IMenu[] {
|
||||
return roots;
|
||||
}
|
||||
|
||||
const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
const ComponentMenuPage: FC<Props> = ({ data, actions }) => {
|
||||
const [rawMenus, setRawMenus] = useState<IMenu[]>([]);
|
||||
const [filterData, setFilterData] = useState<IMenu[]>([]);
|
||||
const [selectedData, setSelectedData] = useState<IMenu | undefined>(undefined);
|
||||
@@ -205,7 +206,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
key: 'row_action',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -215,19 +216,23 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setSelectedData(record);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
Edit Menu
|
||||
</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Menu
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setSelectedData(record);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
Edit Menu
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Menu
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -267,18 +272,20 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
onChange={handleSearch}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
onClick={() => {
|
||||
setSelectedData(undefined);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Menu
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
onClick={() => {
|
||||
setSelectedData(undefined);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Menu
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Table
|
||||
|
||||
@@ -3,6 +3,7 @@ import { 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 ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -27,6 +28,7 @@ async function getMenus() {
|
||||
}
|
||||
|
||||
export default async function MenuPage() {
|
||||
const actions = await getAccessPagePermission('/rbac/menu');
|
||||
const menus = await getMenus();
|
||||
|
||||
return (
|
||||
@@ -42,7 +44,7 @@ export default async function MenuPage() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={menus} />
|
||||
<ComponentPage data={menus} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { type Metadata } from 'next';
|
||||
import Link from 'next/link';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type IRole } from '../component/type';
|
||||
import RolePermissionRow from "../component/role-permission-row";
|
||||
@@ -39,6 +40,7 @@ async function getRoleData(id: string): Promise<IRole | undefined> {
|
||||
}
|
||||
|
||||
const UserRoleDetailPage: FC<Props> = async ({ params }) => {
|
||||
const actions = await getAccessPagePermission('/rbac/user-role', 'VIEW');
|
||||
const { id } = await params;
|
||||
const data: IRole | undefined = await getRoleData(id);
|
||||
|
||||
@@ -109,11 +111,13 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
|
||||
</CardDescription>
|
||||
</div>
|
||||
</div>
|
||||
<Link href={`/admin/rbac/user-role/edit/${id}`}>
|
||||
<Button className="bg-his hover:bg-his/90 text-white font-medium">
|
||||
<PencilLine /> Edit Role
|
||||
</Button>
|
||||
</Link>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<Link href={`/admin/rbac/user-role/edit/${id}`}>
|
||||
<Button className="bg-his hover:bg-his/90 text-white font-medium">
|
||||
<PencilLine /> Edit Role
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 p-4 md:p-6 rounded-lg bg-zinc-50/60 dark:bg-zinc-900/40 border border-zinc-200 dark:border-zinc-800">
|
||||
|
||||
@@ -17,9 +17,10 @@ import { type IRole } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IRole[];
|
||||
actions?: string[];
|
||||
};
|
||||
|
||||
const ComponentRolePage: FC<Props> = ({ data }) => {
|
||||
const ComponentRolePage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IRole[]>([]);
|
||||
const [searchText, setSearchText] = useState('');
|
||||
|
||||
@@ -140,7 +141,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
||||
key: 'action',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -155,16 +156,20 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
||||
View Details
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/admin/rbac/user-role/edit/${record.id}`}>
|
||||
Edit Role
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Role
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/admin/rbac/user-role/edit/${record.id}`}>
|
||||
Edit Role
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Role
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -204,16 +209,18 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
||||
onChange={handleSearch}
|
||||
/>
|
||||
</div>
|
||||
<Link href="/admin/rbac/user-role/create">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Role
|
||||
</Button>
|
||||
</Link>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Link href="/admin/rbac/user-role/create">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Role
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Table
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
import RoleForm from '../component/RoleForm';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
@@ -6,6 +7,7 @@ export const metadata: Metadata = {
|
||||
description: "Create a new user role with custom menu permissions",
|
||||
};
|
||||
|
||||
export default function CreateRolePage() {
|
||||
export default async function CreateRolePage() {
|
||||
await getAccessPagePermission('/rbac/user-role', 'CREATE');
|
||||
return <RoleForm isUpdate={false} />;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type Metadata } from 'next';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
import RoleForm from '../../component/RoleForm';
|
||||
import { type IRole } from '../../component/type';
|
||||
|
||||
@@ -34,6 +35,7 @@ async function getRoleData(id: string): Promise<IRole | undefined> {
|
||||
}
|
||||
|
||||
export default async function EditRolePage({ params }: Props) {
|
||||
await getAccessPagePermission('/rbac/user-role', 'UPDATE');
|
||||
const { id } = await params;
|
||||
const roleData = await getRoleData(id);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { 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 ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -27,6 +28,7 @@ async function getRoles() {
|
||||
}
|
||||
|
||||
export default async function UserRolePage() {
|
||||
const actions = await getAccessPagePermission('/rbac/user-role');
|
||||
const roles = await getRoles();
|
||||
|
||||
return (
|
||||
@@ -42,7 +44,7 @@ export default async function UserRolePage() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={roles} />
|
||||
<ComponentPage data={roles} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -12,9 +12,10 @@ const ExportComponent = lazy(() => import('./Export'));
|
||||
|
||||
type Props = {
|
||||
data: IHistory[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [groupData, setGroupData] = useState<any>(null)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -664,9 +665,11 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<CardTitle>Attendance Distribution</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of all employee attendance distribution!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={groupData} />
|
||||
</Suspense>
|
||||
{actions?.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={groupData} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className='flex flex-col space-y-4'>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Card } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -18,6 +19,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const AttendanceDistributionPage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/report/distribution')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -28,7 +31,7 @@ const AttendanceDistributionPage: FC<Props> = async ({ searchParams }) => {
|
||||
<div className="flex flex-col">
|
||||
<Card>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data.history} />
|
||||
<ComponentPage data={data.history} actions={actions} />
|
||||
</Suspense>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -13,9 +13,10 @@ import useDebounce from '@/hooks/useDebounce';
|
||||
|
||||
type Props = {
|
||||
data: IHistory[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [currentDataTable, setCurrentDataTable] = useState<IHistory[]>([])
|
||||
const [searchText, setSearchText] = useState<string>('')
|
||||
|
||||
@@ -79,15 +80,17 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<CardTitle>Attendance History</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of all employee attendance history!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={exportData} />
|
||||
</Suspense>
|
||||
{actions?.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={exportData} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search report..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
<Input placeholder="Search report..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
</div>
|
||||
<Table
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Card } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -17,6 +18,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const MonthlyPresencePage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/report/history')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -27,9 +30,7 @@ const MonthlyPresencePage: FC<Props> = async ({ searchParams }) => {
|
||||
<div className="flex flex-col">
|
||||
<Card>
|
||||
<Suspense fallback={<div className='flex justify-center items-center w-full h-[40vh]'><LazyLoading /></div>}>
|
||||
<ComponentPage
|
||||
data={data.history}
|
||||
/>
|
||||
<ComponentPage data={data.history} actions={actions} />
|
||||
</Suspense>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
@@ -18,6 +19,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const LeavePermitSickReportPage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/report/leave-permit-sick')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -32,9 +35,11 @@ const LeavePermitSickReportPage: FC<Props> = async ({ searchParams }) => {
|
||||
<CardTitle>Leave, Permit and Sick Report</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of application form for leave, permit and sick!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
|
||||
@@ -4,6 +4,7 @@ import dayjs from 'dayjs';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
@@ -18,6 +19,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const SummaryAttendancePage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/report/monthly-presence')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -32,9 +35,11 @@ const SummaryAttendancePage: FC<Props> = async ({ searchParams }) => {
|
||||
<CardTitle>Summary Attendance Report</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of summary employee attendance report!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.report} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.report} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
|
||||
Reference in New Issue
Block a user