From f5e30087edf27bede51bccfd69b477f2d7fadb91 Mon Sep 17 00:00:00 2001 From: bagasbanuna Date: Thu, 4 Dec 2025 16:59:39 +0800 Subject: [PATCH 1/2] Fix QC Inno Fix: - app/(application)/admin/donation/category-create.tsx - app/(application)/admin/donation/category-update.tsx - app/(application)/admin/donation/category.tsx - components/_ShareComponent/Admin/TableValue.tsx - screens/Authentication/LoginView.tsx - service/api-admin/api-master-admin.ts ### No Issue --- .../admin/donation/category-create.tsx | 59 ++++++- .../admin/donation/category-update.tsx | 83 ++++++++- app/(application)/admin/donation/category.tsx | 163 ++++++++++-------- .../_ShareComponent/Admin/TableValue.tsx | 13 +- screens/Authentication/LoginView.tsx | 4 +- service/api-admin/api-master-admin.ts | 53 ++++++ 6 files changed, 290 insertions(+), 85 deletions(-) diff --git a/app/(application)/admin/donation/category-create.tsx b/app/(application)/admin/donation/category-create.tsx index 587ea69..73aba91 100644 --- a/app/(application)/admin/donation/category-create.tsx +++ b/app/(application)/admin/donation/category-create.tsx @@ -1,17 +1,56 @@ import { BoxButtonOnFooter, ButtonCustom, + StackCustom, + TextCustom, TextInputCustom, ViewWrapper, } from "@/components"; import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle"; +import { MainColor } from "@/constants/color-palet"; +import { apiAdminMasterDonationCategoryCreate } from "@/service/api-admin/api-master-admin"; import { useRouter } from "expo-router"; +import { useState } from "react"; +import { Switch } from "react-native-paper"; +import Toast from "react-native-toast-message"; export default function AdminDonationCategoryCreate() { const router = useRouter(); + const [loading, setLoading] = useState(false); + const [data, setData] = useState({ + name: "", + active: false, + }); + + const onSubmit = async () => { + try { + setLoading(true); + const response = await apiAdminMasterDonationCategoryCreate({ data }); + if (response.success) { + Toast.show({ + type: "success", + text2: "Data berhasil disimpan", + }); + router.back(); + return; + } + + Toast.show({ + type: "error", + text1: "Gagal menyimpan data", + }); + } catch (error) { + console.log("[Error]", error); + } finally { + setLoading(false); + } + }; + const buttonSubmit = ( - router.back()}>Simpan + + Simpan + ); return ( @@ -20,7 +59,23 @@ export default function AdminDonationCategoryCreate() { headerComponent={} footerComponent={buttonSubmit} > - + setData({ ...data, name: text })} + /> + + Status + setData({ ...data, active: value })} + /> + ); diff --git a/app/(application)/admin/donation/category-update.tsx b/app/(application)/admin/donation/category-update.tsx index 91c1241..640dd5a 100644 --- a/app/(application)/admin/donation/category-update.tsx +++ b/app/(application)/admin/donation/category-update.tsx @@ -1,21 +1,76 @@ import { + AlertDefaultSystem, BoxButtonOnFooter, ButtonCustom, + StackCustom, + TextCustom, TextInputCustom, ViewWrapper, } from "@/components"; import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle"; +import { MainColor } from "@/constants/color-palet"; +import { + apiAdminMasterDonationCategoryById, + apiAdminMasterDonationCategoryUpdate, +} from "@/service/api-admin/api-master-admin"; import { useLocalSearchParams, useRouter } from "expo-router"; -import { useState } from "react"; +import { useCallback, useEffect, useState } from "react"; +import { Switch } from "react-native-paper"; export default function AdminDonationCategoryUpdate() { + const router = useRouter(); const { id } = useLocalSearchParams(); const [value, setValue] = useState(id); - const router = useRouter(); + const [data, setData] = useState(null); + const [isLoading, setIsLoading] = useState(false); + + useEffect(() => { + const fetchData = async () => { + const response = await apiAdminMasterDonationCategoryById({ + id: id as any, + }); + console.log(JSON.stringify(response.data, null, 2)); + + setData(response.data); + }; + fetchData(); + }, [id]); + + const handlerSubmit = async () => { + try { + setIsLoading(true); + const response = await apiAdminMasterDonationCategoryUpdate({ + id: id as any, + data: data, + }); + console.log(JSON.stringify(response.data, null, 2)); + router.back(); + } catch (error) { + console.log(error); + } finally { + setIsLoading(false); + } + }; + const buttonSubmit = ( - router.back()}>Update + { + AlertDefaultSystem({ + title: "Update Data", + message: "Apakah anda yakin ingin mengupdate data ini?", + textLeft: "Batal", + textRight: "Ya", + onPressLeft: () => {}, + onPressRight: () => handlerSubmit(), + }); + }} + > + Update + ); return ( @@ -25,10 +80,28 @@ export default function AdminDonationCategoryUpdate() { footerComponent={buttonSubmit} > setData({ ...data, name: value })} /> + + Status + + setData({ ...data, active: value })} + /> + ); diff --git a/app/(application)/admin/donation/category.tsx b/app/(application)/admin/donation/category.tsx index 20f7cf4..b9237f9 100644 --- a/app/(application)/admin/donation/category.tsx +++ b/app/(application)/admin/donation/category.tsx @@ -1,11 +1,15 @@ import { - ActionIcon, - BaseBox, - CenterCustom, - Spacing, - StackCustom, - TextCustom, - ViewWrapper, + ActionIcon, + BadgeCustom, + BaseBox, + CenterCustom, + ClickableCustom, + DividerCustom, + Grid, + Spacing, + StackCustom, + TextCustom, + ViewWrapper, } from "@/components"; import { IconEdit } from "@/components/_Icon"; import AdminActionIconPlus from "@/components/_ShareComponent/Admin/ActionIconPlus"; @@ -14,14 +18,56 @@ import AdminTitlePage from "@/components/_ShareComponent/Admin/TitlePage"; import { GridView_3_3_6 } from "@/components/_ShareComponent/GridView_3_3_6"; import { MainColor } from "@/constants/color-palet"; import { ICON_SIZE_BUTTON } from "@/constants/constans-value"; -import { View } from "react-native"; +import { RefreshControl, View } from "react-native"; import { Divider, Switch } from "react-native-paper"; -import { router } from "expo-router"; +import { router, useFocusEffect } from "expo-router"; +import { useCallback, useEffect, useState } from "react"; +import { apiAdminMasterDonationCategory } from "@/service/api-admin/api-master-admin"; +import { GridDetail_4_8 } from "@/components/_ShareComponent/GridDetail_4_8"; +import GridTwoView from "@/components/_ShareComponent/GridTwoView"; export default function AdminDonationCategory() { + const [listData, setListData] = useState([]); + const [refreshing, setRefreshing] = useState(false); + const [loading, setLoading] = useState(false); + + useFocusEffect( + useCallback(() => { + fetchMaster(); + }, []) + ); + + const fetchMaster = async () => { + try { + setLoading(true); + const response = await apiAdminMasterDonationCategory(); + if (response.success) { + console.log(JSON.stringify(response.data, null, 2)); + setListData(response.data); + } else { + setListData([]); + } + } catch (error) { + console.log("[Error]", error); + } finally { + setLoading(false); + } + }; + + const onRefresh = async () => { + setRefreshing(true); + await fetchMaster(); + setRefreshing(false); + }; + return ( <> - }> + + } + headerComponent={} + > - - - Aksi - - } - component2={Status} - component3={Kategori} - /> + + + + Status + + + Kategori + + + {listData.map((item, index) => ( - - { + router.push(`/admin/donation/category-update?id=${item.id}`); + }} + key={index} + > + + - - } - onPress={() => { - router.push(`/admin/donation/category-update?id=${index}`); - }} - /> + + {item.active ? "Aktif" : "Tidak Aktif"} + - } - component2={ - { - console.log(item); - }} - color={MainColor.yellow} - - /> - } - component3={{item.label}} - /> - + + + {item.name} + + - + ))} - + ); } - -const listData = [ - { - label: "Kegiatan Sosial", - value: "kegiatan_sosial", - }, - { - label: "Pendidikan", - value: "pendidikan", - }, - { - label: "Kesehatan", - value: "kesehatan", - }, - { - label: "Kebudayaan", - value: "kebudayaan", - }, - { - label: "Bencana Alami", - value: "bencana_alami", - }, - { - label: "Lainnya", - value: "lainnya", - }, -]; diff --git a/components/_ShareComponent/Admin/TableValue.tsx b/components/_ShareComponent/Admin/TableValue.tsx index e16851b..d71c764 100644 --- a/components/_ShareComponent/Admin/TableValue.tsx +++ b/components/_ShareComponent/Admin/TableValue.tsx @@ -1,17 +1,23 @@ import Grid from "@/components/Grid/GridCustom"; import React from "react"; -import { View } from "react-native"; +import { StyleProp, View, ViewStyle } from "react-native"; import { Divider } from "react-native-paper"; export default function AdminTableValue({ value1, value2, value3, + style1, + style2, + style3, bottomLine = false, }: { value1: React.ReactNode; value2: React.ReactNode; value3: React.ReactNode; + style1?: ViewStyle; + style2?: ViewStyle; + style3?: ViewStyle; bottomLine?: boolean; }) { return ( @@ -25,6 +31,7 @@ export default function AdminTableValue({ justifyContent: "center", paddingLeft: 10, paddingRight: 10, + ...style1, }} > {value1} @@ -36,6 +43,7 @@ export default function AdminTableValue({ justifyContent: "center", paddingLeft: 10, paddingRight: 10, + ...style2, }} > {value2} @@ -44,9 +52,10 @@ export default function AdminTableValue({ span={6} style={{ justifyContent: "center", - alignItems: "center", + alignItems: "flex-start", paddingLeft: 10, paddingRight: 10, + ...style3, }} > {value3} diff --git a/screens/Authentication/LoginView.tsx b/screens/Authentication/LoginView.tsx index c80833d..3aa2fff 100644 --- a/screens/Authentication/LoginView.tsx +++ b/screens/Authentication/LoginView.tsx @@ -134,10 +134,10 @@ export default function LoginView() { if (token && token !== "" && isAdmin) { // Akan di aktifkan jika sudah losos review - // return ; + return ; // Sementara gunakan ini - return ; + // return ; } return ( diff --git a/service/api-admin/api-master-admin.ts b/service/api-admin/api-master-admin.ts index 5d3e312..4932dbf 100644 --- a/service/api-admin/api-master-admin.ts +++ b/service/api-admin/api-master-admin.ts @@ -167,3 +167,56 @@ export async function apiAdminMasterTypeOfEventUpdate({ } // ================== END EVENT ================== // + +// ================== START DONATION ================== // + +export async function apiAdminMasterDonationCategory() { + try { + const response = await apiConfig.get(`/mobile/admin/master/donation`); + return response.data; + } catch (error) { + throw error; + } +} + +export async function apiAdminMasterDonationCategoryById({ id }: { id: string }) { + try { + const response = await apiConfig.get(`/mobile/admin/master/donation/${id}`); + return response.data; + } catch (error) { + throw error; + } +} + +export async function apiAdminMasterDonationCategoryUpdate({ + id, + data, +}: { + id: string; + data: any; +}) { + try { + const response = await apiConfig.put( + `/mobile/admin/master/donation/${id}`, + { + data: data, + } + ); + return response.data; + } catch (error) { + throw error; + } +} + +export async function apiAdminMasterDonationCategoryCreate({ data }: { data: any }) { + try { + const response = await apiConfig.post(`/mobile/admin/master/donation`, { + data: data, + }); + return response.data; + } catch (error) { + throw error; + } +} + +// ================== END DONATION ================== // \ No newline at end of file From ab5733f336eb4a8d7cf0f4eaea2e8cf1c6e40c39 Mon Sep 17 00:00:00 2001 From: bagasbanuna Date: Thu, 4 Dec 2025 17:41:19 +0800 Subject: [PATCH 2/2] Fix redirect admin --- screens/Authentication/LoginView.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/screens/Authentication/LoginView.tsx b/screens/Authentication/LoginView.tsx index 3aa2fff..c80833d 100644 --- a/screens/Authentication/LoginView.tsx +++ b/screens/Authentication/LoginView.tsx @@ -134,10 +134,10 @@ export default function LoginView() { if (token && token !== "" && isAdmin) { // Akan di aktifkan jika sudah losos review - return ; + // return ; // Sementara gunakan ini - // return ; + return ; } return (