Donasi. Berikut adalah ringkasan perubahan yang telah dilakukan:
1. Menerapkan sistem pagination pada berbagai komponen layar donasi:
- ScreenBeranda.tsx
- ScreenMyDonation.tsx
- ScreenRecapOfNews.tsx
- ScreenListOfNews.tsx
- ScreenListOfDonatur.tsx
- ScreenFundDisbursement.tsx
2. Memperbarui fungsi-fungsi API untuk mendukung parameter page:
- apiDonationGetAll
- apiDonationGetNewsById
- apiDonationListOfDonaturById
- apiDonationDisbursementOfFundsListById
3. Mengganti komponen wrapper lama (ViewWrapper) dengan NewWrapper yang mendukung sistem pagination
4. Membuat komponen layar terpisah untuk meningkatkan modularitas kode
5. Memperbaiki berbagai error yang terjadi, termasuk masalah dengan import komponen dan struktur JSX
### No Issue
171 lines
4.2 KiB
TypeScript
171 lines
4.2 KiB
TypeScript
/* eslint-disable react-hooks/exhaustive-deps */
|
|
import {
|
|
BoxButtonOnFooter,
|
|
ButtonCenteredOnly,
|
|
ButtonCustom,
|
|
InformationBox,
|
|
LandscapeFrameUploaded,
|
|
Spacing,
|
|
StackCustom,
|
|
TextAreaCustom,
|
|
TextInputCustom,
|
|
ViewWrapper,
|
|
} from "@/components";
|
|
import API_STRORAGE from "@/constants/base-url-api-strorage";
|
|
import DIRECTORY_ID from "@/constants/directory-id";
|
|
import {
|
|
apiDonationGetNewsById,
|
|
apiDonationUpdateNews,
|
|
} from "@/service/api-client/api-donation";
|
|
import { uploadFileService } from "@/service/upload-service";
|
|
import pickFile, { IFileData } from "@/utils/pickFile";
|
|
import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
|
|
import { useCallback, useState } from "react";
|
|
import Toast from "react-native-toast-message";
|
|
|
|
export default function DonationEditNews() {
|
|
const { news } = useLocalSearchParams();
|
|
const [data, setData] = useState<any>(null);
|
|
const [image, setImage] = useState<IFileData | null>(null);
|
|
const [isLoading, setLoading] = useState(false);
|
|
|
|
useFocusEffect(
|
|
useCallback(() => {
|
|
onLoadData();
|
|
}, [news]),
|
|
);
|
|
|
|
const onLoadData = async () => {
|
|
try {
|
|
const response = await apiDonationGetNewsById({
|
|
id: news as string,
|
|
category: "get-one",
|
|
});
|
|
|
|
setData(response.data);
|
|
} catch (error) {
|
|
console.log("[ERROR]", error);
|
|
}
|
|
};
|
|
|
|
const handlerSubmitUpdate = async () => {
|
|
let newData;
|
|
if (!data.title || !data.deskripsi) {
|
|
Toast.show({
|
|
type: "error",
|
|
text1: "Judul dan deskripsi harus diisi",
|
|
});
|
|
return;
|
|
}
|
|
|
|
try {
|
|
setLoading(true);
|
|
|
|
newData = {
|
|
title: data?.title,
|
|
deskripsi: data?.deskripsi,
|
|
};
|
|
|
|
if (image && image?.uri) {
|
|
const uploadNewImage = await uploadFileService({
|
|
dirId: DIRECTORY_ID.donasi_kabar,
|
|
imageUri: image?.uri,
|
|
});
|
|
|
|
newData = {
|
|
title: data?.title,
|
|
deskripsi: data?.deskripsi,
|
|
newImageId: uploadNewImage.data.id,
|
|
};
|
|
}
|
|
|
|
const response = await apiDonationUpdateNews({
|
|
id: news as string,
|
|
data: newData,
|
|
});
|
|
|
|
if (!response.success) {
|
|
Toast.show({
|
|
type: "error",
|
|
text1: "Gagal mengupdate berita",
|
|
});
|
|
return;
|
|
}
|
|
|
|
Toast.show({
|
|
type: "success",
|
|
text1: "Berita berhasil diperbarui",
|
|
});
|
|
router.back();
|
|
} catch (error) {
|
|
console.log("[ERROR]", error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<ViewWrapper
|
|
footerComponent={
|
|
<BoxButtonOnFooter>
|
|
<ButtonCustom
|
|
disabled={!data?.title || !data?.deskripsi}
|
|
isLoading={isLoading}
|
|
onPress={() => {
|
|
handlerSubmitUpdate();
|
|
}}
|
|
>
|
|
Update
|
|
</ButtonCustom>
|
|
</BoxButtonOnFooter>
|
|
}
|
|
>
|
|
<StackCustom gap={"xs"}>
|
|
<InformationBox text="Upload gambar bersifat opsional untuk melengkapi kabar terkait donasi Anda." />
|
|
<LandscapeFrameUploaded
|
|
image={
|
|
image
|
|
? image.uri
|
|
: data && data.imageId
|
|
? API_STRORAGE.GET({ fileId: data.imageId })
|
|
: undefined
|
|
}
|
|
/>
|
|
<ButtonCenteredOnly
|
|
onPress={() => {
|
|
pickFile({
|
|
allowedType: "image",
|
|
setImageUri(file) {
|
|
setImage(file);
|
|
},
|
|
});
|
|
}}
|
|
icon="upload"
|
|
>
|
|
Upload
|
|
</ButtonCenteredOnly>
|
|
<Spacing />
|
|
<TextInputCustom
|
|
label="Judul Berita"
|
|
placeholder="Masukan judul berita"
|
|
required
|
|
value={data?.title}
|
|
onChangeText={(value) => setData({ ...data, title: value })}
|
|
/>
|
|
<TextAreaCustom
|
|
label="Deskripsi Berita"
|
|
placeholder="Masukan deskripsi berita"
|
|
required
|
|
showCount
|
|
maxLength={1000}
|
|
value={data?.deskripsi}
|
|
onChangeText={(value) => setData({ ...data, deskripsi: value })}
|
|
/>
|
|
|
|
<Spacing />
|
|
</StackCustom>
|
|
<Spacing />
|
|
</ViewWrapper>
|
|
);
|
|
}
|