diff --git a/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx index 0423bd0..ca872db 100644 --- a/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx @@ -53,14 +53,20 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl useEffect(() => { requestServer(`${CONFIRM_PROVINCE_MANAGER_DETAILS}/${rowId}`, 'get') .then((response) => { - const allAttachments = []; - response.data.data.histories.map((history) => { - history.attachments.map((attachment) => { - allAttachments.push(attachment); - }); - }); - setAttachmentsData(allAttachments); - setDetailsData(response.data); + if (response.data.data.histories.length !== 0) { + let latest_attachments = [] + let attachments = [] + response.data.data.histories.map((allAttachment) => { + if (allAttachment.previous_state_id === 4 || allAttachment.previous_state_id === 5) { + if (!latest_attachments.includes(allAttachment.previous_state_id)) { + attachments = [...attachments, ...allAttachment.attachments] + latest_attachments.push(allAttachment.previous_state_id) + } + } + setDetailsData(response.data); + setAttachmentsData(attachments); + }) + } }) .catch(() => { }).finally(() => { diff --git a/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx index c3b04b4..1bae724 100644 --- a/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx @@ -44,14 +44,20 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl useEffect(() => { requestServer(`${GET_TRANSPORTATION_ASSISTANCE_DETAILS}/${rowId}`, 'get') .then((response) => { - const allAttachments = []; - response.data.data.histories.map((history) => { - history.attachments.map((attachment) => { - allAttachments.push(attachment); - }); - }); - setDetailsData(response.data); - setAttachmentsData(allAttachments); + if (response.data.data.histories.length !== 0) { + let latest_attachments = [] + let attachments = [] + response.data.data.histories.map((allAttachment) => { + if (allAttachment.previous_state_id !== 4) + return + if (!latest_attachments.includes(allAttachment.previous_state_id)) { + attachments = [...attachments, ...allAttachment.attachments] + latest_attachments.push(allAttachment.previous_state_id) + } + }) + setDetailsData(response.data); + setAttachmentsData(attachments); + } }) .catch(() => { }).finally(() => {