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
This commit is contained in:
2025-10-24 16:22:45 +08:00
parent 1e0b72de22
commit 1bcd1a044f
7 changed files with 304 additions and 77 deletions

View File

@@ -5,13 +5,48 @@ import {
ViewWrapper, ViewWrapper,
} from "@/components"; } from "@/components";
import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle"; import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle";
import { apiEventCreateTypeOfEvent } from "@/service/api-admin/api-master-admin";
import { useRouter } from "expo-router"; import { useRouter } from "expo-router";
import { useState } from "react";
import Toast from "react-native-toast-message";
export default function AdminEventTypeOfEventCreate() { export default function AdminEventTypeOfEventCreate() {
const router = useRouter(); const router = useRouter();
const [value, setValue] = useState("");
const [isLoading, setLoading] = useState<boolean>(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 = ( const buttonSubmit = (
<BoxButtonOnFooter> <BoxButtonOnFooter>
<ButtonCustom onPress={() => router.back()}>Simpan</ButtonCustom> <ButtonCustom isLoading={isLoading} onPress={() => handlerSubmit()}>
Simpan
</ButtonCustom>
</BoxButtonOnFooter> </BoxButtonOnFooter>
); );
return ( return (
@@ -20,7 +55,11 @@ export default function AdminEventTypeOfEventCreate() {
headerComponent={<AdminBackButtonAntTitle title="Tambah Tipe Acara" />} headerComponent={<AdminBackButtonAntTitle title="Tambah Tipe Acara" />}
footerComponent={buttonSubmit} footerComponent={buttonSubmit}
> >
<TextInputCustom placeholder="Masukkan Tipe Acara" /> <TextInputCustom
placeholder="Masukkan Tipe Acara"
value={value}
onChangeText={setValue}
/>
</ViewWrapper> </ViewWrapper>
</> </>
); );

View File

@@ -1,23 +1,53 @@
import { import {
ActionIcon, ActionIcon,
BaseBox, BadgeCustom,
CenterCustom, CenterCustom,
LoaderCustom,
Spacing, Spacing,
StackCustom, StackCustom,
TextCustom, TextCustom,
ViewWrapper, ViewWrapper
} from "@/components"; } from "@/components";
import { IconEdit } from "@/components/_Icon"; import { IconEdit } from "@/components/_Icon";
import AdminActionIconPlus from "@/components/_ShareComponent/Admin/ActionIconPlus"; import AdminActionIconPlus from "@/components/_ShareComponent/Admin/ActionIconPlus";
import AdminComp_BoxTitle from "@/components/_ShareComponent/Admin/BoxTitlePage"; import AdminComp_BoxTitle from "@/components/_ShareComponent/Admin/BoxTitlePage";
import AdminTitlePage from "@/components/_ShareComponent/Admin/TitlePage"; 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 { 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 { View } from "react-native";
import { Divider } from "react-native-paper"; import { Divider } from "react-native-paper";
export default function AdminEventTypeOfEvent() { export default function AdminEventTypeOfEvent() {
const [listData, setListData] = useState<any[] | null>(null);
const [loadData, setLoadData] = useState<boolean>(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 ( return (
<> <>
<ViewWrapper headerComponent={<AdminTitlePage title="Event" />}> <ViewWrapper headerComponent={<AdminTitlePage title="Event" />}>
@@ -32,73 +62,68 @@ export default function AdminEventTypeOfEvent() {
} }
/> />
<BaseBox> <>
<GridDetail_4_8 <GridViewCustomSpan
label={ span1={2}
span2={5}
span3={5}
component1={
<TextCustom bold align="center"> <TextCustom bold align="center">
Aksi Aksi
</TextCustom> </TextCustom>
} }
value={<TextCustom bold>Tipe Acara</TextCustom>} component2={<TextCustom bold align="center">Status</TextCustom>}
component3={<TextCustom bold>Tipe Acara</TextCustom>}
/> />
<Divider /> <Divider />
<Spacing /> <Spacing />
<StackCustom> <StackCustom>
{listData.map((item, index) => ( {loadData ? (
<LoaderCustom />
) : _.isEmpty(listData) ? (
<TextCustom align="center" color="gray">
Belum ada data
</TextCustom>
) : (
listData?.map((item, index) => (
<View key={index}> <View key={index}>
<GridDetail_4_8 <GridViewCustomSpan
label={ span1={2}
span2={5}
span3={5}
component1={
<CenterCustom> <CenterCustom>
<ActionIcon <ActionIcon
icon={ icon={
<IconEdit size={ICON_SIZE_BUTTON} color="black" /> <IconEdit size={ICON_SIZE_BUTTON} color="black" />
} }
onPress={() => { onPress={() => {
router.push(`/admin/event/type-update?id=${index}`); router.push(`/admin/event/type-update?id=${item.id}`);
}} }}
/> />
</CenterCustom> </CenterCustom>
} }
value={<TextCustom bold>{item.label}</TextCustom>} style2={{ alignItems: "center" }}
component2={
<CenterCustom>
<BadgeCustom
color={colorActivationForBadge({
status: item?.active,
})}
>
{item?.active ? "Aktif" : "Tidak Aktif"}
</BadgeCustom>
</CenterCustom>
}
component3={<TextCustom >{item.name}</TextCustom>}
/> />
<Divider />
</View> </View>
))} ))
)}
</StackCustom> </StackCustom>
</BaseBox> </>
</ViewWrapper> </ViewWrapper>
</> </>
); );
} }
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",
},
];

View File

@@ -1,20 +1,91 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { import {
BoxButtonOnFooter, BoxButtonOnFooter,
ButtonCustom, ButtonCustom,
Spacing,
TextCustom,
TextInputCustom, TextInputCustom,
ViewWrapper, ViewWrapper,
} from "@/components"; } from "@/components";
import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle"; 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() { export default function AdminEventTypeOfEventUpdate() {
const { id } = useLocalSearchParams(); const { id } = useLocalSearchParams();
console.log("id >", id);
const router = useRouter(); const router = useRouter();
const [data, setData] = useState<{ name: string; active: boolean }>({
name: "",
active: false,
});
const [isLoading, setLoading] = useState<boolean>(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 = ( const buttonSubmit = (
<BoxButtonOnFooter> <BoxButtonOnFooter>
<ButtonCustom onPress={() => router.back()}>Update</ButtonCustom> <ButtonCustom isLoading={isLoading} onPress={() => handlerSubmit()}>
Update
</ButtonCustom>
</BoxButtonOnFooter> </BoxButtonOnFooter>
); );
return ( return (
@@ -23,7 +94,19 @@ export default function AdminEventTypeOfEventUpdate() {
headerComponent={<AdminBackButtonAntTitle title="Ubah Tipe Acara" />} headerComponent={<AdminBackButtonAntTitle title="Ubah Tipe Acara" />}
footerComponent={buttonSubmit} footerComponent={buttonSubmit}
> >
<TextInputCustom placeholder="Masukkan Tipe Acara" value="" /> <TextInputCustom
placeholder="Masukkan Tipe Acara"
value={data.name}
onChangeText={(text) => setData({ ...data, name: text })}
/>
<TextCustom>Aktivasi</TextCustom>
<Spacing height={10} />
<Switch
color={MainColor.yellow}
value={data.active}
onValueChange={(value) => setData({ ...data, active: value })}
/>
</ViewWrapper> </ViewWrapper>
</> </>
); );

View File

@@ -58,3 +58,5 @@ export async function apiAdminEventListOfParticipants({ id }: { id: string }) {
throw error; throw error;
} }
} }

View File

@@ -62,7 +62,9 @@ export async function apiAdminMasterBusinessField() {
export async function apiAdminMasterBusinessFieldById({ id }: { id: string }) { export async function apiAdminMasterBusinessFieldById({ id }: { id: string }) {
try { 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; return response.data;
} catch (error) { } catch (error) {
throw error; throw error;
@@ -77,26 +79,91 @@ export async function apiAdminMasterBusinessFieldUpdate({
data: any; data: any;
}) { }) {
try { try {
const response = await apiConfig.put(`/mobile/admin/master/business-field/${id}`, { const response = await apiConfig.put(
`/mobile/admin/master/business-field/${id}`,
{
data: data, data: data,
}); }
);
return response.data; return response.data;
} catch (error) { } catch (error) {
throw error; throw error;
} }
} }
export async function apiAdminMasterBusinessFieldCreate({ data }: { data: any }) { export async function apiAdminMasterBusinessFieldCreate({
data,
}: {
data: any;
}) {
try { try {
const response = await apiConfig.post(`/mobile/admin/master/business-field`, { const response = await apiConfig.post(
`/mobile/admin/master/business-field`,
{
data: data, data: data,
}); }
);
return response.data; return response.data;
} catch (error) { } catch (error) {
throw error; throw error;
} }
} }
// ================== END BUSINNES FIELD ================== // // ================== 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 ================== //

View File

@@ -177,3 +177,5 @@ export async function apiEventConfirmationAction({
throw error; throw error;
} }
} }

View File

@@ -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;
}
};