test server

This commit is contained in:
2024-04-03 13:21:20 +08:00
parent a87f3be2ed
commit fe14211951
11 changed files with 214 additions and 13 deletions

View File

@@ -4,8 +4,23 @@ import { RouterColab } from "@/app/lib/router_hipmi/router_colab";
import { Button, Select, Stack, TextInput, Textarea } from "@mantine/core";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { MODEL_COLLABORATION_MASTER } from "../model/interface";
import colab_funCreateProyek from "../fun/create/fun_create_proyek";
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/component_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/component_global/notif_global/notifikasi_gagal";
export default function Colab_Create() {
export default function Colab_Create({
listIndustri,
}: {
listIndustri: MODEL_COLLABORATION_MASTER[];
}) {
const [value, setValue] = useState({
title: "",
lokasi: "",
purpose: "",
benefit: "",
projectCollaborationMaster_IndustriId: 0,
});
return (
<>
<Stack px={"sm"}>
@@ -13,22 +28,40 @@ export default function Colab_Create() {
label="Judul"
withAsterisk
placeholder="Masukan judul proyek"
onChange={(val) => {
setValue({
...value,
title: val.currentTarget.value,
});
}}
/>
<TextInput
label="Lokasi"
withAsterisk
placeholder="Masukan lokasi proyek"
onChange={(val) => {
setValue({
...value,
lokasi: val.currentTarget.value,
});
}}
/>
<Select
placeholder="Pilih kategori industri"
label="Pilih Industri"
withAsterisk
data={[
{ value: "1", label: "Teknologi" },
{ value: "2", label: "Tambang Batu Bara" },
]}
data={listIndustri.map((e) => ({
value: e.id,
label: e.name,
}))}
onChange={(val) => {
setValue({
...value,
projectCollaborationMaster_IndustriId: val as any,
});
}}
/>
<Textarea
@@ -36,6 +69,12 @@ export default function Colab_Create() {
placeholder="Masukan tujuan proyek"
withAsterisk
minRows={5}
onChange={(val) => {
setValue({
...value,
purpose: val.currentTarget.value,
});
}}
/>
<Textarea
@@ -43,20 +82,33 @@ export default function Colab_Create() {
placeholder="Masukan keuntungan dalam proyek"
withAsterisk
minRows={5}
onChange={(val) => {
setValue({
...value,
benefit: val.currentTarget.value,
});
}}
/>
<ButtonAction />
<ButtonAction value={value} />
</Stack>
</>
);
}
function ButtonAction() {
function ButtonAction({ value }: { value: any }) {
const router = useRouter();
const [loading, setLoading] = useState(false);
async function onSave() {
setLoading(true);
router.back();
await colab_funCreateProyek(value).then((res) => {
if (res.status === 201) {
setLoading(true);
router.back();
ComponentGlobal_NotifikasiBerhasil(res.message);
} else {
ComponentGlobal_NotifikasiGagal(res.message)
}
});
}
return (

View File

@@ -0,0 +1,27 @@
"use server";
import prisma from "@/app/lib/prisma";
import { MODEL_COLLABORATION } from "../../model/interface";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
export default async function colab_funCreateProyek(
value: MODEL_COLLABORATION
) {
const Author = await User_getUserId();
console.log(Author);
const create = await prisma.projectCollaboration.create({
data: {
title: value.title,
lokasi: value.lokasi,
purpose: value.purpose,
benefit: value.benefit,
projectCollaborationMaster_IndustriId:
value.projectCollaborationMaster_IndustriId,
userId: Author
},
});
if (!create) return { status: 400, message: "Gagal Membuat Proyek" };
return { status: 201, message: "Berhasil Membuar Proyek" };
}

View File

@@ -0,0 +1,5 @@
"use server"
export default async function colab_getListAllProyek() {
}

View File

@@ -0,0 +1,8 @@
"use server";
import prisma from "@/app/lib/prisma";
export default async function colab_funGetMasterIndustri() {
const data = await prisma.projectCollaborationMaster_Industri.findMany({});
return data;
}

View File

@@ -0,0 +1,8 @@
"use server";
import prisma from "@/app/lib/prisma";
export default async function colab_funGetMasterStatus() {
const data = await prisma.projectCollaborationMaster_Status.findMany({});
return data;
}

View File

@@ -0,0 +1,27 @@
import { MODEL_USER } from "@/app_modules/home/model/interface";
export interface MODEL_COLLABORATION_MASTER {
id: string;
name: string;
isActive: boolean;
createdAt: Date;
updatedAt: Date;
}
export interface MODEL_COLLABORATION {
id: string;
isActive: boolean;
createdAt: Date;
updatedAt: Date;
catatan: string;
title: string;
lokasi: string;
purpose: string;
benefit: string;
ProjectCollaborationMaster_Industri: MODEL_COLLABORATION_MASTER[];
projectCollaborationMaster_IndustriId: number;
Author: MODEL_USER;
ProjectCollaborationMaster_Status: MODEL_COLLABORATION_MASTER[];
projectCollaborationMaster_StatusId: number
// ProjectCollaboration_Partisipasi
}