diff --git a/src/app/api/master/tipe-acara/route.ts b/src/app/api/master/tipe-acara/route.ts new file mode 100644 index 00000000..0aa184ee --- /dev/null +++ b/src/app/api/master/tipe-acara/route.ts @@ -0,0 +1,34 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export async function GET(request: Request) { + try { + const data = await prisma.eventMaster_TipeAcara.findMany({ + orderBy: { + id: "asc", + }, + where: { + active: true, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Berhasil mendapatkan data", + data: data, + }, + { status: 200 } + ); + } catch (error) { + console.error("Error Get Master Tipe Acara ", error); + return NextResponse.json( + { + success: false, + message: "API Error Get Data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/dev/(user)/event/create/page.tsx b/src/app/dev/(user)/event/create/page.tsx index 5363ccb1..32a3cec4 100644 --- a/src/app/dev/(user)/event/create/page.tsx +++ b/src/app/dev/(user)/event/create/page.tsx @@ -1,15 +1,5 @@ -import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Event_Create } from "@/app_modules/event"; -import { Event_getMasterTipeAcara } from "@/app_modules/event/fun/master/get_tipe_acara"; export default async function Page() { - const userLoginId = await funGetUserIdByToken(); - const listTipeAcara = await Event_getMasterTipeAcara(); - - return ( - - ); + return ; } diff --git a/src/app/dev/(user)/event/detail/detail_sponsor/[id]/layout.tsx b/src/app/dev/(user)/event/detail/detail_sponsor/[id]/layout.tsx index 5869b245..ca263a9d 100644 --- a/src/app/dev/(user)/event/detail/detail_sponsor/[id]/layout.tsx +++ b/src/app/dev/(user)/event/detail/detail_sponsor/[id]/layout.tsx @@ -3,10 +3,10 @@ import LayoutEvent_DetailSponsor from '@/app_modules/event/detail/detail_sponsor import React from 'react'; async function Layout({children} : {children: React.ReactNode}) { - const userLoginId = await funGetUserIdByToken() + // const userLoginId = await funGetUserIdByToken() return ( <> - + {children} diff --git a/src/app/dev/(user)/event/detail/detail_sponsor/[id]/page.tsx b/src/app/dev/(user)/event/detail/detail_sponsor/[id]/page.tsx index c0e9cdde..dff347af 100644 --- a/src/app/dev/(user)/event/detail/detail_sponsor/[id]/page.tsx +++ b/src/app/dev/(user)/event/detail/detail_sponsor/[id]/page.tsx @@ -3,10 +3,10 @@ import DetailSponsor_Event from '@/app_modules/event/detail/detail_sponsor'; import React from 'react'; async function Page() { - const userLoginId = await funGetUserIdByToken(); + // const userLoginId = await funGetUserIdByToken(); return ( <> - + ); } diff --git a/src/app/dev/(user)/event/detail/main/[id]/page.tsx b/src/app/dev/(user)/event/detail/main/[id]/page.tsx index 34a13089..9b47f808 100644 --- a/src/app/dev/(user)/event/detail/main/[id]/page.tsx +++ b/src/app/dev/(user)/event/detail/main/[id]/page.tsx @@ -1,14 +1,9 @@ -import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Event_DetailMain } from "@/app_modules/event"; export default async function Page() { - const userLoginId = await funGetUserIdByToken(); - return ( <> - + ); } diff --git a/src/app/dev/(user)/event/edit/[id]/layout.tsx b/src/app/dev/(user)/event/edit/[id]/layout.tsx index 2288974b..8fa6a1e9 100644 --- a/src/app/dev/(user)/event/edit/[id]/layout.tsx +++ b/src/app/dev/(user)/event/edit/[id]/layout.tsx @@ -1,8 +1,14 @@ import { LayoutEvent_Edit } from "@/app_modules/event"; import React from "react"; -export default async function Layout({children}: {children: React.ReactNode}) { - return <> - {children} +export default async function Layout({ + children, +}: { + children: React.ReactNode; +}) { + return ( + <> + {children} -} \ No newline at end of file + ); +} diff --git a/src/app/dev/(user)/event/edit/[id]/page.tsx b/src/app/dev/(user)/event/edit/[id]/page.tsx index e1991957..ead792b0 100644 --- a/src/app/dev/(user)/event/edit/[id]/page.tsx +++ b/src/app/dev/(user)/event/edit/[id]/page.tsx @@ -1,25 +1,9 @@ import { Event_Edit } from "@/app_modules/event"; -import { event_getOneById } from "@/app_modules/event/fun/get/get_one_by_id"; -import { Event_getMasterTipeAcara } from "@/app_modules/event/fun/master/get_tipe_acara"; -import _ from "lodash"; - -export default async function Page({ params }: { params: { id: string } }) { - let eventId = params.id; - const data = await event_getOneById(eventId); - const dataEvent = _.omit(data, [ - "Author", - "EventMaster_Status", - "Event_Peserta", - "createdAt", - "updatedAt", - "active", - ]); - - const listTipeAcara = await Event_getMasterTipeAcara() +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/(user)/event/invoice/[id]/page.tsx b/src/app/dev/(user)/event/invoice/[id]/page.tsx index 7574ae8b..1d712941 100644 --- a/src/app/dev/(user)/event/invoice/[id]/page.tsx +++ b/src/app/dev/(user)/event/invoice/[id]/page.tsx @@ -3,10 +3,10 @@ import Event_Invoice from '@/app_modules/event/detail/invoice'; import React from 'react'; async function Page() { - const userLoginId = await funGetUserIdByToken(); + // const userLoginId = await funGetUserIdByToken(); return ( <> - + ); } diff --git a/src/app/dev/(user)/event/konfirmasi/[id]/page.tsx b/src/app/dev/(user)/event/konfirmasi/[id]/page.tsx index d59a2bd5..76f439c6 100644 --- a/src/app/dev/(user)/event/konfirmasi/[id]/page.tsx +++ b/src/app/dev/(user)/event/konfirmasi/[id]/page.tsx @@ -1,13 +1,10 @@ -import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import UiEvent_V2_Konfirmasi from "@/app_modules/event/_ui/V2_konfirmasi"; export default async function Page() { - const userLoginId = await funGetUserIdByToken(); - return ( <> {/* */} - + ); } diff --git a/src/app/dev/(user)/event/main/status/[id]/page.tsx b/src/app/dev/(user)/event/main/status/[id]/page.tsx index 174d569d..1336dc64 100644 --- a/src/app/dev/(user)/event/main/status/[id]/page.tsx +++ b/src/app/dev/(user)/event/main/status/[id]/page.tsx @@ -1,18 +1,6 @@ import { Event_StatusPage } from "@/app_modules/event"; -import { - event_getAllByStatusId, - event_getMasterStatus, -} from "@/app_modules/event/fun"; async function Page({ params }: { params: { id: string } }) { - // let statusId = params.id; - // const listStatus = await event_getMasterStatus(); - - // const dataStatus = await event_getAllByStatusId({ - // page: 1, - // statusId: statusId, - // }); - return ( <> diff --git a/src/app_modules/event/_lib/api_event.ts b/src/app_modules/event/_lib/api_event.ts index ea697595..7fa0b20d 100644 --- a/src/app_modules/event/_lib/api_event.ts +++ b/src/app_modules/event/_lib/api_event.ts @@ -1,19 +1,41 @@ import { IEventSponsor } from "./interface"; export const apiGetEventDetailById = async ({ id }: { id: string }) => { - const { token } = await fetch("/api/get-cookie").then((res) => res.json()); - if (!token) return await token.json().catch(() => null); + 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; + } - const response = await fetch(`/api/event/${id}`, { - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - }); + const response = await fetch(`/api/event/${id}`, { + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }); - return await response.json().catch(() => null); + // Check if the response is OK + if (!response.ok) { + const errorData = await response.json().catch(() => null); + console.error( + "Failed to get event detail", + response.statusText, + errorData + ); + throw new Error(errorData?.message || "Failed to get event detail"); + } + + // Return the JSON response + const data = await response.json(); + return data; + } catch (error) { + console.error("Error get event detail", error); + throw error; // Re-throw the error to handle it in the calling function + } }; export const apiGetEventCekPeserta = async ({ @@ -129,7 +151,13 @@ export const apiGetOneSponsorEventById = async ({ id }: { id: string }) => { return await response.json().catch(() => null); }; -export const apiGetEventKonfirmasiById = async ({ id, userId }: { id: string; userId: string }) => { +export const apiGetEventKonfirmasiById = async ({ + id, + userId, +}: { + id: string; + userId: string; +}) => { try { // Fetch token from cookie const { token } = await fetch("/api/get-cookie").then((res) => res.json()); @@ -138,7 +166,46 @@ export const apiGetEventKonfirmasiById = async ({ id, userId }: { id: string; us return null; } - const response = await fetch(`/api/event/${id}/konfirmasi?userId=${userId}`, { + const response = await fetch( + `/api/event/${id}/konfirmasi?userId=${userId}`, + { + 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( + "Failed to get event konfirmasi", + response.statusText, + errorData + ); + throw new Error(errorData?.message || "Failed to get event konfirmasi"); + } + + // Return the JSON response + return await response.json(); + } catch (error) { + console.error("Error get event konfirmasi", error); + throw error; // Re-throw the error to handle it in the calling function + } +}; + +export const apiGetMasterTipeAcara = async () => { + 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; + } + + const response = await fetch(`/api/master/tipe-acara`, { headers: { "Content-Type": "application/json", Accept: "application/json", @@ -149,14 +216,18 @@ export const apiGetEventKonfirmasiById = async ({ id, userId }: { id: string; us // Check if the response is OK if (!response.ok) { const errorData = await response.json().catch(() => null); - console.error("Failed to get event konfirmasi", response.statusText, errorData); - throw new Error(errorData?.message || "Failed to get event konfirmasi"); + console.error( + "Failed to get master tipe acara", + response.statusText, + errorData + ); + throw new Error(errorData?.message || "Failed to get master tipe acara"); } // Return the JSON response return await response.json(); } catch (error) { - console.error("Error get event konfirmasi", error); + console.error("Error get master tipe acara", error); throw error; // Re-throw the error to handle it in the calling function } -}; \ No newline at end of file +}; diff --git a/src/app_modules/event/_ui/V2_konfirmasi.tsx b/src/app_modules/event/_ui/V2_konfirmasi.tsx index 01d429da..8657213c 100644 --- a/src/app_modules/event/_ui/V2_konfirmasi.tsx +++ b/src/app_modules/event/_ui/V2_konfirmasi.tsx @@ -29,6 +29,7 @@ import { Event_funJoinAndConfirmEvent } from "../fun/create/fun_join_and_confirm import { Event_funJoinEvent } from "../fun/create/fun_join_event"; import { gs_event_hotMenu } from "../global_state"; import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; +import { apiNewGetUserIdByToken } from "@/app_modules/_global/lib/api_fetch_global"; interface IKonfirmasiProps { dataEvent: { @@ -50,11 +51,7 @@ interface IKonfirmasiProps { kehadiran: boolean | null; } -export default function UiEvent_V2_Konfirmasi({ - userLoginId, -}: { - userLoginId: string; -}) { +export default function UiEvent_V2_Konfirmasi() { const params = useParams<{ id: string }>(); const eventId = params.id; @@ -63,6 +60,7 @@ export default function UiEvent_V2_Konfirmasi({ const router = useRouter(); const [isLoading, setLoading] = useState(false); const [hotMenu, setHotMenu] = useAtom(gs_event_hotMenu); + const [userLoginId, setUserLoginId] = useState(null); // Load Data useShallowEffect(() => { @@ -71,15 +69,19 @@ export default function UiEvent_V2_Konfirmasi({ async function onLoadData() { try { - const response = await apiGetEventKonfirmasiById({ - id: eventId, - userId: userLoginId, - }); + const responseUser = await apiNewGetUserIdByToken(); + if (responseUser.success) { + setUserLoginId(responseUser.userId); + const response = await apiGetEventKonfirmasiById({ + id: eventId, + userId: responseUser.userId, + }); - if (response.res) { - setData(response.res); - } else { - setData(null); + if (response.res) { + setData(response.res); + } else { + setData(null); + } } } catch (error) { setData(null); @@ -87,8 +89,10 @@ export default function UiEvent_V2_Konfirmasi({ } } + + // Jika data kosong - if (data === undefined) { + if (data === undefined || !userLoginId) { return ; } diff --git a/src/app_modules/event/component/button/button_create_event.tsx b/src/app_modules/event/component/button/button_create_event.tsx index a4c81357..32a0c234 100644 --- a/src/app_modules/event/component/button/button_create_event.tsx +++ b/src/app_modules/event/component/button/button_create_event.tsx @@ -1,4 +1,6 @@ import { MainColor } from "@/app_modules/_global/color"; +import { funReplaceHtml } from "@/app_modules/_global/fun/fun_replace_html"; +import { maxInputLength } from "@/app_modules/_global/lib/maximal_setting"; import { ComponentGlobal_NotifikasiBerhasil, ComponentGlobal_NotifikasiGagal, @@ -6,6 +8,7 @@ import { import { notifikasiToAdmin_funCreate } from "@/app_modules/notifikasi/fun"; import { IRealtimeData } from "@/lib/global_state"; import { RouterEvent } from "@/lib/router_hipmi/router_event"; +import { clientLogger } from "@/util/clientLogger"; import { Button } from "@mantine/core"; import { useAtom } from "jotai"; import { useRouter } from "next/navigation"; @@ -13,9 +16,6 @@ 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 { clientLogger } from "@/util/clientLogger"; -import { funReplaceHtml } from "@/app_modules/_global/fun/fun_replace_html"; -import { maxInputLength } from "@/app_modules/_global/lib/maximal_setting"; export default function Event_ComponentCreateButton({ value, diff --git a/src/app_modules/event/create/create.tsx b/src/app_modules/event/create/create.tsx index 96035642..f2d868fd 100644 --- a/src/app_modules/event/create/create.tsx +++ b/src/app_modules/event/create/create.tsx @@ -1,40 +1,31 @@ "use client"; +import { MainColor } from "@/app_modules/_global/color"; import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown"; +import Component_V3_Label_TextInput from "@/app_modules/_global/component/new/comp_V3_label_text_input"; +import { Component_V3_TextEditor } from "@/app_modules/_global/component/new/comp_V3_text_editor"; +import { funReplaceHtml } from "@/app_modules/_global/fun/fun_replace_html"; +import { apiNewGetUserIdByToken } from "@/app_modules/_global/lib/api_fetch_global"; +import { baseStylesTextInput } from "@/app_modules/_global/lib/base_style_text_input"; +import { maxInputLength } from "@/app_modules/_global/lib/maximal_setting"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; import { MODEL_DEFAULT_MASTER_OLD } from "@/app_modules/model_global/interface"; -import { - Button, - Select, - Stack, - Text, - TextInput, - Textarea, -} from "@mantine/core"; +import { Select, Stack, TextInput } from "@mantine/core"; import { DateTimePicker } from "@mantine/dates"; +import { useShallowEffect } from "@mantine/hooks"; +import _ from "lodash"; import moment from "moment"; import { useState } from "react"; +import { apiGetMasterTipeAcara } from "../_lib/api_event"; import { Event_ComponentCreateButton } from "../component"; import ComponentEvent_ErrorMaximalInput from "../component/error_maksimal_input"; -import { MainColor } from "@/app_modules/_global/color"; -import { Component_V3_TextEditor } from "@/app_modules/_global/component/new/comp_V3_text_editor"; -import { maxInputLength } from "@/app_modules/_global/lib/maximal_setting"; -import { funReplaceHtml } from "@/app_modules/_global/fun/fun_replace_html"; -import Component_V3_Label_TextInput from "@/app_modules/_global/component/new/comp_V3_label_text_input"; - -export default function Event_Create({ - listTipeAcara, - authorId, -}: { - listTipeAcara: MODEL_DEFAULT_MASTER_OLD[]; - authorId: string; -}) { - const [listTipe, setListTipe] = useState(listTipeAcara); +export default function Event_Create() { + const [listTipe, setListTipe] = useState(); const [isTimeStart, setIsTimeStart] = useState(false); const [diffTimeStart, setDiffTimeStart] = useState(0); const [isTimeEnd, setIsTimeEnd] = useState(false); const [diffTimeEnd, setDiffTimeEnd] = useState(0); - const [value, setValue] = useState({ title: "", lokasi: "", @@ -42,24 +33,61 @@ export default function Event_Create({ tanggal: Date.toString(), tanggalSelesai: Date.toString(), eventMaster_TipeAcaraId: 0, - authorId: authorId, + authorId: "", }); + useShallowEffect(() => { + handleGetUserLoginId(); + }, []); + + async function handleGetUserLoginId() { + try { + const response = await apiNewGetUserIdByToken(); + if (response.success) { + setValue({ + ...value, + authorId: response.userId, + }); + } + } catch (error) { + setValue({ + ...value, + authorId: "", + }); + } + } + + useShallowEffect(() => { + handleGetMasterTipeAcara(); + }, []); + + async function handleGetMasterTipeAcara() { + try { + const response = await apiGetMasterTipeAcara(); + if (response.success) { + setListTipe(response.data); + } else { + setListTipe([]); + } + } catch (error) { + setListTipe([]); + } + } + + if (!listTipe || !value.authorId) { + return ; + } + return ( <> {/*
{JSON.stringify(value, null, 2)}
*/} - +