From 0f84963214ee6dc5b5a44d945540826a66bec9e0 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 11 Dec 2024 11:51:45 +0700 Subject: update pengajuan tempo --- src/lib/pengajuan-tempo/component/Referensi.jsx | 81 ++++++++++++++++++++----- 1 file changed, 66 insertions(+), 15 deletions(-) (limited to 'src/lib/pengajuan-tempo/component/Referensi.jsx') diff --git a/src/lib/pengajuan-tempo/component/Referensi.jsx b/src/lib/pengajuan-tempo/component/Referensi.jsx index 6d9d0bd6..1b7b0f4c 100644 --- a/src/lib/pengajuan-tempo/component/Referensi.jsx +++ b/src/lib/pengajuan-tempo/component/Referensi.jsx @@ -10,8 +10,12 @@ import { PlusCircleIcon } from '@heroicons/react/24/outline'; import useDevice from '@/core/hooks/useDevice'; import { Trash2Icon } from 'lucide-react'; import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline'; +import BottomPopup from '@/core/components/elements/Popup/BottomPopup'; const initialData = []; const Referensi = ({ chekValid, buttonSubmitClick, data }) => { + const [changeConfirmation, setChangeConfirmation] = useState(false); + const [selectedIndex, setSelectedIndex] = useState(null); + const { isDesktop, isMobile } = useDevice(); const [openIndexes, setOpenIndexes] = useState([]); @@ -26,7 +30,7 @@ const Referensi = ({ chekValid, buttonSubmitClick, data }) => { resolver: yupResolver(validationSchema), defaultValues, }); - const { formSupplier, updateFormSupplier, updateHasSave } = + const { formSupplier, updateFormSupplier, updateHasSave, hasSavedata } = usePengajuanTempoStoreSupplier(); const { form } = usePengajuanTempoStore(); const [formData, setFormData] = useState([ @@ -63,9 +67,8 @@ const Referensi = ({ chekValid, buttonSubmitClick, data }) => { const editData = supplierData.map((item, i) => i === index ? { ...item, [name]: formattedValue } : item ); - setSupplierData(editData); - if (value == '') { + if (value == '' && supplierData.supplier) { updateHasSave(true); } }; @@ -89,12 +92,26 @@ const Referensi = ({ chekValid, buttonSubmitClick, data }) => { } }; - const handleDeleteSupplier = (index) => { - // updateHasSave(false); // Indikasi bahwa data telah berubah - - const updatedData = supplierData.filter((_, i) => i !== index); - setSupplierData(updatedData); - updateFormSupplier(updatedData); // Update store atau state terkait + useEffect(() => { + const isAllFieldsEmpty = Object.values(newSupplier).every( + (value) => value === '' + ); + if (isAllFieldsEmpty) { + updateHasSave(true); + } else { + updateHasSave(false); + } + }, [newSupplier]); + + const handleDeleteSupplier = () => { + if (selectedIndex !== null) { + // Logika untuk menghapus supplier + const updatedSuppliers = supplierData.filter( + (_, idx) => idx !== selectedIndex + ); + setSupplierData(updatedSuppliers); + setChangeConfirmation(false); + } }; const handleAddNewSupplier = () => { @@ -181,8 +198,37 @@ const Referensi = ({ chekValid, buttonSubmitClick, data }) => { ); }; + const handleOpenConfirmation = (index) => { + setSelectedIndex(index); + setChangeConfirmation(true); + }; return ( <> + setChangeConfirmation(false)} + title='Ubah profil Bisnis' + > +
+ Apakah anda yakin menghapus data? +
+
+ + +
+
{isDesktop && (
@@ -262,7 +308,8 @@ const Referensi = ({ chekValid, buttonSubmitClick, data }) => { /> handleDeleteSupplier(index)} + onClick={() => handleOpenConfirmation(index)} + className='cursor-pointer' /> @@ -332,13 +379,15 @@ const Referensi = ({ chekValid, buttonSubmitClick, data }) => { className='bg-gray-200 border border-gray-500 rounded-md text-sm text-gray-500 p-2 h-11 mb-1 content-center flex flex-row justify-center items-center' > {} - {''} Tambah data baru + {''} Tambah Data Baru *Klik simpan sebelum lanjut ke tahap selanjutnya @@ -546,9 +595,11 @@ const Referensi = ({ chekValid, buttonSubmitClick, data }) => {
-- cgit v1.2.3