API Event
Add: - api-client/api-event : fetch get one, update data, update status, create event Fix: - UI : create , detail dan status: untuk menyambungkan ke API ### No Issue
This commit is contained in:
@@ -1,27 +1,57 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
import {
|
import {
|
||||||
BoxWithHeaderSection,
|
BoxWithHeaderSection,
|
||||||
Grid,
|
Grid,
|
||||||
ScrollableCustom,
|
LoaderCustom,
|
||||||
StackCustom,
|
ScrollableCustom,
|
||||||
TextCustom
|
StackCustom,
|
||||||
|
TextCustom,
|
||||||
} from "@/components";
|
} from "@/components";
|
||||||
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
|
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
|
||||||
|
import { useAuth } from "@/hooks/use-auth";
|
||||||
import { dummyMasterStatus } from "@/lib/dummy-data/_master/status";
|
import { dummyMasterStatus } from "@/lib/dummy-data/_master/status";
|
||||||
import { useState } from "react";
|
import { apiEventGetByStatus } from "@/service/api-client/api-event";
|
||||||
|
import { useFocusEffect } from "expo-router";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { useCallback, useState } from "react";
|
||||||
|
|
||||||
export default function EventStatus() {
|
export default function EventStatus() {
|
||||||
const id = "test-id-event";
|
const { user } = useAuth();
|
||||||
|
const id = user?.id || "";
|
||||||
const [activeCategory, setActiveCategory] = useState<string | null>(
|
const [activeCategory, setActiveCategory] = useState<string | null>(
|
||||||
"publish"
|
"publish"
|
||||||
);
|
);
|
||||||
|
const [listData, setListData] = useState([]);
|
||||||
|
const [loadingGetData, setLoadingGetData] = useState(false);
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
onLoadData();
|
||||||
|
}, [activeCategory, id])
|
||||||
|
);
|
||||||
|
|
||||||
|
async function onLoadData() {
|
||||||
|
try {
|
||||||
|
setLoadingGetData(true);
|
||||||
|
const response = await apiEventGetByStatus({
|
||||||
|
id: id!,
|
||||||
|
status: activeCategory!,
|
||||||
|
});
|
||||||
|
// console.log("Response", JSON.stringify(response.data, null, 2));
|
||||||
|
setListData(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
} finally {
|
||||||
|
setLoadingGetData(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handlePress = (item: any) => {
|
const handlePress = (item: any) => {
|
||||||
setActiveCategory(item.value);
|
setActiveCategory(item.value);
|
||||||
// tambahkan logika lain seperti filter dsb.
|
// tambahkan logika lain seperti filter dsb.
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollComponent = (
|
const tabsComponent = (
|
||||||
<ScrollableCustom
|
<ScrollableCustom
|
||||||
data={dummyMasterStatus.map((e, i) => ({
|
data={dummyMasterStatus.map((e, i) => ({
|
||||||
id: i,
|
id: i,
|
||||||
@@ -34,30 +64,36 @@ export default function EventStatus() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ViewWrapper headerComponent={scrollComponent}>
|
<ViewWrapper headerComponent={tabsComponent}>
|
||||||
<BoxWithHeaderSection href={`/event/${id}/${activeCategory}/detail-event`}>
|
{loadingGetData ? (
|
||||||
<StackCustom gap={"xs"}>
|
<LoaderCustom />
|
||||||
<Grid>
|
) : _.isEmpty(listData) ? (
|
||||||
<Grid.Col span={8}>
|
<TextCustom align="center">Tidak ada data {activeCategory}</TextCustom>
|
||||||
<TextCustom truncate bold>
|
) : (
|
||||||
Lorem ipsum,{" "}
|
listData.map((item: any, i) => (
|
||||||
<TextCustom color="green">{activeCategory}</TextCustom> dolor
|
<BoxWithHeaderSection
|
||||||
sit amet consectetur adipisicing elit.
|
key={i}
|
||||||
</TextCustom>
|
href={`/event/${item.id }/${activeCategory}/detail-event`}
|
||||||
</Grid.Col>
|
>
|
||||||
<Grid.Col span={4} style={{ alignItems: "flex-end" }}>
|
<StackCustom gap={"xs"}>
|
||||||
<TextCustom>{new Date().toLocaleDateString()}</TextCustom>
|
<Grid>
|
||||||
</Grid.Col>
|
<Grid.Col span={8}>
|
||||||
</Grid>
|
<TextCustom truncate bold>
|
||||||
|
{item?.title}
|
||||||
|
</TextCustom>
|
||||||
|
</Grid.Col>
|
||||||
|
<Grid.Col span={4} style={{ alignItems: "flex-end" }}>
|
||||||
|
<TextCustom>
|
||||||
|
{new Date(item?.tanggal).toLocaleDateString()}
|
||||||
|
</TextCustom>
|
||||||
|
</Grid.Col>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<TextCustom truncate={2}>
|
<TextCustom truncate={2}>{item?.deskripsi}</TextCustom>
|
||||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur
|
</StackCustom>
|
||||||
eveniet ab eum ducimus tempore a quia deserunt quisquam. Tempora,
|
</BoxWithHeaderSection>
|
||||||
atque. Aperiam minima asperiores dicta perferendis quis adipisci,
|
))
|
||||||
dolore optio porro!
|
)}
|
||||||
</TextCustom>
|
|
||||||
</StackCustom>
|
|
||||||
</BoxWithHeaderSection>
|
|
||||||
</ViewWrapper>
|
</ViewWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
import {
|
import {
|
||||||
BaseBox,
|
BaseBox,
|
||||||
DotButton,
|
DotButton,
|
||||||
@@ -11,17 +12,64 @@ import {
|
|||||||
} from "@/components";
|
} from "@/components";
|
||||||
import { IMenuDrawerItem } from "@/components/_Interface/types";
|
import { IMenuDrawerItem } from "@/components/_Interface/types";
|
||||||
import LeftButtonCustom from "@/components/Button/BackButton";
|
import LeftButtonCustom from "@/components/Button/BackButton";
|
||||||
import Event_AlertButtonStatusSection from "@/screens/Event/AlertButtonStatusSection";
|
|
||||||
import Event_ButtonStatusSection from "@/screens/Event/ButtonStatusSection";
|
import Event_ButtonStatusSection from "@/screens/Event/ButtonStatusSection";
|
||||||
import { menuDrawerDraftEvent } from "@/screens/Event/menuDrawerDraft";
|
import { menuDrawerDraftEvent } from "@/screens/Event/menuDrawerDraft";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { apiEventGetOne } from "@/service/api-client/api-event";
|
||||||
import { useState } from "react";
|
import { dateTimeView } from "@/utils/dateTimeView";
|
||||||
|
import {
|
||||||
|
router,
|
||||||
|
Stack,
|
||||||
|
useFocusEffect,
|
||||||
|
useLocalSearchParams,
|
||||||
|
} from "expo-router";
|
||||||
|
import { useCallback, useState } from "react";
|
||||||
|
|
||||||
export default function EventDetailStatus() {
|
export default function EventDetailStatus() {
|
||||||
const { id, status } = useLocalSearchParams();
|
const { id, status } = useLocalSearchParams();
|
||||||
const [openDrawer, setOpenDrawer] = useState(false);
|
const [openDrawer, setOpenDrawer] = useState(false);
|
||||||
const [openAlert, setOpenAlert] = useState(false);
|
// const [openAlert, setOpenAlert] = useState(false);
|
||||||
const [openDeleteAlert, setOpenDeleteAlert] = useState(false);
|
|
||||||
|
const [data, setData] = useState<any>();
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
onLoadData();
|
||||||
|
}, [id])
|
||||||
|
);
|
||||||
|
|
||||||
|
async function onLoadData() {
|
||||||
|
try {
|
||||||
|
const response = await apiEventGetOne({ id: id as string });
|
||||||
|
if (response.success) {
|
||||||
|
setData(response.data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const listData = [
|
||||||
|
{
|
||||||
|
title: "Lokasi",
|
||||||
|
value: data?.lokasi || "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Tipe Acara",
|
||||||
|
value: data?.EventMaster_TipeAcara?.name || "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Tanggal Mulai",
|
||||||
|
value: dateTimeView({ date: data?.tanggal }) || "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Tanggal Berakhir",
|
||||||
|
value: dateTimeView({ date: data?.tanggalSelesai }) || "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Deskripsi",
|
||||||
|
value: data?.deskripsi || "-",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const handlePress = (item: IMenuDrawerItem) => {
|
const handlePress = (item: IMenuDrawerItem) => {
|
||||||
console.log("PATH >> ", item.path);
|
console.log("PATH >> ", item.path);
|
||||||
@@ -45,7 +93,7 @@ export default function EventDetailStatus() {
|
|||||||
<BaseBox>
|
<BaseBox>
|
||||||
<StackCustom>
|
<StackCustom>
|
||||||
<TextCustom bold align="center" size="xlarge">
|
<TextCustom bold align="center" size="xlarge">
|
||||||
Judul event {status}
|
{data?.title || "-"}
|
||||||
</TextCustom>
|
</TextCustom>
|
||||||
{listData.map((item, index) => (
|
{listData.map((item, index) => (
|
||||||
<Grid key={index}>
|
<Grid key={index}>
|
||||||
@@ -60,9 +108,8 @@ export default function EventDetailStatus() {
|
|||||||
</StackCustom>
|
</StackCustom>
|
||||||
</BaseBox>
|
</BaseBox>
|
||||||
<Event_ButtonStatusSection
|
<Event_ButtonStatusSection
|
||||||
|
id={id as string}
|
||||||
status={status as string}
|
status={status as string}
|
||||||
onOpenAlert={setOpenAlert}
|
|
||||||
onOpenDeleteAlert={setOpenDeleteAlert}
|
|
||||||
/>
|
/>
|
||||||
<Spacing />
|
<Spacing />
|
||||||
</ViewWrapper>
|
</ViewWrapper>
|
||||||
@@ -70,7 +117,7 @@ export default function EventDetailStatus() {
|
|||||||
<DrawerCustom
|
<DrawerCustom
|
||||||
isVisible={openDrawer}
|
isVisible={openDrawer}
|
||||||
closeDrawer={() => setOpenDrawer(false)}
|
closeDrawer={() => setOpenDrawer(false)}
|
||||||
height={250}
|
height={"auto"}
|
||||||
>
|
>
|
||||||
<MenuDrawerDynamicGrid
|
<MenuDrawerDynamicGrid
|
||||||
data={menuDrawerDraftEvent({ id: id as string }) as any}
|
data={menuDrawerDraftEvent({ id: id as string }) as any}
|
||||||
@@ -78,40 +125,6 @@ export default function EventDetailStatus() {
|
|||||||
onPressItem={handlePress as any}
|
onPressItem={handlePress as any}
|
||||||
/>
|
/>
|
||||||
</DrawerCustom>
|
</DrawerCustom>
|
||||||
|
|
||||||
<Event_AlertButtonStatusSection
|
|
||||||
id={id as string}
|
|
||||||
status={status as string}
|
|
||||||
openAlert={openAlert}
|
|
||||||
setOpenAlert={setOpenAlert}
|
|
||||||
openDeleteAlert={openDeleteAlert}
|
|
||||||
setOpenDeleteAlert={setOpenDeleteAlert}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const listData = [
|
|
||||||
{
|
|
||||||
title: "Lokasi",
|
|
||||||
value:
|
|
||||||
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur eveniet ab eum ducimus tempore a quia deserunt quisquam. Tempora, atque. Aperiam minima asperiores dicta perferendis quis adipisci, dolore optio porro!",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Tipe Acara",
|
|
||||||
value: "Workshop",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Tanggal Mulai",
|
|
||||||
value: "Senin, 18 Juli 2025, 10:00 WIB",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Tanggal Berakhir",
|
|
||||||
value: "Selasa, 19 Juli 2025, 12:00 WIB",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Deskripsi",
|
|
||||||
value:
|
|
||||||
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur eveniet ab eum ducimus tempore a quia deserunt quisquam. Tempora, atque. Aperiam minima asperiores dicta perferendis quis adipisci, dolore optio porro!",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|||||||
@@ -1,106 +1,265 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
import {
|
import {
|
||||||
ButtonCustom,
|
ButtonCustom,
|
||||||
|
LoaderCustom,
|
||||||
SelectCustom,
|
SelectCustom,
|
||||||
|
Spacing,
|
||||||
StackCustom,
|
StackCustom,
|
||||||
TextAreaCustom,
|
TextAreaCustom,
|
||||||
|
TextCustom,
|
||||||
TextInputCustom,
|
TextInputCustom,
|
||||||
ViewWrapper,
|
ViewWrapper,
|
||||||
} from "@/components";
|
} from "@/components";
|
||||||
import DateTimePickerCustom from "@/components/DateInput/DateTimePickerCustom";
|
import DateTimePickerCustom from "@/components/DateInput/DateTimePickerCustom";
|
||||||
import { masterTypeEvent } from "@/lib/dummy-data/event/master-type-event";
|
import {
|
||||||
|
apiEventGetOne,
|
||||||
|
apiEventUpdateData,
|
||||||
|
} from "@/service/api-client/api-event";
|
||||||
|
import { apiMasterEventType } from "@/service/api-client/api-master";
|
||||||
import { DateTimePickerEvent } from "@react-native-community/datetimepicker";
|
import { DateTimePickerEvent } from "@react-native-community/datetimepicker";
|
||||||
import { router } from "expo-router";
|
import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
|
||||||
import React, { useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
import { Platform } from "react-native";
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
export default function EventEdit() {
|
export default function EventEdit() {
|
||||||
|
const { id } = useLocalSearchParams();
|
||||||
|
const [data, setData] = useState<any>();
|
||||||
|
// {
|
||||||
|
// title: "",
|
||||||
|
// lokasi: "",
|
||||||
|
// deskripsi: "",
|
||||||
|
// eventMaster_TipeAcaraId: "",
|
||||||
|
// tanggal: "",
|
||||||
|
// tanggalSelesai: "",
|
||||||
|
// authorId: "",
|
||||||
|
// }
|
||||||
|
const [listTypeEvent, setListTypeEvent] = useState([]);
|
||||||
const [selectedDate, setSelectedDate] = useState<
|
const [selectedDate, setSelectedDate] = useState<
|
||||||
Date | DateTimePickerEvent | null
|
Date | DateTimePickerEvent | null
|
||||||
>(null);
|
>();
|
||||||
|
|
||||||
const [selectedEndDate, setSelectedEndDate] = useState<
|
const [selectedEndDate, setSelectedEndDate] = useState<
|
||||||
Date | DateTimePickerEvent | null
|
Date | DateTimePickerEvent | null
|
||||||
>(null);
|
>();
|
||||||
|
|
||||||
const handlerSubmit = () => {
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [isLoadData, setIsLoadData] = useState(false);
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
onLoadData();
|
||||||
|
}, [id])
|
||||||
|
);
|
||||||
|
|
||||||
|
async function onLoadData() {
|
||||||
try {
|
try {
|
||||||
if (selectedDate) {
|
setIsLoadData(true);
|
||||||
console.log("Tanggal yang dipilih:", selectedDate);
|
const response = await apiEventGetOne({ id: id as string });
|
||||||
console.log(`ISO Format ${Platform.OS}:`, selectedDate.toString());
|
if (response.success) {
|
||||||
// Kirim ke API atau proses lanjutan
|
setData(response.data);
|
||||||
} else {
|
setSelectedDate(new Date(response.data.tanggal));
|
||||||
console.log("Tanggal belum dipilih");
|
setSelectedEndDate(new Date(response.data.tanggalSelesai));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedEndDate) {
|
|
||||||
console.log("Tanggal yang dipilih:", selectedEndDate);
|
|
||||||
console.log(`ISO Format ${Platform.OS}:`, selectedEndDate.toString());
|
|
||||||
// Kirim ke API atau proses lanjutan
|
|
||||||
} else {
|
|
||||||
console.log("Tanggal berakhir belum dipilih");
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Data berhasil terupdate");
|
|
||||||
router.back()
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log("[ERROR]", error);
|
||||||
|
} finally {
|
||||||
|
setIsLoadData(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onLoadMasterEventType();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onLoadMasterEventType = async () => {
|
||||||
|
try {
|
||||||
|
const response = await apiMasterEventType();
|
||||||
|
setListTypeEvent(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error onLoadMasterEventType", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const buttonSubmit = (
|
const validateDate = () => {
|
||||||
<ButtonCustom title="Update" onPress={handlerSubmit} />
|
if (
|
||||||
);
|
data?.title === "" ||
|
||||||
|
data?.lokasi === "" ||
|
||||||
|
data?.deskripsi === "" ||
|
||||||
|
data?.eventMaster_TipeAcaraId === ""
|
||||||
|
) {
|
||||||
|
Toast.show({
|
||||||
|
type: "info",
|
||||||
|
text1: "Info",
|
||||||
|
text2: "Lengkapi semua data",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startDate = new Date(selectedDate as any);
|
||||||
|
const endDate = new Date(selectedEndDate as any);
|
||||||
|
|
||||||
|
if (startDate >= endDate) {
|
||||||
|
Toast.show({
|
||||||
|
type: "info",
|
||||||
|
text1: "Info",
|
||||||
|
text2: "Ubah tanggal berakhirnya event",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlerSubmit = async () => {
|
||||||
|
validateDate();
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const newData = {
|
||||||
|
...data,
|
||||||
|
tanggal: new Date(selectedDate as any).toISOString(),
|
||||||
|
tanggalSelesai: new Date(selectedEndDate as any).toISOString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await apiEventUpdateData({
|
||||||
|
id: id as string,
|
||||||
|
data: newData,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
|
Toast.show({
|
||||||
|
type: "success",
|
||||||
|
text1: response.message,
|
||||||
|
});
|
||||||
|
return router.back();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const validateDateRange = (
|
||||||
|
selectedDate: string | Date,
|
||||||
|
selectedEndDate: string | Date
|
||||||
|
): { isValid: boolean; error?: string } => {
|
||||||
|
const startDate = new Date(selectedDate);
|
||||||
|
const endDate = new Date(selectedEndDate);
|
||||||
|
|
||||||
|
// Cek apakah tanggal valid
|
||||||
|
if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
|
||||||
|
return {
|
||||||
|
isValid: false,
|
||||||
|
error: "Invalid date provided",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startDate >= endDate) {
|
||||||
|
return {
|
||||||
|
isValid: false,
|
||||||
|
error: "Ubah tanggal berakhirnya event",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
isValid: true,
|
||||||
|
error: undefined,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ViewWrapper>
|
<ViewWrapper>
|
||||||
<StackCustom gap={"xs"}>
|
{isLoadData ? (
|
||||||
<TextInputCustom
|
<LoaderCustom />
|
||||||
placeholder="Masukkan nama event"
|
) : (
|
||||||
label="Nama Event"
|
<StackCustom gap={"xs"}>
|
||||||
required
|
<TextInputCustom
|
||||||
/>
|
placeholder="Masukkan nama event"
|
||||||
<SelectCustom
|
label="Nama Event"
|
||||||
label="Tipe Event"
|
required
|
||||||
placeholder="Pilih tipe event"
|
value={data?.title}
|
||||||
data={masterTypeEvent}
|
onChangeText={(value) => setData({ ...data, title: value })}
|
||||||
onChange={(value) => console.log(value)}
|
/>
|
||||||
/>
|
<SelectCustom
|
||||||
<TextInputCustom
|
label="Tipe Event"
|
||||||
label="Lokasi"
|
placeholder="Pilih tipe event"
|
||||||
placeholder="Masukkan lokasi event"
|
data={listTypeEvent.map((item: any) => ({
|
||||||
required
|
label: item.name,
|
||||||
/>
|
value: item.id,
|
||||||
|
}))}
|
||||||
|
value={data?.eventMaster_TipeAcaraId || ""}
|
||||||
|
onChange={(value) => {
|
||||||
|
console.log(value);
|
||||||
|
setData({ ...data, eventMaster_TipeAcaraId: value });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInputCustom
|
||||||
|
label="Lokasi"
|
||||||
|
placeholder="Masukkan lokasi event"
|
||||||
|
required
|
||||||
|
value={data?.lokasi}
|
||||||
|
onChangeText={(value) => setData({ ...data, lokasi: value })}
|
||||||
|
/>
|
||||||
|
<DateTimePickerCustom
|
||||||
|
minimumDate={new Date(Date.now())}
|
||||||
|
label="Tanggal & Waktu Mulai"
|
||||||
|
required
|
||||||
|
value={selectedDate as any}
|
||||||
|
onChange={(date: any) => {
|
||||||
|
setSelectedDate(date as any);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<StackCustom gap={0}>
|
||||||
|
<DateTimePickerCustom
|
||||||
|
minimumDate={selectedDate as any}
|
||||||
|
label="Tanggal & Waktu Berakhir"
|
||||||
|
required
|
||||||
|
value={selectedEndDate as any}
|
||||||
|
onChange={(date: any) => {
|
||||||
|
setSelectedEndDate(date as any);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
<DateTimePickerCustom
|
{/* Muncul */}
|
||||||
label="Tanggal & Waktu Mulai"
|
{validateDateRange(selectedDate as any, selectedEndDate as any)
|
||||||
required
|
.isValid ? (
|
||||||
onChange={(date: Date) => {
|
<TextCustom style={{ color: "green" }}>
|
||||||
setSelectedDate(date as any);
|
{
|
||||||
}}
|
validateDateRange(
|
||||||
value={selectedDate as any}
|
selectedDate as any,
|
||||||
minimumDate={new Date(Date.now())}
|
selectedEndDate as any
|
||||||
/>
|
).error
|
||||||
|
}
|
||||||
|
</TextCustom>
|
||||||
|
) : (
|
||||||
|
<TextCustom style={{ color: "red" }}>
|
||||||
|
{
|
||||||
|
validateDateRange(
|
||||||
|
selectedDate as any,
|
||||||
|
selectedEndDate as any
|
||||||
|
).error
|
||||||
|
}
|
||||||
|
</TextCustom>
|
||||||
|
)}
|
||||||
|
<Spacing />
|
||||||
|
</StackCustom>
|
||||||
|
|
||||||
<DateTimePickerCustom
|
<TextAreaCustom
|
||||||
label="Tanggal & Waktu Berakhir"
|
label="Deskripsi"
|
||||||
required
|
placeholder="Masukkan deskripsi event"
|
||||||
onChange={(date: Date) => {
|
required
|
||||||
setSelectedEndDate(date as any);
|
showCount
|
||||||
}}
|
maxLength={100}
|
||||||
value={selectedEndDate as any}
|
value={data?.deskripsi}
|
||||||
/>
|
onChangeText={(value) => setData({ ...data, deskripsi: value })}
|
||||||
|
/>
|
||||||
|
|
||||||
<TextAreaCustom
|
<ButtonCustom
|
||||||
label="Deskripsi"
|
isLoading={isLoading}
|
||||||
placeholder="Masukkan deskripsi event"
|
title="Update"
|
||||||
required
|
onPress={handlerSubmit}
|
||||||
showCount
|
/>
|
||||||
maxLength={100}
|
</StackCustom>
|
||||||
/>
|
)}
|
||||||
|
|
||||||
{buttonSubmit}
|
|
||||||
</StackCustom>
|
|
||||||
</ViewWrapper>
|
</ViewWrapper>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
ButtonCustom,
|
ButtonCustom,
|
||||||
SelectCustom,
|
SelectCustom,
|
||||||
|
Spacing,
|
||||||
StackCustom,
|
StackCustom,
|
||||||
TextAreaCustom,
|
TextAreaCustom,
|
||||||
TextCustom,
|
TextCustom,
|
||||||
@@ -9,11 +10,12 @@ import {
|
|||||||
} from "@/components";
|
} from "@/components";
|
||||||
import DateTimePickerCustom from "@/components/DateInput/DateTimePickerCustom";
|
import DateTimePickerCustom from "@/components/DateInput/DateTimePickerCustom";
|
||||||
import { useAuth } from "@/hooks/use-auth";
|
import { useAuth } from "@/hooks/use-auth";
|
||||||
import { masterTypeEvent } from "@/lib/dummy-data/event/master-type-event";
|
import { apiEventCreate } from "@/service/api-client/api-event";
|
||||||
|
import { apiMasterEventType } from "@/service/api-client/api-master";
|
||||||
import { DateTimePickerEvent } from "@react-native-community/datetimepicker";
|
import { DateTimePickerEvent } from "@react-native-community/datetimepicker";
|
||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Platform } from "react-native";
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
interface EventCreateProps {
|
interface EventCreateProps {
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -27,8 +29,23 @@ interface EventCreateProps {
|
|||||||
|
|
||||||
export default function EventCreate() {
|
export default function EventCreate() {
|
||||||
const [data, setData] = useState<EventCreateProps>();
|
const [data, setData] = useState<EventCreateProps>();
|
||||||
|
const [listTypeEvent, setListTypeEvent] = useState([]);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onLoadMasterEventType();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onLoadMasterEventType = async () => {
|
||||||
|
try {
|
||||||
|
const response = await apiMasterEventType();
|
||||||
|
setListTypeEvent(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error onLoadMasterEventType", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const [selectedDate, setSelectedDate] = useState<
|
const [selectedDate, setSelectedDate] = useState<
|
||||||
Date | DateTimePickerEvent | null
|
Date | DateTimePickerEvent | null
|
||||||
>(null);
|
>(null);
|
||||||
@@ -37,35 +54,76 @@ export default function EventCreate() {
|
|||||||
Date | DateTimePickerEvent | null
|
Date | DateTimePickerEvent | null
|
||||||
>(null);
|
>(null);
|
||||||
|
|
||||||
const handlerSubmit = () => {
|
const handlerSubmit = async () => {
|
||||||
|
if (
|
||||||
|
!data?.title ||
|
||||||
|
!data?.lokasi ||
|
||||||
|
!data?.deskripsi ||
|
||||||
|
!data?.eventMaster_TipeAcaraId
|
||||||
|
) {
|
||||||
|
Toast.show({
|
||||||
|
type: "info",
|
||||||
|
text1: "Info",
|
||||||
|
text2: "Lengkapi semua data",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!selectedDate || !selectedEndDate) {
|
||||||
|
Toast.show({
|
||||||
|
type: "info",
|
||||||
|
text1: "Info",
|
||||||
|
text2: "Pilih tanggal mulai dan berakhir",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (selectedDate) {
|
||||||
|
// console.log("Tanggal yang dipilih:", selectedDate);
|
||||||
|
// console.log(`ISO Format ${Platform.OS}:`, selectedDate.toString());
|
||||||
|
|
||||||
|
// // Kirim ke API atau proses lanjutan
|
||||||
|
// } else {
|
||||||
|
// console.log("Tanggal belum dipilih");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (selectedEndDate) {
|
||||||
|
// console.log("Tanggal yang dipilih:", selectedEndDate);
|
||||||
|
// console.log(`ISO Format ${Platform.OS}:`, selectedEndDate.toString());
|
||||||
|
// // Kirim ke API atau proses lanjutan
|
||||||
|
// } else {
|
||||||
|
// console.log("Tanggal berakhir belum dipilih");
|
||||||
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// if (selectedDate) {
|
setIsLoading(true);
|
||||||
// console.log("Tanggal yang dipilih:", selectedDate);
|
|
||||||
// console.log(`ISO Format ${Platform.OS}:`, selectedDate.toString());
|
|
||||||
// // Kirim ke API atau proses lanjutan
|
|
||||||
// } else {
|
|
||||||
// console.log("Tanggal belum dipilih");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (selectedEndDate) {
|
const newData = {
|
||||||
// console.log("Tanggal yang dipilih:", selectedEndDate);
|
...data,
|
||||||
// console.log(`ISO Format ${Platform.OS}:`, selectedEndDate.toString());
|
tanggal: new Date(selectedDate as any).toISOString(),
|
||||||
// // Kirim ke API atau proses lanjutan
|
tanggalSelesai: new Date(selectedEndDate as any).toISOString(),
|
||||||
// } else {
|
authorId: user?.id,
|
||||||
// console.log("Tanggal berakhir belum dipilih");
|
};
|
||||||
// }
|
|
||||||
|
|
||||||
console.log("Data berhasil disimpan", JSON.stringify(data, null, 2));
|
console.log("Data berhasil disimpan", JSON.stringify(newData, null, 2));
|
||||||
// router.navigate("/event/status");
|
|
||||||
|
const response = await apiEventCreate(newData);
|
||||||
|
console.log("Response", JSON.stringify(response, null, 2));
|
||||||
|
|
||||||
|
router.navigate("/event/status");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const buttonSubmit = (
|
const buttonSubmit = (
|
||||||
<ButtonCustom title="Simpan" onPress={handlerSubmit} />
|
<ButtonCustom
|
||||||
// <BoxButtonOnFooter>
|
isLoading={isLoading}
|
||||||
// </BoxButtonOnFooter>
|
title="Simpan"
|
||||||
|
onPress={handlerSubmit}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -78,14 +136,20 @@ export default function EventCreate() {
|
|||||||
required
|
required
|
||||||
onChangeText={(value: any) => setData({ ...data, title: value })}
|
onChangeText={(value: any) => setData({ ...data, title: value })}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SelectCustom
|
<SelectCustom
|
||||||
label="Tipe Event"
|
label="Tipe Event"
|
||||||
placeholder="Pilih tipe event"
|
placeholder="Pilih tipe event"
|
||||||
data={masterTypeEvent}
|
data={listTypeEvent.map((item: any) => ({
|
||||||
|
label: item.name,
|
||||||
|
value: item.id,
|
||||||
|
}))}
|
||||||
|
value={data?.eventMaster_TipeAcaraId || ""}
|
||||||
onChange={(value: any) =>
|
onChange={(value: any) =>
|
||||||
setData({ ...data, eventMaster_TipeAcaraId: value })
|
setData({ ...data, eventMaster_TipeAcaraId: value })
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInputCustom
|
<TextInputCustom
|
||||||
label="Lokasi"
|
label="Lokasi"
|
||||||
placeholder="Masukkan lokasi event"
|
placeholder="Masukkan lokasi event"
|
||||||
@@ -103,14 +167,24 @@ export default function EventCreate() {
|
|||||||
minimumDate={new Date(Date.now())}
|
minimumDate={new Date(Date.now())}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<DateTimePickerCustom
|
<StackCustom gap={0}>
|
||||||
label="Tanggal & Waktu Berakhir"
|
<DateTimePickerCustom
|
||||||
required
|
disabled={!selectedDate}
|
||||||
onChange={(date: Date) => {
|
label="Tanggal & Waktu Berakhir"
|
||||||
setSelectedEndDate(date as any);
|
required
|
||||||
}}
|
onChange={(date: Date) => {
|
||||||
value={selectedEndDate as any}
|
setSelectedEndDate(date as any);
|
||||||
/>
|
}}
|
||||||
|
value={selectedEndDate as any}
|
||||||
|
minimumDate={new Date(selectedDate as any)}
|
||||||
|
/>
|
||||||
|
{!selectedDate && (
|
||||||
|
<TextCustom color="gray" size={"small"}>
|
||||||
|
Note: Pilih tanggal mulai terlebih dahulu
|
||||||
|
</TextCustom>
|
||||||
|
)}
|
||||||
|
<Spacing />
|
||||||
|
</StackCustom>
|
||||||
|
|
||||||
<TextAreaCustom
|
<TextAreaCustom
|
||||||
label="Deskripsi"
|
label="Deskripsi"
|
||||||
@@ -118,6 +192,9 @@ export default function EventCreate() {
|
|||||||
required
|
required
|
||||||
showCount
|
showCount
|
||||||
maxLength={100}
|
maxLength={100}
|
||||||
|
onChangeText={(value: any) =>
|
||||||
|
setData({ ...data, deskripsi: value })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{buttonSubmit}
|
{buttonSubmit}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
||||||
// DateTimeInput.tsx
|
// DateTimeInput.tsx
|
||||||
import { MainColor } from "@/constants/color-palet";
|
import { MainColor } from "@/constants/color-palet";
|
||||||
import { GStyles } from "@/styles/global-styles";
|
import { GStyles } from "@/styles/global-styles";
|
||||||
@@ -119,7 +119,7 @@ const DateTimeInput_Android: React.FC<DateTimeInputProps> = ({
|
|||||||
<Ionicons
|
<Ionicons
|
||||||
name="calendar-outline"
|
name="calendar-outline"
|
||||||
size={20}
|
size={20}
|
||||||
color={MainColor.placeholder}
|
color={disabled ? MainColor.white_gray : MainColor.placeholder}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
@@ -131,8 +131,8 @@ const DateTimeInput_Android: React.FC<DateTimeInputProps> = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Grid.Col span={6} style={{}}>
|
<Grid.Col span={6} style={{}}>
|
||||||
<Pressable onPress={toggleDatePicker}>
|
<Pressable onPress={() => !disabled && toggleDatePicker()}>
|
||||||
<TextCustom color="gray">
|
<TextCustom color={disabled ? "default" : "gray"}>
|
||||||
{selectedDate ? (
|
{selectedDate ? (
|
||||||
<TextCustom color="black">
|
<TextCustom color="black">
|
||||||
{selectedDate.toLocaleDateString()}
|
{selectedDate.toLocaleDateString()}
|
||||||
@@ -148,8 +148,8 @@ const DateTimeInput_Android: React.FC<DateTimeInputProps> = ({
|
|||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
|
|
||||||
<Grid.Col span={5} style={{}}>
|
<Grid.Col span={5} style={{}}>
|
||||||
<Pressable onPress={toggleTimePicker}>
|
<Pressable onPress={() => !disabled && toggleTimePicker()}>
|
||||||
<TextCustom color="gray">
|
<TextCustom color={disabled ? "default" : "gray"}>
|
||||||
{selectedTime ? (
|
{selectedTime ? (
|
||||||
<TextCustom color="black">
|
<TextCustom color="black">
|
||||||
{selectedTime.toLocaleTimeString("id-ID", {
|
{selectedTime.toLocaleTimeString("id-ID", {
|
||||||
|
|||||||
@@ -3,24 +3,19 @@ import { MainColor } from "@/constants/color-palet";
|
|||||||
import { GStyles } from "@/styles/global-styles";
|
import { GStyles } from "@/styles/global-styles";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
import DateTimePicker, {
|
import DateTimePicker, {
|
||||||
DateTimePickerEvent,
|
DateTimePickerEvent,
|
||||||
} from "@react-native-community/datetimepicker";
|
} from "@react-native-community/datetimepicker";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import {
|
import { StyleProp, Text, View, ViewStyle } from "react-native";
|
||||||
StyleProp,
|
|
||||||
Text,
|
|
||||||
View,
|
|
||||||
ViewStyle
|
|
||||||
} from "react-native";
|
|
||||||
import ClickableCustom from "../Clickable/ClickableCustom";
|
import ClickableCustom from "../Clickable/ClickableCustom";
|
||||||
import TextCustom from "../Text/TextCustom";
|
import TextCustom from "../Text/TextCustom";
|
||||||
|
|
||||||
interface DateTimeInputProps {
|
interface DateTimeInputProps {
|
||||||
// Main
|
// Main
|
||||||
value?: DateTimePickerEvent;
|
value?: DateTimePickerEvent | Date | null;
|
||||||
mode?: "date" | "time";
|
mode?: "date" | "time";
|
||||||
onChange: (selectedDate: DateTimePickerEvent) => void;
|
onChange: (selectedDate: DateTimePickerEvent | Date | null) => void;
|
||||||
maximumDate?: Date;
|
maximumDate?: Date;
|
||||||
minimumDate?: Date;
|
minimumDate?: Date;
|
||||||
// Main
|
// Main
|
||||||
@@ -74,7 +69,7 @@ const DateTimeInput_IOS: React.FC<DateTimeInputProps> = ({
|
|||||||
<ClickableCustom
|
<ClickableCustom
|
||||||
activeOpacity={0.8}
|
activeOpacity={0.8}
|
||||||
style={[GStyles.inputContainerArea, containerStyle]}
|
style={[GStyles.inputContainerArea, containerStyle]}
|
||||||
onPress={handlePress}
|
onPress={() => !disabled && handlePress()}
|
||||||
>
|
>
|
||||||
{label && (
|
{label && (
|
||||||
<Text style={GStyles.inputLabel}>
|
<Text style={GStyles.inputLabel}>
|
||||||
@@ -95,11 +90,11 @@ const DateTimeInput_IOS: React.FC<DateTimeInputProps> = ({
|
|||||||
<Ionicons
|
<Ionicons
|
||||||
name="calendar-outline"
|
name="calendar-outline"
|
||||||
size={20}
|
size={20}
|
||||||
color={MainColor.placeholder}
|
color={disabled ? MainColor.white : MainColor.placeholder}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<TextCustom color="gray">
|
<TextCustom color={disabled ? "default" : "gray"}>
|
||||||
{selectedDate ? (
|
{selectedDate ? (
|
||||||
<TextCustom color="black">
|
<TextCustom color="black">
|
||||||
{dayjs(selectedDate).format("DD-MM-YYYY HH:mm")}
|
{dayjs(selectedDate).format("DD-MM-YYYY HH:mm")}
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
|
import { DateTimePickerEvent } from "@react-native-community/datetimepicker";
|
||||||
import {
|
|
||||||
DateTimePickerEvent,
|
|
||||||
} from "@react-native-community/datetimepicker";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Platform } from "react-native";
|
import { Platform } from "react-native";
|
||||||
import DateTimeInput_Android from "./DataTimeAndroid";
|
import DateTimeInput_Android from "./DataTimeAndroid";
|
||||||
import DateTimeInput_IOS from "./DateTimeIOS";
|
import DateTimeInput_IOS from "./DateTimeIOS";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
value?: Date;
|
value?: Date | DateTimePickerEvent | null;
|
||||||
onChange?: (date: Date) => void;
|
onChange?: (date: Date) => void;
|
||||||
label?: string;
|
label?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
maximumDate?: Date;
|
maximumDate?: Date;
|
||||||
minimumDate?: Date;
|
minimumDate?: Date;
|
||||||
|
disabled?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DateTimePickerCustom: React.FC<Props> = ({
|
const DateTimePickerCustom: React.FC<Props> = ({
|
||||||
@@ -23,18 +21,21 @@ const DateTimePickerCustom: React.FC<Props> = ({
|
|||||||
required,
|
required,
|
||||||
maximumDate,
|
maximumDate,
|
||||||
minimumDate,
|
minimumDate,
|
||||||
|
disabled = false,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{Platform.OS === "ios" ? (
|
{Platform.OS === "ios" ? (
|
||||||
<DateTimeInput_IOS
|
<DateTimeInput_IOS
|
||||||
label={label}
|
label={label}
|
||||||
onChange={(date: DateTimePickerEvent) => {
|
onChange={(date: DateTimePickerEvent | Date | null) => {
|
||||||
onChange?.(date as any);
|
onChange?.(date as any);
|
||||||
}}
|
}}
|
||||||
required={required}
|
required={required}
|
||||||
maximumDate={maximumDate}
|
maximumDate={maximumDate}
|
||||||
minimumDate={minimumDate}
|
minimumDate={minimumDate}
|
||||||
|
disabled={disabled}
|
||||||
|
value={value as DateTimePickerEvent | Date | null}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<DateTimeInput_Android
|
<DateTimeInput_Android
|
||||||
@@ -45,6 +46,7 @@ const DateTimePickerCustom: React.FC<Props> = ({
|
|||||||
required={required}
|
required={required}
|
||||||
maximumDate={maximumDate}
|
maximumDate={maximumDate}
|
||||||
minimumDate={minimumDate}
|
minimumDate={minimumDate}
|
||||||
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ export default function LoginView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (token && !isAdmin) {
|
if (token && !isAdmin) {
|
||||||
return <Redirect href={"/(application)/(user)/home"} />;
|
return <Redirect href={"/(application)/(user)/event/(tabs)"} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token && isAdmin) {
|
if (token && isAdmin) {
|
||||||
|
|||||||
@@ -1,28 +1,138 @@
|
|||||||
import { ButtonCustom, Grid } from "@/components";
|
import { AlertDefaultSystem, ButtonCustom, Grid } from "@/components";
|
||||||
import { View } from "react-native";
|
import { apiEventUpdateStatus } from "@/service/api-client/api-event";
|
||||||
|
import { router } from "expo-router";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
export default function Event_ButtonStatusSection({
|
export default function Event_ButtonStatusSection({
|
||||||
|
id,
|
||||||
status,
|
status,
|
||||||
onOpenAlert,
|
|
||||||
onOpenDeleteAlert,
|
|
||||||
}: {
|
}: {
|
||||||
|
id: string;
|
||||||
status: string;
|
status: string;
|
||||||
onOpenAlert: (value: boolean) => void;
|
|
||||||
onOpenDeleteAlert: (value: boolean) => void;
|
|
||||||
}) {
|
}) {
|
||||||
|
const handleBatalkanReview = () => {
|
||||||
|
AlertDefaultSystem({
|
||||||
|
title: "Batalkan Review",
|
||||||
|
message: "Apakah Anda yakin ingin batalkan review ini?",
|
||||||
|
textLeft: "Batal",
|
||||||
|
textRight: "Ya",
|
||||||
|
onPressRight: async () => {
|
||||||
|
try {
|
||||||
|
const response = await apiEventUpdateStatus({
|
||||||
|
id: id,
|
||||||
|
status: "draft",
|
||||||
|
});
|
||||||
|
|
||||||
const handleOpenAlert = () => {
|
if (response.success) {
|
||||||
onOpenAlert(true);
|
Toast.show({
|
||||||
|
type: "success",
|
||||||
|
text1: response.message,
|
||||||
|
});
|
||||||
|
router.back();
|
||||||
|
} else {
|
||||||
|
Toast.show({
|
||||||
|
type: "info",
|
||||||
|
text1: "Info",
|
||||||
|
text2: response.message,
|
||||||
|
});
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAjukanReview = () => {
|
||||||
|
AlertDefaultSystem({
|
||||||
|
title: "Ajukan Review",
|
||||||
|
message: "Apakah Anda yakin ingin ajukan review ini?",
|
||||||
|
textLeft: "Batal",
|
||||||
|
textRight: "Ya",
|
||||||
|
onPressRight: async () => {
|
||||||
|
try {
|
||||||
|
const response = await apiEventUpdateStatus({
|
||||||
|
id: id,
|
||||||
|
status: "review",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
|
Toast.show({
|
||||||
|
type: "success",
|
||||||
|
text1: response.message,
|
||||||
|
});
|
||||||
|
router.back();
|
||||||
|
} else {
|
||||||
|
Toast.show({
|
||||||
|
type: "info",
|
||||||
|
text1: "Info",
|
||||||
|
text2: response.message,
|
||||||
|
});
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditKembali = () => {
|
||||||
|
AlertDefaultSystem({
|
||||||
|
title: "Edit Kembali",
|
||||||
|
message: "Apakah Anda yakin ingin edit kembali ini?",
|
||||||
|
textLeft: "Batal",
|
||||||
|
textRight: "Ya",
|
||||||
|
onPressRight: async () => {
|
||||||
|
try {
|
||||||
|
const response = await apiEventUpdateStatus({
|
||||||
|
id: id,
|
||||||
|
status: "draft",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
|
Toast.show({
|
||||||
|
type: "success",
|
||||||
|
text1: response.message,
|
||||||
|
});
|
||||||
|
router.back();
|
||||||
|
} else {
|
||||||
|
Toast.show({
|
||||||
|
type: "info",
|
||||||
|
text1: "Info",
|
||||||
|
text2: response.message,
|
||||||
|
});
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOpenDeleteAlert = () => {
|
const handleOpenDeleteAlert = () => {
|
||||||
onOpenDeleteAlert(true);
|
AlertDefaultSystem({
|
||||||
|
title: "Hapus",
|
||||||
|
message: "Apakah Anda yakin ingin menghapus data ini?",
|
||||||
|
textLeft: "Batal",
|
||||||
|
textRight: "Hapus",
|
||||||
|
onPressRight: () => {
|
||||||
|
console.log("Hapus");
|
||||||
|
router.back();
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const DeleteButton = () => {
|
const DeleteButton = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ButtonCustom backgroundColor="red" textColor="white" onPress={handleOpenDeleteAlert}>
|
<ButtonCustom
|
||||||
|
backgroundColor="red"
|
||||||
|
textColor="white"
|
||||||
|
onPress={handleOpenDeleteAlert}
|
||||||
|
>
|
||||||
Hapus
|
Hapus
|
||||||
</ButtonCustom>
|
</ButtonCustom>
|
||||||
</>
|
</>
|
||||||
@@ -35,7 +145,7 @@ export default function Event_ButtonStatusSection({
|
|||||||
|
|
||||||
case "review":
|
case "review":
|
||||||
return (
|
return (
|
||||||
<ButtonCustom onPress={handleOpenAlert}>
|
<ButtonCustom onPress={handleBatalkanReview}>
|
||||||
Batalkan Review
|
Batalkan Review
|
||||||
</ButtonCustom>
|
</ButtonCustom>
|
||||||
);
|
);
|
||||||
@@ -44,13 +154,14 @@ export default function Event_ButtonStatusSection({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={5}>
|
<Grid.Col span={6} style={{ paddingRight: 10 }}>
|
||||||
<ButtonCustom onPress={handleOpenAlert}>Ajukan Review</ButtonCustom>
|
<ButtonCustom onPress={handleAjukanReview}>
|
||||||
|
Ajukan Review
|
||||||
|
</ButtonCustom>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={2}>
|
<Grid.Col span={6} style={{ paddingLeft: 10 }}>
|
||||||
<View />
|
{DeleteButton()}
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={5}>{DeleteButton()}</Grid.Col>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -59,13 +170,14 @@ export default function Event_ButtonStatusSection({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={5}>
|
<Grid.Col span={6} style={{ paddingRight: 10 }}>
|
||||||
<ButtonCustom onPress={handleOpenAlert}>Edit Kembali</ButtonCustom>
|
<ButtonCustom onPress={handleEditKembali}>
|
||||||
|
Edit Kembali
|
||||||
|
</ButtonCustom>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={2}>
|
<Grid.Col span={6} style={{ paddingLeft: 10 }}>
|
||||||
<View />
|
{DeleteButton()}
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={5}>{DeleteButton()}</Grid.Col>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
64
service/api-client/api-event.ts
Normal file
64
service/api-client/api-event.ts
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import { apiConfig } from "../api-config";
|
||||||
|
|
||||||
|
export async function apiEventCreate(data: any) {
|
||||||
|
try {
|
||||||
|
const response = await apiConfig.post(`/mobile/event`, {
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function apiEventGetByStatus({
|
||||||
|
id,
|
||||||
|
status,
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
status: string;
|
||||||
|
}) {
|
||||||
|
try {
|
||||||
|
const response = await apiConfig.get(`/mobile/event/${id}/${status}`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function apiEventGetOne({ id }: { id: string }) {
|
||||||
|
try {
|
||||||
|
const response = await apiConfig.get(`/mobile/event/${id}`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function apiEventUpdateStatus({
|
||||||
|
id,
|
||||||
|
status,
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
status: "draft" | "review" | "publish" | "reject";
|
||||||
|
}) {
|
||||||
|
try {
|
||||||
|
const response = await apiConfig.put(`/mobile/event/${id}/${status}`);
|
||||||
|
console.log("[SUCCESS]", response.data);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
// console.log("[ERROR FECTH]", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function apiEventUpdateData({ id, data }: { id: string; data: any }) {
|
||||||
|
try {
|
||||||
|
const response = await apiConfig.put(`/mobile/event/${id}`, {
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,11 @@ export async function apiMasterSubBidangBisnis({ id }: { id?: string }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// export async function apiMasterEventType(params:type) {
|
export async function apiMasterEventType() {
|
||||||
|
try {
|
||||||
// }
|
const response = await apiConfig.get(`/mobile/master/event-type`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
utils/dateTimeView.ts
Normal file
12
utils/dateTimeView.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
export const dateTimeView = ({
|
||||||
|
date,
|
||||||
|
withoutTime = false,
|
||||||
|
}: {
|
||||||
|
date: any;
|
||||||
|
withoutTime?: boolean;
|
||||||
|
}) => {
|
||||||
|
const newDate = dayjs(date).format(`DD-MM-YYYY, ${withoutTime ? "" : "HH:mm"}`);
|
||||||
|
return newDate;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user