From 7035139733faacc4f2c61ea5f2d443c9c2305487 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Tue, 17 Oct 2023 11:38:05 +0800 Subject: [PATCH 1/3] fix Desc: - Perubahan minor Issue: Di server master bidang bisnis tidak terpanggil --- src/app/dev/portofolio/create/page.tsx | 7 ++-- src/app/dev/portofolio/main/[id]/layout.tsx | 9 ++++ src/app/dev/portofolio/main/[id]/page.tsx | 15 +++++++ .../katalog/component/header_transparent.tsx | 16 +++++--- src/app_modules/katalog/index.ts | 4 +- .../katalog/portofolio/create/layout.tsx | 2 +- .../katalog/portofolio/create/view.tsx | 13 ++++-- .../portofolio/fun/fun_get_all_portofolio.ts | 16 ++++++++ ..._bidang_bisnis.ts => get_bidang_bisnis.ts} | 0 .../portofolio/fun/get_one_portofolio.ts | 29 +++++++++++++ src/app_modules/katalog/portofolio/index.ts | 6 ++- .../katalog/portofolio/list_view/view.tsx | 12 +++++- .../katalog/portofolio/main/layout.tsx | 33 +++++++++++++++ .../katalog/portofolio/main/view.tsx | 41 +++++++++++++++++++ src/app_modules/models/portofolio.ts | 32 +++++++++++---- 15 files changed, 208 insertions(+), 27 deletions(-) create mode 100644 src/app/dev/portofolio/main/[id]/layout.tsx create mode 100644 src/app/dev/portofolio/main/[id]/page.tsx create mode 100644 src/app_modules/katalog/portofolio/fun/fun_get_all_portofolio.ts rename src/app_modules/katalog/portofolio/fun/{get_list_bidang_bisnis.ts => get_bidang_bisnis.ts} (100%) create mode 100644 src/app_modules/katalog/portofolio/fun/get_one_portofolio.ts create mode 100644 src/app_modules/katalog/portofolio/main/layout.tsx create mode 100644 src/app_modules/katalog/portofolio/main/view.tsx diff --git a/src/app/dev/portofolio/create/page.tsx b/src/app/dev/portofolio/create/page.tsx index 92d01ad6..353e59f4 100644 --- a/src/app/dev/portofolio/create/page.tsx +++ b/src/app/dev/portofolio/create/page.tsx @@ -1,16 +1,17 @@ import { myConsole } from "@/app/fun/my_console"; import { CreatePortofolio } from "@/app_modules/katalog/portofolio"; -import { getBidangBisnis } from "@/app_modules/katalog/portofolio/fun/get_list_bidang_bisnis"; +import { getBidangBisnis } from "@/app_modules/katalog/portofolio/fun/get_bidang_bisnis"; import { getProfile } from "@/app_modules/katalog/profile"; export default async function Page() { - const bidangBisnis = await getBidangBisnis(); + const bidangBisnis = await getBidangBisnis() const id = await getProfile(); const profileId = id?.id; + // console.log(bidangBisnis) return ( <> - + ); } diff --git a/src/app/dev/portofolio/main/[id]/layout.tsx b/src/app/dev/portofolio/main/[id]/layout.tsx new file mode 100644 index 00000000..c6d17588 --- /dev/null +++ b/src/app/dev/portofolio/main/[id]/layout.tsx @@ -0,0 +1,9 @@ +import { PortofolioLayout } from "@/app_modules/katalog/portofolio"; + +export default async function Layout({ children }: { children: any }) { + return ( + <> + {children} + + ); +} diff --git a/src/app/dev/portofolio/main/[id]/page.tsx b/src/app/dev/portofolio/main/[id]/page.tsx new file mode 100644 index 00000000..25e9a13e --- /dev/null +++ b/src/app/dev/portofolio/main/[id]/page.tsx @@ -0,0 +1,15 @@ +import { ViewPortofolio } from "@/app_modules/katalog/portofolio"; +import { getOnePortofolio } from "@/app_modules/katalog/portofolio/fun/get_one_portofolio"; + +export default async function Page({params}: {params: {id: string}}) { + + const getPorto = await getOnePortofolio(params.id) + // console.log(getPorto) + + return ( + <> + {/* {JSON.stringify(getPorto)} */} + + + ); +} diff --git a/src/app_modules/katalog/component/header_transparent.tsx b/src/app_modules/katalog/component/header_transparent.tsx index 05b1feb2..27c3c7e4 100644 --- a/src/app_modules/katalog/component/header_transparent.tsx +++ b/src/app_modules/katalog/component/header_transparent.tsx @@ -2,22 +2,28 @@ import { Header, Group, ActionIcon, Text } from "@mantine/core"; import { IconArrowLeft } from "@tabler/icons-react"; +import { useRouter } from "next/navigation"; import React from "react"; -export default function headerTransparent({ - icon1, +export default function HeaderTransparent({ + route, icon2, title, }: { - icon1: React.ReactNode; - icon2: React.ReactNode; + route: any; + icon2: any; title: string; }) { + const router = useRouter(); return ( <> +
- {icon1} + router.push(route)}> + + + {title} {icon2} diff --git a/src/app_modules/katalog/index.ts b/src/app_modules/katalog/index.ts index 740fbc1b..215b6612 100644 --- a/src/app_modules/katalog/index.ts +++ b/src/app_modules/katalog/index.ts @@ -1,3 +1,3 @@ -import headerTransparent from "./component/header_transparent"; +import HeaderTransparent from "./component/header_transparent"; -export {headerTransparent} \ No newline at end of file +export {HeaderTransparent as headerTransparent} \ No newline at end of file diff --git a/src/app_modules/katalog/portofolio/create/layout.tsx b/src/app_modules/katalog/portofolio/create/layout.tsx index e5e6e58c..5deec16c 100644 --- a/src/app_modules/katalog/portofolio/create/layout.tsx +++ b/src/app_modules/katalog/portofolio/create/layout.tsx @@ -4,7 +4,7 @@ import { ActionIcon, AppShell, Group, Header, Text } from "@mantine/core"; import { IconArrowLeft } from "@tabler/icons-react"; import { useRouter } from "next/navigation"; -export default function PortofolioLayout({ children }: { children: any }) { +export default function CreatePortofolioLayout({ children }: { children: any }) { const router = useRouter(); return ( <> diff --git a/src/app_modules/katalog/portofolio/create/view.tsx b/src/app_modules/katalog/portofolio/create/view.tsx index f8863e4b..a205a126 100644 --- a/src/app_modules/katalog/portofolio/create/view.tsx +++ b/src/app_modules/katalog/portofolio/create/view.tsx @@ -3,6 +3,7 @@ import { myConsole } from "@/app/fun/my_console"; import { ApiHipmi } from "@/app/lib/api"; import { Warna } from "@/app/lib/warna"; +import { BIDANG_BISNIS } from "@/app_modules/models/portofolio"; import { Button, Select, Stack, TextInput, Title } from "@mantine/core"; import _ from "lodash"; import { useRouter } from "next/navigation"; @@ -10,10 +11,10 @@ import { useState } from "react"; import toast from "react-simple-toasts"; export default function CreatePortofolio({ - data, + bidangBisnis, profileId, }: { - data: any; + bidangBisnis: BIDANG_BISNIS; profileId: any; }) { const router = useRouter(); @@ -46,7 +47,7 @@ export default function CreatePortofolio({ }) .then((res) => res.json()) .then((val) => { - myConsole(val) + myConsole(val); if (val.status == 201) { toast("Berhasil disimpan"); return router.push("/dev/katalog/view"); @@ -58,6 +59,7 @@ export default function CreatePortofolio({ return ( <> + {/* {JSON.stringify(bidangBisnis)} */} ({ + data={_.map(bidangBisnis as any).map((e: any) => ({ value: e.id, label: e.name, }))} @@ -108,7 +100,7 @@ export default function CreatePortofolio({ onChange={(val) => { setValue({ ...value, - deskripssi: val.target.value, + deskripsi: val.target.value, }); }} /> diff --git a/src/app_modules/katalog/portofolio/fun/fun_create_portofolio.ts b/src/app_modules/katalog/portofolio/fun/fun_create_portofolio.ts new file mode 100644 index 00000000..1cc3caf5 --- /dev/null +++ b/src/app_modules/katalog/portofolio/fun/fun_create_portofolio.ts @@ -0,0 +1,32 @@ +"use server"; + +import prisma from "@/app/lib/prisma"; +import { MODEL_PORTOFOLIO } from "@/app_modules/models/portofolio"; +import { revalidatePath } from "next/cache"; + +export default async function funCreatePortofolio(data: MODEL_PORTOFOLIO) { + console.log(data); + + const res = await prisma.katalog.create({ + data: { + profileId: data.profileId, + namaBisnis: data.namaBisnis, + deskripsi: data.deskripsi, + tlpn: data.tlpn, + alamatKantor: data.alamatKantor, + masterBidangBisnisId: data.masterBidangBisnisId, + }, + }); + + if (!res) + return { + status: 401, + success: false, + }; + + revalidatePath(`/dev/katalog/${data.profileId}`); + return { + status: 201, + success: true, + }; +} diff --git a/src/app_modules/katalog/portofolio/fun/get_list_portofolio.ts b/src/app_modules/katalog/portofolio/fun/get_list_portofolio.ts index fa5a000f..7a4d6e38 100644 --- a/src/app_modules/katalog/portofolio/fun/get_list_portofolio.ts +++ b/src/app_modules/katalog/portofolio/fun/get_list_portofolio.ts @@ -12,9 +12,10 @@ export async function funGetListPortofolio(profileId: any) { namaBisnis: true, alamatKantor: true, tlpn: true, - deskripssi: true, + deskripsi: true, masterBidangBisnisId: true, active: true, + profileId: true }, }); diff --git a/src/app_modules/katalog/portofolio/fun/get_one_portofolio.ts b/src/app_modules/katalog/portofolio/fun/get_one_portofolio.ts index 154f5edb..91572a8c 100644 --- a/src/app_modules/katalog/portofolio/fun/get_one_portofolio.ts +++ b/src/app_modules/katalog/portofolio/fun/get_one_portofolio.ts @@ -12,7 +12,7 @@ export async function getOnePortofolio(id: string) { id: true, namaBisnis: true, alamatKantor: true, - deskripssi: true, + deskripsi: true, tlpn: true, active: true, MasterBidangBisnis: { @@ -22,6 +22,7 @@ export async function getOnePortofolio(id: string) { active: true, }, }, + profileId: true, }, }); diff --git a/src/app_modules/katalog/portofolio/main/layout.tsx b/src/app_modules/katalog/portofolio/main/layout.tsx index f13b46ca..e19363c9 100644 --- a/src/app_modules/katalog/portofolio/main/layout.tsx +++ b/src/app_modules/katalog/portofolio/main/layout.tsx @@ -6,14 +6,14 @@ import HeaderTransparent from "../../component/header_transparent"; import { useRouter } from "next/navigation"; import { IconArrowLeft, IconEdit } from "@tabler/icons-react"; -export default function PortofolioLayout({ children }: { children: any }) { +export default function PortofolioLayout({ children, profileId }: { children: any, profileId: any }) { const router = useRouter(); return ( <> {porto.namaBisnis} {porto.alamatKantor} +{porto.tlpn} - {porto.deskripssi} + {porto.deskripsi} {porto.MasterBidangBisnis.name}
- {" "}
diff --git a/src/app_modules/katalog/profile/create/view.tsx b/src/app_modules/katalog/profile/create/view.tsx index ce8f9ffd..563ea13c 100644 --- a/src/app_modules/katalog/profile/create/view.tsx +++ b/src/app_modules/katalog/profile/create/view.tsx @@ -10,10 +10,10 @@ import _ from "lodash"; import { useRouter } from "next/navigation"; import { useState } from "react"; import toast from "react-simple-toasts"; +import funCreateNewProfile from "../fun/fun_create_profile"; -export default function CreateProfile() { +export default function CreateProfile({ userId }: { userId: any }) { const router = useRouter(); - const [token, setToken] = useAtom(gs_token); const [value, setValue] = useState({ name: "", @@ -24,7 +24,7 @@ export default function CreateProfile() { async function onSubmit() { const body = { - userId: token?.id, + userId: userId, name: value.name, email: value.email, alamat: value.alamat, @@ -36,22 +36,14 @@ export default function CreateProfile() { if (_.values(value).includes("")) return toast("Lengkapi data"); // if(_.values(value.email).includes(`${/^\S+@\S+$/.test(value.email) ? null : "Invalid email"}`)){} - await fetch(ApiHipmi.create_profile, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(body), - }) - .then((res) => res.json()) - .then((val) => { - if (val.status == 201) { - toast("Data tersimpan") - return router.push("/dev/katalog/view"); - } else { - return toast("Server Error!!!") - } - }); + await funCreateNewProfile(body).then((res) => { + if (res.status === 201) { + toast("Data tersimpan"); + return router.push("/dev/katalog/view"); + } else { + toast("Gagal") + } + }); } return ( diff --git a/src/app_modules/katalog/profile/edit/layout.tsx b/src/app_modules/katalog/profile/edit/layout.tsx index eb33bac3..b15d0da8 100644 --- a/src/app_modules/katalog/profile/edit/layout.tsx +++ b/src/app_modules/katalog/profile/edit/layout.tsx @@ -11,7 +11,7 @@ import { import { IconArrowLeft } from "@tabler/icons-react"; import { useRouter } from "next/navigation"; -export default function EditProfileLayout({ children }: { children: any }) { +export default function EditProfileLayout({ children, profileId }: { children: any, profileId: any }) { const router = useRouter() return ( <> @@ -20,7 +20,7 @@ export default function EditProfileLayout({ children }: { children: any }) { header={
- router.push("/dev/katalog/view")}> + router.push(`/dev/katalog/${profileId}`)}> Edit Profile diff --git a/src/app_modules/katalog/profile/edit/view.tsx b/src/app_modules/katalog/profile/edit/view.tsx index 9f7a80d5..72f88401 100644 --- a/src/app_modules/katalog/profile/edit/view.tsx +++ b/src/app_modules/katalog/profile/edit/view.tsx @@ -4,7 +4,7 @@ import { myConsole } from "@/app/fun/my_console"; import { ApiHipmi } from "@/app/lib/api"; import { Warna } from "@/app/lib/warna"; import { gs_token } from "@/app_modules/home/state/global_state"; -import { Button, Select, Stack, TextInput } from "@mantine/core"; +import { Button, Loader, Select, Stack, TextInput } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import { useAtom } from "jotai"; import _ from "lodash"; @@ -13,57 +13,53 @@ import { useState } from "react"; import toast from "react-simple-toasts"; import { gs_profile } from "../state/global_state"; import { loadDataProfile } from "../fun/fun_get_profile"; +import { USER_PROFILE } from "@/app_modules/models/user_profile"; +import funEditProfile from "../fun/fun_edit_profile"; -export default function EditProfile({ data }: { data: any }) { +export default function EditProfile({ data }: { data: USER_PROFILE }) { const router = useRouter(); //Get data profile - const [profile, setProfile] = useAtom(gs_profile) - useShallowEffect(() => { - loadDataProfile(setProfile); - }, []); + const [dataProfile, setDataProfile] = useState(data); async function onUpdate() { - const body = profile; + const body = dataProfile; if (_.values(body).includes("")) return toast("Lengkapi data"); - await fetch(ApiHipmi.edit_profile, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(body), - }) - .then((res) => res.json()) - .then((val) => { - myConsole(val); - if (val.status == 200) { - toast("Data tersimpan"); - loadDataProfile(setProfile) - return setTimeout(() => router.push("/dev/katalog/view"), 1000); - } else { - return toast("Gagal update !!!"); - } - }); + await funEditProfile(body).then((res) => { + if (res.status === 200) { + toast("Update berhasil"); + setTimeout(() => router.push(`/dev/katalog/${data.Profile?.id}`), 1000); + } else { + toast("Gagal update"); + } + }); } - if(!profile) return <> + if (!dataProfile) + return ( + <> + + + ); return ( <> - {/* {JSON.stringify(profile)} */} - - + + { - setProfile({ - ...profile, - name: val.target.value, + setDataProfile({ + ...(dataProfile as any), + Profile: { + ...dataProfile.Profile, + name: val.target.value, + }, }); }} /> @@ -71,12 +67,14 @@ export default function EditProfile({ data }: { data: any }) { { - myConsole(val.target.value); - setProfile({ - ...profile, - email: val.target.value, + setDataProfile({ + ...(dataProfile as any), + Profile: { + ...dataProfile.Profile, + email: val.target.value, + }, }); }} /> @@ -84,27 +82,32 @@ export default function EditProfile({ data }: { data: any }) { { - myConsole(val.target.value); - setProfile({ - ...profile, - alamat: val.target.value, + setDataProfile({ + ...(dataProfile as any), + Profile: { + ...dataProfile.Profile, + alamat: val.target.value, + }, }); }} />