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,40 +618,57 @@ 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),
)
}
/> />
<Button {['admin', 'hr'].some((role) =>
onClick={() => { user.user.user.permission
setDisableBtn(true) .split(',')
if ( .map((p: string) => p.trim())
customAddNotes.id === 0 .includes(role),
// || ) ? (
// customAddNotes.totalLeave === '' || <Button
// customAddNotes.totalLeave === '0' onClick={() => {
// customAddNotes.dayAdditional === 0 || setDisableBtn(true)
// customAddNotes.note === '' if (
) { customAddNotes.id === 0
notifications.show({ // ||
title: 'Error', // customAddNotes.totalLeave === '' ||
message: 'Input data required', // customAddNotes.totalLeave === '0'
color: 'red', // customAddNotes.dayAdditional === 0 ||
}) // customAddNotes.note === ''
setDisableBtn(false) ) {
} else { notifications.show({
updateInfoNote( title: 'Error',
customAddNotes.id, message: 'Input data required',
customAddNotes.user, color: 'red',
customAddNotes.totalLeave, })
customAddNotes.dayAdditional, setDisableBtn(false)
customAddNotes.specialLeave, } else {
customAddNotes.note, updateInfoNote(
) customAddNotes.id,
} customAddNotes.user,
}} customAddNotes.totalLeave,
disabled={disableBtn} customAddNotes.dayAdditional,
> customAddNotes.specialLeave,
Save customAddNotes.note,
</Button> )
}
}}
disabled={disableBtn}
>
Save
</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>
<Table.Th>Action</Table.Th>
{['admin', 'hr'].some((role) =>
user.user.user.permission
.split(',')
.map((p: string) => p.trim())
.includes(role),
) ? (
<Table.Th>Action</Table.Th>
) : (
''
)}
</Table.Tr> </Table.Tr>
</Table.Thead> </Table.Thead>
@ -1129,50 +1184,60 @@ const LeaveManagement = () => {
{item.reason_name} {item.reason_name}
</Badge> </Badge>
</Table.Td> </Table.Td>
<Table.Td>
{item.reason_code === 'ONLEAVE' ? ( {['admin', 'hr'].some((role) =>
<IconRefresh user.user.user.permission
.split(',')
.map((p: string) => p.trim())
.includes(role),
) ? (
<Table.Td>
{item.reason_code === 'ONLEAVE' ? (
<IconRefresh
className={classes.deleteIcon}
onClick={() => {
setIsStatusConfirmOpen(true)
setNoteStatus({
id: item.id,
reason: 'LEAVE_WITHOUT_PAY',
})
}}
title="Chuyển thành không phép"
width={20}
height={20}
/>
) : item.reason_code === 'LEAVE_WITHOUT_PAY' ? (
<IconRefresh
className={classes.editIcon}
onClick={() => {
setIsStatusConfirmOpen(true)
setNoteStatus({
id: item.id,
reason: 'ONLEAVE',
})
}}
title="Chuyển thành có phép"
width={20}
height={20}
/>
) : (
''
)}
<IconTrash
className={classes.deleteIcon} className={classes.deleteIcon}
onClick={() => { onClick={() => {
setIsStatusConfirmOpen(true) setNoteToDelete(item)
setNoteStatus({ setIsDeleteConfirmOpen(true)
id: item.id,
reason: 'LEAVE_WITHOUT_PAY',
})
}} }}
title="Chuyển thành không phép" title="Xóa Note"
width={20} width={20}
height={20} height={20}
/> />
) : item.reason_code === 'LEAVE_WITHOUT_PAY' ? ( </Table.Td>
<IconRefresh ) : (
className={classes.editIcon} ''
onClick={() => { )}
setIsStatusConfirmOpen(true)
setNoteStatus({
id: item.id,
reason: 'ONLEAVE',
})
}}
title="Chuyển thành có phép"
width={20}
height={20}
/>
) : (
''
)}
<IconTrash
className={classes.deleteIcon}
onClick={() => {
setNoteToDelete(item)
setIsDeleteConfirmOpen(true)
}}
title="Xóa Note"
width={20}
height={20}
/>
</Table.Td>
</Table.Tr> </Table.Tr>
) )
})} })}