fix event

deskripsi:
- fix api status event
This commit is contained in:
2025-02-20 16:43:43 +08:00
parent 4e42dd7a94
commit ae1554a47f
10 changed files with 349 additions and 102 deletions

View File

@@ -39,7 +39,7 @@ export default function ComponentEvent_BoxListStatus({
<Text c={MainColor.white} align="right" fz={"sm"} lineClamp={1}>
{new Intl.DateTimeFormat("id-ID", {
dateStyle: "medium",
}).format(data.tanggal)}
}).format(new Date(data.tanggal))}
</Text>
</Group>

View File

@@ -0,0 +1,45 @@
export { apiGetEventByStatus };
const apiGetEventByStatus = async ({
status,
page,
}: {
status: string;
page: string;
}) => {
try {
// Fetch token from cookie
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) {
console.error("No token found");
return null;
}
// Send PUT request to update portfolio logo
const isPage = `?page=${page}`;
const response = await fetch(`/api/event/status/${status}${isPage}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
});
// Check if the response is OK
if (!response.ok) {
const errorData = await response.json().catch(() => null);
console.error(
"Error updating portfolio logo:",
errorData?.message || "Unknown error"
);
return null;
}
return await response.json();
} catch (error) {
console.error("Error updating portfolio medsos:", error);
throw error; // Re-throw the error to handle it in the calling function
}
};

View File

@@ -1,21 +1,19 @@
import { IRealtimeData } from "@/lib/global_state";
import { RouterEvent } from "@/lib/router_hipmi/router_event";
import { MainColor } from "@/app_modules/_global/color";
import {
ComponentGlobal_NotifikasiBerhasil,
ComponentGlobal_NotifikasiGagal,
ComponentGlobal_NotifikasiPeringatan,
} from "@/app_modules/_global/notif_global";
import { notifikasiToAdmin_funCreate } from "@/app_modules/notifikasi/fun";
import { IRealtimeData } from "@/lib/global_state";
import { RouterEvent } from "@/lib/router_hipmi/router_event";
import { Button } from "@mantine/core";
import { useAtom } from "jotai";
import moment from "moment";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { WibuRealtime } from "wibu-pkg";
import { Event_funCreate } from "../../fun/create/fun_create";
import { gs_event_hotMenu } from "../../global_state";
import { event_checkStatus } from "../../fun/get/fun_check_status_by_id";
import { clientLogger } from "@/util/clientLogger";
export default function Event_ComponentCreateButton({
value,
@@ -31,42 +29,47 @@ export default function Event_ComponentCreateButton({
const [isLoading, setLoading] = useState(false);
async function onSave() {
const res = await Event_funCreate(value);
try {
setLoading(true);
const res = await Event_funCreate(value);
if (res.status === 201) {
const dataNotifikasi: IRealtimeData = {
appId: res.data?.id as any,
status: res.data?.EventMaster_Status?.name as any,
userId: res.data?.authorId as any,
pesan: res.data?.title as any,
kategoriApp: "EVENT",
title: "Event baru",
};
if (res.status === 201) {
const dataNotifikasi: IRealtimeData = {
appId: res.data?.id as any,
status: res.data?.EventMaster_Status?.name as any,
userId: res.data?.authorId as any,
pesan: res.data?.title as any,
kategoriApp: "EVENT",
title: "Event baru",
};
const notif = await notifikasiToAdmin_funCreate({
data: dataNotifikasi as any,
});
if (notif.status === 201) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "ADMIN",
const notif = await notifikasiToAdmin_funCreate({
data: dataNotifikasi as any,
});
WibuRealtime.setData({
type: "trigger",
pushNotificationTo: "ADMIN",
dataMessage: dataNotifikasi,
});
if (notif.status === 201) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "ADMIN",
});
ComponentGlobal_NotifikasiBerhasil(res.message);
setHotMenu(1);
setLoading(true);
router.push(RouterEvent.status({ id: "2" }), { scroll: false });
WibuRealtime.setData({
type: "trigger",
pushNotificationTo: "ADMIN",
dataMessage: dataNotifikasi,
});
ComponentGlobal_NotifikasiBerhasil(res.message);
setHotMenu(1);
router.push(RouterEvent.status({ id: "2" }), { scroll: false });
}
} else {
setLoading(false);
ComponentGlobal_NotifikasiGagal(res.message);
}
} else {
ComponentGlobal_NotifikasiGagal(res.message);
} catch (error) {
setLoading(false);
clientLogger.error("Error create event", error);
}
}