From 1bcd1a044f9d18b0101d39d441458b658dc7adf8 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Fri, 24 Oct 2025 16:22:45 +0800 Subject: [PATCH] Integrasi API: Event Type Add: - utils/colorActivationForBadge.ts Fix: - app/(application)/admin/event/type-create.tsx - app/(application)/admin/event/type-of-event.tsx - app/(application)/admin/event/type-update.tsx - service/api-admin/api-admin-event.ts - service/api-admin/api-master-admin.ts - service/api-client/api-event.ts ### No Issue --- app/(application)/admin/event/type-create.tsx | 43 +++++- .../admin/event/type-of-event.tsx | 145 ++++++++++-------- app/(application)/admin/event/type-update.tsx | 93 ++++++++++- service/api-admin/api-admin-event.ts | 2 + service/api-admin/api-master-admin.ts | 87 +++++++++-- service/api-client/api-event.ts | 2 + utils/colorActivationForBadge.ts | 9 ++ 7 files changed, 304 insertions(+), 77 deletions(-) create mode 100644 utils/colorActivationForBadge.ts diff --git a/app/(application)/admin/event/type-create.tsx b/app/(application)/admin/event/type-create.tsx index ca69b0f..d5ba5f1 100644 --- a/app/(application)/admin/event/type-create.tsx +++ b/app/(application)/admin/event/type-create.tsx @@ -5,13 +5,48 @@ import { ViewWrapper, } from "@/components"; import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle"; +import { apiEventCreateTypeOfEvent } from "@/service/api-admin/api-master-admin"; import { useRouter } from "expo-router"; +import { useState } from "react"; +import Toast from "react-native-toast-message"; export default function AdminEventTypeOfEventCreate() { const router = useRouter(); + const [value, setValue] = useState(""); + const [isLoading, setLoading] = useState(false); + + const handlerSubmit = async () => { + try { + setLoading(true); + const response = await apiEventCreateTypeOfEvent({ + data: value, + }); + + + if (!response.success) { + Toast.show({ + type: "error", + text1: "Gagal menambahkan tipe acara", + }); + return; + } + Toast.show({ + type: "success", + text1: "Berhasil menambahkan tipe acara", + }); + router.back(); + } catch (error) { + console.log("[ERROR CREATE TYPE EVENT]", error); + } finally { + setLoading(false); + } + }; + const buttonSubmit = ( - router.back()}>Simpan + handlerSubmit()}> + Simpan + ); return ( @@ -20,7 +55,11 @@ export default function AdminEventTypeOfEventCreate() { headerComponent={} footerComponent={buttonSubmit} > - + ); diff --git a/app/(application)/admin/event/type-of-event.tsx b/app/(application)/admin/event/type-of-event.tsx index 7df44ea..8a0c8c6 100644 --- a/app/(application)/admin/event/type-of-event.tsx +++ b/app/(application)/admin/event/type-of-event.tsx @@ -1,23 +1,53 @@ import { ActionIcon, - BaseBox, + BadgeCustom, CenterCustom, + LoaderCustom, Spacing, StackCustom, TextCustom, - ViewWrapper, + ViewWrapper } from "@/components"; import { IconEdit } from "@/components/_Icon"; import AdminActionIconPlus from "@/components/_ShareComponent/Admin/ActionIconPlus"; import AdminComp_BoxTitle from "@/components/_ShareComponent/Admin/BoxTitlePage"; import AdminTitlePage from "@/components/_ShareComponent/Admin/TitlePage"; -import { GridDetail_4_8 } from "@/components/_ShareComponent/GridDetail_4_8"; +import { GridViewCustomSpan } from "@/components/_ShareComponent/GridViewCustomSpan"; import { ICON_SIZE_BUTTON } from "@/constants/constans-value"; -import { router } from "expo-router"; +import { apiAdminMasterTypeOfEvent } from "@/service/api-admin/api-master-admin"; +import { colorActivationForBadge } from "@/utils/colorActivationForBadge"; +import { router, useFocusEffect } from "expo-router"; +import _ from "lodash"; +import { useCallback, useState } from "react"; import { View } from "react-native"; import { Divider } from "react-native-paper"; export default function AdminEventTypeOfEvent() { + const [listData, setListData] = useState(null); + const [loadData, setLoadData] = useState(false); + + useFocusEffect( + useCallback(() => { + onLoadData(); + }, []) + ); + + const onLoadData = async () => { + try { + setLoadData(true); + const response = await apiAdminMasterTypeOfEvent(); + + if (response.success) { + setListData(response.data); + } + } catch (error) { + console.log("[ERROR]",error); + setListData([]); + } finally { + setLoadData(false); + } + }; + return ( <> }> @@ -32,73 +62,68 @@ export default function AdminEventTypeOfEvent() { } /> - - + Aksi } - value={Tipe Acara} + component2={Status} + component3={Tipe Acara} /> - {listData.map((item, index) => ( - - - - } - onPress={() => { - router.push(`/admin/event/type-update?id=${index}`); - }} - /> - - } - value={{item.label}} - /> - - - ))} + {loadData ? ( + + ) : _.isEmpty(listData) ? ( + + Belum ada data + + ) : ( + listData?.map((item, index) => ( + + + + } + onPress={() => { + router.push(`/admin/event/type-update?id=${item.id}`); + }} + /> + + } + style2={{ alignItems: "center" }} + component2={ + + + {item?.active ? "Aktif" : "Tidak Aktif"} + + + } + component3={{item.name}} + /> + + )) + )} - + ); } - -const listData = [ - { - label: "Seminar", - value: "seminar", - }, - { - label: "Workshop", - value: "workshop", - }, - { - label: "Konferensi", - value: "konferensi", - }, - { - label: "Lomba", - value: "lomba", - }, - { - label: "Pameran", - value: "pameran", - }, - { - label: "Pesta", - value: "pesta", - }, - { - label: "Pertandingan", - value: "pertandingan", - }, -]; diff --git a/app/(application)/admin/event/type-update.tsx b/app/(application)/admin/event/type-update.tsx index 134b2bb..85d5a5c 100644 --- a/app/(application)/admin/event/type-update.tsx +++ b/app/(application)/admin/event/type-update.tsx @@ -1,20 +1,91 @@ +/* eslint-disable react-hooks/exhaustive-deps */ import { BoxButtonOnFooter, ButtonCustom, + Spacing, + TextCustom, TextInputCustom, ViewWrapper, } from "@/components"; import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle"; -import { useLocalSearchParams, useRouter } from "expo-router"; +import { MainColor } from "@/constants/color-palet"; +import { + apiAdminMasterTypeOfEventGetOne, + apiAdminMasterTypeOfEventUpdate, +} from "@/service/api-admin/api-master-admin"; + +import { useFocusEffect, useLocalSearchParams, useRouter } from "expo-router"; +import { useCallback, useState } from "react"; +import { Switch } from "react-native-paper"; +import Toast from "react-native-toast-message"; export default function AdminEventTypeOfEventUpdate() { const { id } = useLocalSearchParams(); - console.log("id >", id); - const router = useRouter(); + + const [data, setData] = useState<{ name: string; active: boolean }>({ + name: "", + active: false, + }); + const [isLoading, setLoading] = useState(false); + + useFocusEffect( + useCallback(() => { + onLoadData(); + }, [id]) + ); + + const onLoadData = async () => { + try { + const response = await apiAdminMasterTypeOfEventGetOne({ + id: id as string, + }); + + if (response.success) { + setData({ + name: response.data.name, + active: response.data.active, + }); + } + } catch (error) { + console.log("[ERROR UPDATE]", error); + } + }; + + const handlerSubmit = async () => { + try { + setLoading(true); + + const response = await apiAdminMasterTypeOfEventUpdate({ + id: id as string, + data: data, + }); + + if (!response.success) { + Toast.show({ + type: "error", + text1: "Gagal mengupdate tipe acara", + }); + return; + } + + Toast.show({ + type: "success", + text1: "Berhasil mengupdate tipe acara", + }); + router.back(); + } catch (error) { + console.log("[ERROR UPDATE]", error); + } finally { + setLoading(false); + } + }; + const buttonSubmit = ( - router.back()}>Update + handlerSubmit()}> + Update + ); return ( @@ -23,7 +94,19 @@ export default function AdminEventTypeOfEventUpdate() { headerComponent={} footerComponent={buttonSubmit} > - + setData({ ...data, name: text })} + /> + + Aktivasi + + setData({ ...data, active: value })} + /> ); diff --git a/service/api-admin/api-admin-event.ts b/service/api-admin/api-admin-event.ts index f25a268..5c73f81 100644 --- a/service/api-admin/api-admin-event.ts +++ b/service/api-admin/api-admin-event.ts @@ -58,3 +58,5 @@ export async function apiAdminEventListOfParticipants({ id }: { id: string }) { throw error; } } + + diff --git a/service/api-admin/api-master-admin.ts b/service/api-admin/api-master-admin.ts index bc06b97..5d3e312 100644 --- a/service/api-admin/api-master-admin.ts +++ b/service/api-admin/api-master-admin.ts @@ -62,7 +62,9 @@ export async function apiAdminMasterBusinessField() { export async function apiAdminMasterBusinessFieldById({ id }: { id: string }) { try { - const response = await apiConfig.get(`/mobile/admin/master/business-field/${id}`); + const response = await apiConfig.get( + `/mobile/admin/master/business-field/${id}` + ); return response.data; } catch (error) { throw error; @@ -77,26 +79,91 @@ export async function apiAdminMasterBusinessFieldUpdate({ data: any; }) { try { - const response = await apiConfig.put(`/mobile/admin/master/business-field/${id}`, { - data: data, - }); + const response = await apiConfig.put( + `/mobile/admin/master/business-field/${id}`, + { + data: data, + } + ); return response.data; } catch (error) { throw error; } } -export async function apiAdminMasterBusinessFieldCreate({ data }: { data: any }) { +export async function apiAdminMasterBusinessFieldCreate({ + data, +}: { + data: any; +}) { try { - const response = await apiConfig.post(`/mobile/admin/master/business-field`, { - data: data, - }); + const response = await apiConfig.post( + `/mobile/admin/master/business-field`, + { + data: data, + } + ); return response.data; } catch (error) { throw error; } } - - // ================== END BUSINNES FIELD ================== // + +// ================== START EVENT ================== // +export async function apiAdminMasterTypeOfEvent() { + try { + const response = await apiConfig.get(`/mobile/admin/master/type-of-event`); + return response.data; + } catch (error) { + throw error; + } +} + +export async function apiEventCreateTypeOfEvent({ data }: { data: string }) { + try { + const response = await apiConfig.post( + `/mobile/admin/master/type-of-event`, + { + data: data, + } + ); + return response.data; + } catch (error) { + throw error; + } +} + +export async function apiAdminMasterTypeOfEventGetOne({ id }: { id: string }) { + try { + const response = await apiConfig.get( + `/mobile/admin/master/type-of-event/${id}` + ); + return response.data; + } catch (error) { + throw error; + } +} + +export async function apiAdminMasterTypeOfEventUpdate({ + id, + data, +}: { + id: string; + data: any; +}) { + try { + const response = await apiConfig.put( + `/mobile/admin/master/type-of-event/${id}`, + { + data: data, + } + ); + return response.data; + } catch (error) { + throw error; + } +} + +// ================== END EVENT ================== // diff --git a/service/api-client/api-event.ts b/service/api-client/api-event.ts index 16ae3a8..ecd0b0d 100644 --- a/service/api-client/api-event.ts +++ b/service/api-client/api-event.ts @@ -177,3 +177,5 @@ export async function apiEventConfirmationAction({ throw error; } } + + diff --git a/utils/colorActivationForBadge.ts b/utils/colorActivationForBadge.ts new file mode 100644 index 0000000..86ebbea --- /dev/null +++ b/utils/colorActivationForBadge.ts @@ -0,0 +1,9 @@ +import { AccentColor } from "@/constants/color-palet"; + +export const colorActivationForBadge = ({ status }: { status: boolean }) => { + if (status) { + return AccentColor.blue; + } else { + return AccentColor.blackgray; + } +};