feat(FE-170): add approval logic to RecordingForm for detail view actions

This commit is contained in:
rstubryan
2025-11-06 17:17:49 +07:00
parent d8b076d105
commit b24c9d8336
@@ -94,6 +94,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
const rejectModal = useModal(); const rejectModal = useModal();
const deleteModal = useModal(); const deleteModal = useModal();
const isRecordingApproved = useCallback((recording?: Recording) => {
return (
recording?.approval?.action === 'APPROVED' &&
recording?.approval?.step_name === 'Disetujui' &&
recording?.approval?.step_number === 3
);
}, []);
// ===== FORM HANDLERS ===== // ===== FORM HANDLERS =====
const createRecordingHandler = useCallback( const createRecordingHandler = useCallback(
async ( async (
@@ -1281,7 +1289,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
Kembali Kembali
</Button> </Button>
{type === 'detail' && ( {type === 'detail' && !isRecordingApproved(initialValues) && (
<div className='flex flex-row gap-2'> <div className='flex flex-row gap-2'>
<Button <Button
variant='outline' variant='outline'
@@ -2406,7 +2414,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
{/* Action buttons */} {/* Action buttons */}
<div className='flex flex-row justify-between gap-2 flex-wrap'> <div className='flex flex-row justify-between gap-2 flex-wrap'>
{/* Left side - Detail & Edit actions */} {/* Left side - Detail & Edit actions */}
{type !== 'add' && ( {type !== 'add' && !isRecordingApproved(initialValues) && (
<div className='flex flex-row justify-start gap-2'> <div className='flex flex-row justify-start gap-2'>
{type === 'detail' && deleteRecordingClickHandler && ( {type === 'detail' && deleteRecordingClickHandler && (
<Button <Button
@@ -2561,7 +2569,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
</section> </section>
{/* ===== MODALS ===== */} {/* ===== MODALS ===== */}
{type !== 'add' && ( {type !== 'add' && !isRecordingApproved(initialValues) && (
<> <>
<ConfirmationModal <ConfirmationModal
ref={deleteModal.ref} ref={deleteModal.ref}
@@ -2579,7 +2587,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
/> />
{/* Approve Confirmation Modal */} {/* Approve Confirmation Modal */}
{(type as 'add' | 'edit' | 'detail') === 'detail' && ( {(type as 'add' | 'edit' | 'detail') === 'detail' &&
!isRecordingApproved(initialValues) && (
<ConfirmationModal <ConfirmationModal
ref={approveModal.ref} ref={approveModal.ref}
type='success' type='success'
@@ -2597,7 +2606,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
)} )}
{/* Reject Confirmation Modal */} {/* Reject Confirmation Modal */}
{(type as 'add' | 'edit' | 'detail') === 'detail' && ( {(type as 'add' | 'edit' | 'detail') === 'detail' &&
!isRecordingApproved(initialValues) && (
<ConfirmationModal <ConfirmationModal
ref={rejectModal.ref} ref={rejectModal.ref}
type='error' type='error'