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/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