Merge pull request 'update permission display for leave management' (#133) from vi.ticket-email into dev

Reviewed-on: #133
This commit is contained in:
joseph 2025-07-02 11:23:51 +10:00
commit 3e865e5575
1 changed files with 136 additions and 71 deletions

View File

@ -40,6 +40,8 @@ import {
} from '@/api/Admin' } from '@/api/Admin'
import { update, Xdelete } from '@/rtk/helpers/CRUD' import { update, Xdelete } from '@/rtk/helpers/CRUD'
import { get, exportFile } from '@/rtk/helpers/apiService' import { get, exportFile } from '@/rtk/helpers/apiService'
import { useSelector } from 'react-redux'
import { RootState } from '@/rtk/store'
interface User { interface User {
id: number id: number
@ -95,6 +97,8 @@ interface UserData {
// } // }
const LeaveManagement = () => { const LeaveManagement = () => {
const user = useSelector((state: RootState) => state.authentication)
const [opened1, { open: open1, close: close1 }] = useDisclosure(false) const [opened1, { open: open1, close: close1 }] = useDisclosure(false)
const [openedDetailOff, { open: openDetailOff, close: closeDetailOff }] = const [openedDetailOff, { open: openDetailOff, close: closeDetailOff }] =
useDisclosure(false) useDisclosure(false)
@ -527,6 +531,14 @@ const LeaveManagement = () => {
}} }}
label={'Phép năm'} label={'Phép năm'}
placeholder="Nhập số ngày phép năm" placeholder="Nhập số ngày phép năm"
disabled={
!['admin', 'hr'].some((role) =>
user.user.user.permission
.split(',')
.map((p: string) => p.trim())
.includes(role),
)
}
/> />
<TextInput <TextInput
mb={'md'} mb={'md'}
@ -554,6 +566,14 @@ const LeaveManagement = () => {
}} }}
label={'Phép năm cũ'} label={'Phép năm cũ'}
placeholder="Nhập số ngày phép năm cũ" placeholder="Nhập số ngày phép năm cũ"
disabled={
!['admin', 'hr'].some((role) =>
user.user.user.permission
.split(',')
.map((p: string) => p.trim())
.includes(role),
)
}
/> />
<TextInput <TextInput
mb={'md'} mb={'md'}
@ -581,6 +601,14 @@ const LeaveManagement = () => {
}} }}
label={'Phép đặc biệt'} label={'Phép đặc biệt'}
placeholder="Nhập số ngày phép đặc biệt" placeholder="Nhập số ngày phép đặc biệt"
disabled={
!['admin', 'hr'].some((role) =>
user.user.user.permission
.split(',')
.map((p: string) => p.trim())
.includes(role),
)
}
/> />
<Textarea <Textarea
mb={'md'} mb={'md'}
@ -590,8 +618,22 @@ const LeaveManagement = () => {
setCustomAddNotes({ ...customAddNotes, note: e.target.value }) setCustomAddNotes({ ...customAddNotes, note: e.target.value })
}} }}
rows={10} rows={10}
disabled={
!['admin', 'hr'].some((role) =>
user.user.user.permission
.split(',')
.map((p: string) => p.trim())
.includes(role),
)
}
/> />
{['admin', 'hr'].some((role) =>
user.user.user.permission
.split(',')
.map((p: string) => p.trim())
.includes(role),
) ? (
<Button <Button
onClick={() => { onClick={() => {
setDisableBtn(true) setDisableBtn(true)
@ -624,6 +666,9 @@ const LeaveManagement = () => {
> >
Save Save
</Button> </Button>
) : (
''
)}
</Drawer> </Drawer>
{/* Filter Year, Export Btn */} {/* Filter Year, Export Btn */}
@ -1102,7 +1147,17 @@ const LeaveManagement = () => {
<Table.Tr> <Table.Tr>
<Table.Th>Time</Table.Th> <Table.Th>Time</Table.Th>
<Table.Th>Status</Table.Th> <Table.Th>Status</Table.Th>
{['admin', 'hr'].some((role) =>
user.user.user.permission
.split(',')
.map((p: string) => p.trim())
.includes(role),
) ? (
<Table.Th>Action</Table.Th> <Table.Th>Action</Table.Th>
) : (
''
)}
</Table.Tr> </Table.Tr>
</Table.Thead> </Table.Thead>
@ -1129,6 +1184,13 @@ const LeaveManagement = () => {
{item.reason_name} {item.reason_name}
</Badge> </Badge>
</Table.Td> </Table.Td>
{['admin', 'hr'].some((role) =>
user.user.user.permission
.split(',')
.map((p: string) => p.trim())
.includes(role),
) ? (
<Table.Td> <Table.Td>
{item.reason_code === 'ONLEAVE' ? ( {item.reason_code === 'ONLEAVE' ? (
<IconRefresh <IconRefresh
@ -1173,6 +1235,9 @@ const LeaveManagement = () => {
height={20} height={20}
/> />
</Table.Td> </Table.Td>
) : (
''
)}
</Table.Tr> </Table.Tr>
) )
})} })}