fix ( event )
deskripsi: - create event sponsor - penambahan database eventSponsor & eventTransaksi - API create sponsor on progress
This commit is contained in:
@@ -47,6 +47,9 @@ model User {
|
||||
User_Notifikasi Notifikasi[] @relation("UserNotifikasi")
|
||||
BusinessMaps BusinessMaps[]
|
||||
Investasi_Invoice Investasi_Invoice[]
|
||||
|
||||
EventSponsor EventSponsor[]
|
||||
EventTransaksi EventTransaksi[]
|
||||
}
|
||||
|
||||
model MasterUserRole {
|
||||
@@ -166,6 +169,7 @@ model MasterBank {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
Investasi_Invoice Investasi_Invoice[]
|
||||
EventTransaksi EventTransaksi[]
|
||||
}
|
||||
|
||||
model MasterStatus {
|
||||
@@ -593,6 +597,8 @@ model Event {
|
||||
Event_Peserta Event_Peserta[]
|
||||
EventMaster_TipeAcara EventMaster_TipeAcara? @relation(fields: [eventMaster_TipeAcaraId], references: [id])
|
||||
eventMaster_TipeAcaraId Int?
|
||||
EventSponsor EventSponsor[]
|
||||
EventTransaksi EventTransaksi[]
|
||||
}
|
||||
|
||||
model EventMaster_TipeAcara {
|
||||
@@ -952,3 +958,45 @@ model MasterKategoriApp {
|
||||
name String
|
||||
value String?
|
||||
}
|
||||
|
||||
// ======================= EVENT ======================= //
|
||||
|
||||
model EventSponsor {
|
||||
id String @id @default(cuid())
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
name String
|
||||
fileName String
|
||||
fileExt String?
|
||||
fileId String
|
||||
|
||||
Author User? @relation(fields: [auhtorId], references: [id])
|
||||
auhtorId String?
|
||||
|
||||
Event Event? @relation(fields: [eventId], references: [id])
|
||||
eventId String?
|
||||
|
||||
EventTransaksi EventTransaksi?
|
||||
}
|
||||
|
||||
model EventTransaksi {
|
||||
id String @id @default(cuid())
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
nominal Int
|
||||
MasterBank MasterBank? @relation(fields: [masterBankId], references: [id])
|
||||
masterBankId String?
|
||||
status String
|
||||
transferImageId String?
|
||||
|
||||
AuthorId User? @relation(fields: [authorId], references: [id])
|
||||
authorId String?
|
||||
|
||||
Event Event? @relation(fields: [eventId], references: [id])
|
||||
eventId String?
|
||||
|
||||
EventSponsor EventSponsor? @relation(fields: [eventSponsorId], references: [id])
|
||||
eventSponsorId String? @unique
|
||||
}
|
||||
|
||||
@@ -48,3 +48,5 @@ export async function GET(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
52
src/app/api/event/sponsor/[id]/route.ts
Normal file
52
src/app/api/event/sponsor/[id]/route.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
context: { params: { id: string } }
|
||||
) {
|
||||
const method = request.method;
|
||||
if (method !== "POST") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
const { id } = context.params;
|
||||
|
||||
const body = await request.json();
|
||||
console.log("body", body);
|
||||
console.log("id", id);
|
||||
|
||||
// const res = await prisma.eventSponsor.create({
|
||||
|
||||
// })
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success create sponsor",
|
||||
});
|
||||
|
||||
// try {
|
||||
// const { id } = context.params;
|
||||
|
||||
// const body = await request.json();
|
||||
// console.log("body",body);
|
||||
// console.log("id",id);
|
||||
|
||||
// // const res = await prisma.eventSponsor.create({
|
||||
|
||||
// // })
|
||||
|
||||
// return NextResponse.json({
|
||||
// success: true,
|
||||
// message: "Success create sponsor",
|
||||
// });
|
||||
// } catch (error) {
|
||||
// return NextResponse.json(
|
||||
// { success: false, message: "Failed create sponsor" },
|
||||
// { status: 500 }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
@@ -21,6 +21,10 @@ const DIRECTORY_ID = {
|
||||
|
||||
// Job
|
||||
job_image: "cm0ypp6zl0003kp7jf59zuvjy",
|
||||
|
||||
// Event
|
||||
event_sponsor: "cm65zlbyf001udvmggnd6i0oh",
|
||||
event_bukti_transfer: "cm65zlehy001wdvmgnobur2zh",
|
||||
};
|
||||
|
||||
export default DIRECTORY_ID;
|
||||
|
||||
@@ -7,7 +7,7 @@ export const RouterEvent = {
|
||||
riwayat: ({ id }: { id: string }) => `/dev/event/main/riwayat/${id}`,
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param statusId | 1 - 4 | 1: Publish, 2: Review, 3: Draft, 4: Reject
|
||||
* @type string
|
||||
*/
|
||||
@@ -34,18 +34,13 @@ export const RouterEvent = {
|
||||
detail_riwayat: "/dev/event/detail/riwayat/",
|
||||
|
||||
//peserta
|
||||
daftar_peserta: ({ id }: { id: string }) =>
|
||||
`/dev/event/detail/peserta/${id}`,
|
||||
daftar_peserta: ({ id }: { id: string }) => `/dev/event/detail/peserta/${id}`,
|
||||
|
||||
//sponsor
|
||||
daftar_sponsor: ({ id }: { id: string }) =>
|
||||
`/dev/event/detail/sponsor/${id}`,
|
||||
daftar_sponsor: ({ id }: { id: string }) => `/dev/event/detail/sponsor/${id}`,
|
||||
edit_sponsor: "/dev/event/detail/sponsor/edit_sponsor/",
|
||||
tambah_sponsor: "/dev/event/detail/sponsor/tambah_sponsor/",
|
||||
tambah_sponsor: ({ id }: { id: string }) =>
|
||||
`/dev/event/detail/sponsor/tambah_sponsor/${id}`,
|
||||
detail_sponsor: ({ id }: { id: string }) =>
|
||||
`/dev/event/detail/detail_sponsor/${id}`,
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -60,3 +60,29 @@ export const apiGetEventPesertaById = async ({
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
// =============== SPONSOR =============== //
|
||||
|
||||
export const apiGetEventCreateSponsor = async ({
|
||||
id,
|
||||
data,
|
||||
}: {
|
||||
id: string;
|
||||
data: any;
|
||||
}) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/event/sponsor/${id}`, {
|
||||
method: "POST",
|
||||
body: data,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -1,27 +1,37 @@
|
||||
'use client';
|
||||
import { RouterEvent } from '@/app/lib/router_hipmi/router_event';
|
||||
import { UIGlobal_Drawer, UIGlobal_LayoutHeaderTamplate, UIGlobal_LayoutTamplate } from '@/app_modules/_global/ui';
|
||||
import { ActionIcon } from '@mantine/core';
|
||||
import { IconDotsVertical } from '@tabler/icons-react';
|
||||
import React, { useState } from 'react';
|
||||
"use client";
|
||||
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
|
||||
import {
|
||||
UIGlobal_Drawer,
|
||||
UIGlobal_LayoutHeaderTamplate,
|
||||
UIGlobal_LayoutTamplate,
|
||||
} from "@/app_modules/_global/ui";
|
||||
import { ActionIcon } from "@mantine/core";
|
||||
import { IconDotsVertical } from "@tabler/icons-react";
|
||||
import { useParams } from "next/navigation";
|
||||
import React, { useState } from "react";
|
||||
import { TfiCup } from "react-icons/tfi";
|
||||
|
||||
function LayoutEvent_Sponsor({ children}: { children: React.ReactNode;}) {
|
||||
function LayoutEvent_Sponsor({ children }: { children: React.ReactNode }) {
|
||||
const params = useParams<{ id: string }>();
|
||||
|
||||
const [openDrawer, setOpenDrawer] = useState(false);
|
||||
return (
|
||||
<>
|
||||
<UIGlobal_LayoutTamplate
|
||||
header={<UIGlobal_LayoutHeaderTamplate
|
||||
title="Daftar Sponsor"
|
||||
customButtonRight={
|
||||
<ActionIcon
|
||||
variant='transparent'
|
||||
onClick={() => setOpenDrawer(true)}
|
||||
>
|
||||
<IconDotsVertical color="white" />
|
||||
</ActionIcon>
|
||||
}
|
||||
/>}>
|
||||
header={
|
||||
<UIGlobal_LayoutHeaderTamplate
|
||||
title="Daftar Sponsor"
|
||||
customButtonRight={
|
||||
<ActionIcon
|
||||
variant="transparent"
|
||||
onClick={() => setOpenDrawer(true)}
|
||||
>
|
||||
<IconDotsVertical color="white" />
|
||||
</ActionIcon>
|
||||
}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</UIGlobal_LayoutTamplate>
|
||||
<UIGlobal_Drawer
|
||||
@@ -30,12 +40,11 @@ function LayoutEvent_Sponsor({ children}: { children: React.ReactNode;}) {
|
||||
component={[
|
||||
{
|
||||
id: 1,
|
||||
name: 'Tambah Sponsor',
|
||||
icon: <TfiCup/>,
|
||||
path: RouterEvent.tambah_sponsor,
|
||||
name: "Tambah Sponsor",
|
||||
icon: <TfiCup />,
|
||||
path: RouterEvent.tambah_sponsor({ id: params.id }),
|
||||
},
|
||||
]}
|
||||
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
'use client';
|
||||
|
||||
import { AccentColor, MainColor } from '@/app_modules/_global/color';
|
||||
import { MODEL_MASTER_BANK } from '@/app_modules/investasi/_lib/interface';
|
||||
import { Button, Paper, Radio, Stack, Title } from '@mantine/core';
|
||||
@@ -19,7 +20,7 @@ const bank = [
|
||||
namaBank: "BNI",
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
id: 4,
|
||||
namaBank: "BSI",
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,11 +1,201 @@
|
||||
import Event_CreateSponsor from '@/app_modules/event/component/detail/create_sponsor';
|
||||
import React from 'react';
|
||||
"use client";
|
||||
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import {
|
||||
ComponentGlobal_BoxInformation,
|
||||
ComponentGlobal_BoxUploadImage,
|
||||
ComponentGlobal_ButtonUploadFileImage,
|
||||
ComponentGlobal_CardStyles,
|
||||
} from "@/app_modules/_global/component";
|
||||
import Event_CreateSponsor from "@/app_modules/event/component/detail/create_sponsor";
|
||||
import {
|
||||
Stack,
|
||||
Box,
|
||||
AspectRatio,
|
||||
Group,
|
||||
Button,
|
||||
TextInput,
|
||||
Title,
|
||||
Loader,
|
||||
Image,
|
||||
Center,
|
||||
Text,
|
||||
} from "@mantine/core";
|
||||
import { IconPhoto, IconCamera, IconFileTypePdf } from "@tabler/icons-react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import React, { useState } from "react";
|
||||
import { apiGetEventCreateSponsor } from "../../_lib/api_event";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { funUploadFileToStorage } from "@/app_modules/_global/fun/upload/fun_upload_to_storage";
|
||||
import {
|
||||
ComponentGlobal_NotifikasiBerhasil,
|
||||
ComponentGlobal_NotifikasiPeringatan,
|
||||
} from "@/app_modules/_global/notif_global";
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
|
||||
function Event_TambahSponsor() {
|
||||
const params = useParams<{ id: string }>();
|
||||
const router = useRouter();
|
||||
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const [name, setName] = useState("");
|
||||
|
||||
async function onCreated() {
|
||||
if (!file) {
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setIsLoading(true);
|
||||
|
||||
const uploadFile = await funUploadFileToStorage({
|
||||
file: file,
|
||||
dirId: DIRECTORY_ID.event_sponsor,
|
||||
});
|
||||
|
||||
if (!uploadFile.success) {
|
||||
setIsLoading(false);
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal upload file");
|
||||
return;
|
||||
}
|
||||
|
||||
const data = {
|
||||
name: name,
|
||||
fileName: file.name,
|
||||
fileId: uploadFile.data.id,
|
||||
};
|
||||
|
||||
const created: any = await apiGetEventCreateSponsor({
|
||||
id: params.id,
|
||||
data: data,
|
||||
});
|
||||
|
||||
if (created) {
|
||||
setIsLoading(false);
|
||||
ComponentGlobal_NotifikasiBerhasil(created.message);
|
||||
}
|
||||
} catch (error) {
|
||||
setIsLoading(false);
|
||||
clientLogger.error("Error create sponsor", error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Event_CreateSponsor/>
|
||||
<Stack spacing={"md"} px={"xs"}>
|
||||
<Box mb={"sm"}>
|
||||
<ComponentGlobal_BoxInformation informasi="Upload file berformat pdf atau file gambar untuk logo sponsor anda." />
|
||||
</Box>
|
||||
|
||||
<TextInput
|
||||
styles={{
|
||||
label: {
|
||||
color: MainColor.white,
|
||||
},
|
||||
required: {
|
||||
color: MainColor.red,
|
||||
},
|
||||
input: {
|
||||
backgroundColor: MainColor.white,
|
||||
},
|
||||
}}
|
||||
withAsterisk
|
||||
label="Nama Sponsor"
|
||||
placeholder="Masukan nama sponsor"
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
/>
|
||||
|
||||
{/* <ComponentGlobal_BoxUploadImage>
|
||||
{isLoadingImg ? (
|
||||
<Stack justify="center" align="center" h={"100%"}>
|
||||
<Loader size={150} color="yellow" />
|
||||
</Stack>
|
||||
) : img ? (
|
||||
<AspectRatio ratio={1 / 1} mah={265} mx={"auto"}>
|
||||
<Image
|
||||
style={{ maxHeight: 250, margin: "auto", padding: "5px" }}
|
||||
alt="Foto"
|
||||
height={250}
|
||||
src={URL.createObjectURL(img)}
|
||||
/>
|
||||
</AspectRatio>
|
||||
) : (
|
||||
<Stack justify="center" align="center" h={"100%"}>
|
||||
<IconPhoto size={150} color="gray" />
|
||||
</Stack>
|
||||
)}
|
||||
</ComponentGlobal_BoxUploadImage> */}
|
||||
|
||||
<Stack spacing={0}>
|
||||
<ComponentGlobal_CardStyles marginBottom={0}>
|
||||
<Center>
|
||||
{file ? (
|
||||
<Text>{file.name}</Text>
|
||||
) : (
|
||||
<Group>
|
||||
<IconFileTypePdf size={50} /> . <IconPhoto size={50} />
|
||||
</Group>
|
||||
)}
|
||||
</Center>
|
||||
</ComponentGlobal_CardStyles>
|
||||
|
||||
<Center>
|
||||
<ComponentGlobal_ButtonUploadFileImage
|
||||
onSetFile={setFile}
|
||||
accept="image/jpeg,image/png,application/pdf"
|
||||
/>
|
||||
</Center>
|
||||
</Stack>
|
||||
|
||||
Box
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
style={{
|
||||
transition: "all 0.3s ease",
|
||||
position: "absolute",
|
||||
bottom: 20,
|
||||
width: "90%",
|
||||
}}
|
||||
disabled={file == null || name == ""}
|
||||
loading={isLoading ? true : false}
|
||||
loaderPosition="center"
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
// onCreated();
|
||||
}}
|
||||
bg={MainColor.yellow}
|
||||
color="yellow"
|
||||
c={"black"}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
{/* <Stack mt={30}>
|
||||
<Button
|
||||
mt={90}
|
||||
mb={20}
|
||||
radius={"xl"}
|
||||
color="yellow"
|
||||
c={"black"}
|
||||
bg={MainColor.yellow}
|
||||
onClick={() =>
|
||||
router.replace("/dev/event/detail/sponsor/nominal_sponsor")
|
||||
}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Stack> */}
|
||||
</Stack>
|
||||
|
||||
{/* <Event_CreateSponsor /> */}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user