mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
refactor(FE-170,174): refine RecordingTable approval logic and remove unused tooltips
This commit is contained in:
@@ -28,7 +28,6 @@ import Badge from '@/components/Badge';
|
|||||||
import CheckboxInput from '@/components/input/CheckboxInput';
|
import CheckboxInput from '@/components/input/CheckboxInput';
|
||||||
import TextArea from '@/components/input/TextArea';
|
import TextArea from '@/components/input/TextArea';
|
||||||
import { BaseApproval, BaseApiResponse } from '@/types/api/api-general';
|
import { BaseApproval, BaseApiResponse } from '@/types/api/api-general';
|
||||||
import { router } from 'next/client';
|
|
||||||
|
|
||||||
const RowOptionsMenu = ({
|
const RowOptionsMenu = ({
|
||||||
type = 'dropdown',
|
type = 'dropdown',
|
||||||
@@ -59,15 +58,6 @@ const RowOptionsMenu = ({
|
|||||||
const isApproved = isRecordingApproved(props.row.original);
|
const isApproved = isRecordingApproved(props.row.original);
|
||||||
const isGradingDone = isGradingCompleted(props.row.original);
|
const isGradingDone = isGradingCompleted(props.row.original);
|
||||||
|
|
||||||
const getApprovalTooltip = () => {
|
|
||||||
if (isLayingCategory && !isGradingDone) {
|
|
||||||
return 'Recording LAYING belum bisa disetujui/ditolak karena grading telur belum selesai';
|
|
||||||
}
|
|
||||||
return isGradingDone
|
|
||||||
? 'Recording bisa disetujui karena sudah grading'
|
|
||||||
: 'Recording bisa disetujui';
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RowOptionsMenuWrapper type={type}>
|
<RowOptionsMenuWrapper type={type}>
|
||||||
<Button
|
<Button
|
||||||
@@ -94,7 +84,6 @@ const RowOptionsMenu = ({
|
|||||||
color='info'
|
color='info'
|
||||||
className={`justify-start text-sm`}
|
className={`justify-start text-sm`}
|
||||||
href={`/production/recording/grading/add?recording_id=${props.row.original.id}`}
|
href={`/production/recording/grading/add?recording_id=${props.row.original.id}`}
|
||||||
title={'Lanjut ke proses grading untuk telur konsumsi baik'}
|
|
||||||
>
|
>
|
||||||
<Icon icon='material-symbols:egg' width={16} height={16} />
|
<Icon icon='material-symbols:egg' width={16} height={16} />
|
||||||
Grading
|
Grading
|
||||||
@@ -106,7 +95,6 @@ const RowOptionsMenu = ({
|
|||||||
variant='ghost'
|
variant='ghost'
|
||||||
color='success'
|
color='success'
|
||||||
className='justify-start text-sm'
|
className='justify-start text-sm'
|
||||||
title={getApprovalTooltip()}
|
|
||||||
>
|
>
|
||||||
<Icon icon='material-symbols:check' width={16} height={16} />
|
<Icon icon='material-symbols:check' width={16} height={16} />
|
||||||
Approve
|
Approve
|
||||||
@@ -118,7 +106,6 @@ const RowOptionsMenu = ({
|
|||||||
variant='ghost'
|
variant='ghost'
|
||||||
color='error'
|
color='error'
|
||||||
className='justify-start text-sm'
|
className='justify-start text-sm'
|
||||||
title={getApprovalTooltip()}
|
|
||||||
>
|
>
|
||||||
<Icon icon='material-symbols:close' width={16} height={16} />
|
<Icon icon='material-symbols:close' width={16} height={16} />
|
||||||
Reject
|
Reject
|
||||||
@@ -332,10 +319,7 @@ const ApprovalHistoryModal = ({
|
|||||||
</Badge>
|
</Badge>
|
||||||
</td>
|
</td>
|
||||||
<td className='max-w-xs'>
|
<td className='max-w-xs'>
|
||||||
<div
|
<div className='truncate'>
|
||||||
className='truncate'
|
|
||||||
title={approval.notes || '-'}
|
|
||||||
>
|
|
||||||
{approval.notes || '-'}
|
{approval.notes || '-'}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
@@ -541,13 +525,17 @@ const RecordingTable = () => {
|
|||||||
const recording = recordings.data.find((r) => r.id === id);
|
const recording = recordings.data.find((r) => r.id === id);
|
||||||
if (!recording || isRecordingApproved(recording)) return false;
|
if (!recording || isRecordingApproved(recording)) return false;
|
||||||
|
|
||||||
if (recording.project_flock_category === 'LAYING') {
|
if (recording.project_flock_category === 'GROWING') {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return recording.project_flock_category === 'GROWING';
|
if (recording.project_flock_category === 'LAYING') {
|
||||||
|
return isGradingCompleted(recording);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
}, [selectedRowIds, recordings, isRecordingApproved]);
|
}, [selectedRowIds, recordings, isRecordingApproved, isGradingCompleted]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isResponseSuccess(recordings) && recordings.data) {
|
if (isResponseSuccess(recordings) && recordings.data) {
|
||||||
@@ -558,12 +546,15 @@ const RecordingTable = () => {
|
|||||||
const recording = recordings.data.find(
|
const recording = recordings.data.find(
|
||||||
(r) => r.id === parseInt(rowId)
|
(r) => r.id === parseInt(rowId)
|
||||||
);
|
);
|
||||||
if (
|
if (recording && !isRecordingApproved(recording)) {
|
||||||
recording &&
|
if (recording.project_flock_category === 'GROWING') {
|
||||||
recording.project_flock_category === 'GROWING' &&
|
newSelection[rowId] = true;
|
||||||
!isRecordingApproved(recording)
|
} else if (
|
||||||
) {
|
recording.project_flock_category === 'LAYING' &&
|
||||||
newSelection[rowId] = true;
|
isGradingCompleted(recording)
|
||||||
|
) {
|
||||||
|
newSelection[rowId] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -574,7 +565,13 @@ const RecordingTable = () => {
|
|||||||
setRowSelection(newSelection);
|
setRowSelection(newSelection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [recordings, rowSelection, isRecordingApproved, setRowSelection]);
|
}, [
|
||||||
|
recordings,
|
||||||
|
rowSelection,
|
||||||
|
isRecordingApproved,
|
||||||
|
isGradingCompleted,
|
||||||
|
setRowSelection,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-full p-0 sm:p-4'>
|
<div className='w-full p-0 sm:p-4'>
|
||||||
@@ -604,11 +601,6 @@ const RecordingTable = () => {
|
|||||||
selectedRowIds.length === 0 || eligibleRowIds.length === 0
|
selectedRowIds.length === 0 || eligibleRowIds.length === 0
|
||||||
}
|
}
|
||||||
className='w-full sm:w-fit'
|
className='w-full sm:w-fit'
|
||||||
title={
|
|
||||||
eligibleRowIds.length === 0
|
|
||||||
? 'Hanya recording GROWING yang bisa disetujui'
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<Icon icon='material-symbols:check' width={24} height={24} />
|
<Icon icon='material-symbols:check' width={24} height={24} />
|
||||||
Approve
|
Approve
|
||||||
@@ -625,11 +617,6 @@ const RecordingTable = () => {
|
|||||||
selectedRowIds.length === 0 || eligibleRowIds.length === 0
|
selectedRowIds.length === 0 || eligibleRowIds.length === 0
|
||||||
}
|
}
|
||||||
className='w-full sm:w-fit'
|
className='w-full sm:w-fit'
|
||||||
title={
|
|
||||||
eligibleRowIds.length === 0
|
|
||||||
? 'Hanya recording GROWING yang bisa ditolak'
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<Icon icon='material-symbols:close' width={24} height={24} />
|
<Icon icon='material-symbols:close' width={24} height={24} />
|
||||||
Reject
|
Reject
|
||||||
@@ -717,11 +704,6 @@ const RecordingTable = () => {
|
|||||||
}
|
}
|
||||||
onChange={handleSelectAllGrowing}
|
onChange={handleSelectAllGrowing}
|
||||||
disabled={hasNoSelectableGrowing}
|
disabled={hasNoSelectableGrowing}
|
||||||
title={
|
|
||||||
hasNoSelectableGrowing
|
|
||||||
? 'Tidak ada recording GROWING yang bisa dipilih'
|
|
||||||
: 'Pilih semua recording GROWING'
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -736,11 +718,6 @@ const RecordingTable = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isDisabled = !row.getCanSelect() || isApproved;
|
const isDisabled = !row.getCanSelect() || isApproved;
|
||||||
let tooltip = '';
|
|
||||||
|
|
||||||
if (isApproved) {
|
|
||||||
tooltip = 'Recording sudah disetujui final';
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -750,7 +727,6 @@ const RecordingTable = () => {
|
|||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
indeterminate={row.getIsSomeSelected()}
|
indeterminate={row.getIsSomeSelected()}
|
||||||
onChange={row.getToggleSelectedHandler()}
|
onChange={row.getToggleSelectedHandler()}
|
||||||
title={tooltip}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -840,7 +816,6 @@ const RecordingTable = () => {
|
|||||||
'cursor-pointer hover:opacity-80 transition-opacity whitespace-nowrap',
|
'cursor-pointer hover:opacity-80 transition-opacity whitespace-nowrap',
|
||||||
}}
|
}}
|
||||||
onClick={openApprovalHistory}
|
onClick={openApprovalHistory}
|
||||||
title='Klik untuk lihat riwayat approval'
|
|
||||||
>
|
>
|
||||||
{getStatusText(approval.action)}
|
{getStatusText(approval.action)}
|
||||||
</Badge>
|
</Badge>
|
||||||
@@ -854,7 +829,7 @@ const RecordingTable = () => {
|
|||||||
if (!approval?.notes) return '-';
|
if (!approval?.notes) return '-';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='max-w-xs' title={approval.notes}>
|
<div className='max-w-xs'>
|
||||||
<p className='text-sm truncate'>{approval.notes}</p>
|
<p className='text-sm truncate'>{approval.notes}</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user