();
- const [opened, { open, close }] = useDisclosure(false);
+
+ async function onUpdate() {
+ setLoading(true);
+ const body = {
+ id: data.id,
+ donasiMaster_KategoriId: data.DonasiMaster_Ketegori.id,
+ donasiMaster_DurasiId: data.DonasiMaster_Durasi.id,
+ title: data.title,
+ target: data.target,
+ };
+
+ if (_.values(body).includes(""))
+ return ComponentGlobal_NotifikasiPeringatan("Lengkapin Data");
+
+ try {
+ if (file !== null) {
+ const uploadImage = await funGlobal_UploadToStorage({
+ file: file as File,
+ dirId: DIRECTORY_ID.donasi_image,
+ });
+ if (!uploadImage.success) {
+ setLoading(false);
+ ComponentGlobal_NotifikasiPeringatan("Gagal upload file gambar");
+ }
+
+ const deleteImage = await funGlobal_DeleteFileById({
+ fileId: data.imageId,
+ });
+ if (!deleteImage.success) {
+ setLoading(false);
+ ComponentGlobal_NotifikasiPeringatan("Gagal hapus gambar lama");
+ }
+
+ const res = await Donasi_funUpdateDonasi({
+ data: body as any,
+ fileId: uploadImage.data.id,
+ });
+ if (res.status === 200) {
+ ComponentGlobal_NotifikasiBerhasil(res.message);
+ router.back();
+ setLoading(false);
+ } else {
+ ComponentGlobal_NotifikasiPeringatan(res.message);
+ setLoading(false);
+ }
+ } else {
+ const res = await Donasi_funUpdateDonasi({
+ data: body as any,
+ });
+ if (res.status === 200) {
+ ComponentGlobal_NotifikasiBerhasil(res.message);
+ router.back();
+ setLoading(false);
+ } else {
+ ComponentGlobal_NotifikasiPeringatan(res.message);
+ setLoading(false);
+ }
+ }
+ } catch (error) {
+ console.log(error);
+ }
+ }
return (
<>
- {/* {JSON.stringify(donasi, null, 2)} */}