diff --git a/README_DEV.md b/README_DEV.md index 163712b5..f209b32e 100644 --- a/README_DEV.md +++ b/README_DEV.md @@ -1,3 +1,5 @@ +## Page info + ### API - src/app/api @@ -28,3 +30,8 @@ Deskripsi: Folder client yang mencakup sub menu dari menu-menu utama - Home: 1. home page + +## NOTE +Function name: +- g = global +- gs = global state \ No newline at end of file diff --git a/src/app/api/profile/edit/route.ts b/src/app/api/profile/edit/route.ts new file mode 100644 index 00000000..d41cd1d4 --- /dev/null +++ b/src/app/api/profile/edit/route.ts @@ -0,0 +1,33 @@ +import { myConsole } from "@/app/fun/my_console"; +import prisma from "@/app/lib/prisma"; +import { NextResponse } from "next/server"; + +export async function POST(req: Request) { + if (req.method === "POST") { + const body = await req.json(); + // myConsole(body); + + const data = await prisma.profile.update({ + where: { + id: body.id + }, + data: { + name: body.name, + email: body.email, + alamat: body.alamat, + jenisKelamin: body.jenisKelamin + } + }) + + if(data) { + return NextResponse.json({status: 200}) + } else { + return new Response("Error",{ status :401 }); + } + + + + return NextResponse.json({ success: true }); + } + return NextResponse.json({ success: false }); +} diff --git a/src/app/dev/katalog/profile/edit/layout.tsx b/src/app/dev/katalog/profile/edit/layout.tsx new file mode 100644 index 00000000..9b8d49f1 --- /dev/null +++ b/src/app/dev/katalog/profile/edit/layout.tsx @@ -0,0 +1,9 @@ +import { EditProfileLayout } from "@/app_modules/katalog/profile"; + +export default function Layout({ children }: { children: any }) { + return ( + <> + {children} + + ); +} diff --git a/src/app/dev/katalog/profile/edit/page.tsx b/src/app/dev/katalog/profile/edit/page.tsx new file mode 100644 index 00000000..a1684084 --- /dev/null +++ b/src/app/dev/katalog/profile/edit/page.tsx @@ -0,0 +1,13 @@ +import { getProfile } from "@/app_modules/katalog/profile"; +import EditProfile from "@/app_modules/katalog/profile/edit/view"; + +export default async function Page() { + const data = await getProfile(); + + return ( + <> + {/* {JSON.stringify(data)} */} + + + ); +} diff --git a/src/app/dev/katalog/view/page.tsx b/src/app/dev/katalog/view/page.tsx index 5463ee42..62de781d 100644 --- a/src/app/dev/katalog/view/page.tsx +++ b/src/app/dev/katalog/view/page.tsx @@ -1,7 +1,12 @@ +import { getProfile } from "@/app_modules/katalog/profile"; import { KatalogView } from "@/app_modules/katalog/view"; export default async function Page() { - return <> - + const data = await getProfile(); + return ( + <> + {/* {JSON.stringify(data)} */} + -} \ No newline at end of file + ); +} diff --git a/src/app/fun/my_console.ts b/src/app/fun/my_console.ts index 631977d6..3be763da 100644 --- a/src/app/fun/my_console.ts +++ b/src/app/fun/my_console.ts @@ -1,5 +1,5 @@ export function myConsole(value: any) { - const onData = false; + const onData = true; if (onData) { console.log(value); } diff --git a/src/app/lib/api.ts b/src/app/lib/api.ts index 30855752..31500caf 100644 --- a/src/app/lib/api.ts +++ b/src/app/lib/api.ts @@ -8,5 +8,6 @@ export const ApiHipmi = { logout: "/api/auth/logout", //Profile - create_profile: "/api/profile/create" + create_profile: "/api/profile/create", + edit_profile: "/api/profile/edit", }; diff --git a/src/app_modules/home/fun/get-token.ts b/src/app_modules/home/fun/api-get-token.ts similarity index 100% rename from src/app_modules/home/fun/get-token.ts rename to src/app_modules/home/fun/api-get-token.ts diff --git a/src/app_modules/home/index.ts b/src/app_modules/home/index.ts index 30db04bb..fb448aff 100644 --- a/src/app_modules/home/index.ts +++ b/src/app_modules/home/index.ts @@ -1,4 +1,4 @@ import HomeView from "./view"; import HomeLayout from "./layout"; -import { getToken } from "./fun/get-token"; +import { getToken } from "./fun/api-get-token"; export {HomeView, HomeLayout, getToken} \ No newline at end of file diff --git a/src/app_modules/home/view.tsx b/src/app_modules/home/view.tsx index b04768cc..acf582c2 100644 --- a/src/app_modules/home/view.tsx +++ b/src/app_modules/home/view.tsx @@ -15,7 +15,7 @@ import { Logout } from "../auth"; import { useState } from "react"; import { ApiHipmi } from "@/app/lib/api"; import { useShallowEffect } from "@mantine/hooks"; -import { getToken } from "./fun/get-token"; +import { getToken } from "./fun/api-get-token"; import { IconAffiliate, diff --git a/src/app_modules/katalog/profile/edit/layout.tsx b/src/app_modules/katalog/profile/edit/layout.tsx new file mode 100644 index 00000000..eb33bac3 --- /dev/null +++ b/src/app_modules/katalog/profile/edit/layout.tsx @@ -0,0 +1,36 @@ +"use client"; + +import { + ActionIcon, + AppShell, + Group, + Header, + Text, + Title, +} from "@mantine/core"; +import { IconArrowLeft } from "@tabler/icons-react"; +import { useRouter } from "next/navigation"; + +export default function EditProfileLayout({ children }: { children: any }) { + const router = useRouter() + return ( + <> + + + router.push("/dev/katalog/view")}> + + + Edit Profile + + + + } + > + {children} + + + ); +} diff --git a/src/app_modules/katalog/profile/edit/view.tsx b/src/app_modules/katalog/profile/edit/view.tsx new file mode 100644 index 00000000..2c39c97d --- /dev/null +++ b/src/app_modules/katalog/profile/edit/view.tsx @@ -0,0 +1,122 @@ +"use client"; + +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 { useShallowEffect } from "@mantine/hooks"; +import { useAtom } from "jotai"; +import _ from "lodash"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import toast from "react-simple-toasts"; +import { gs_profile } from "../state/global_state"; +import { g_getProfile } from "../fun/fun-get-profile"; + +export default function EditProfile({ data }: { data: any }) { + const router = useRouter(); + + //Get data profile + const [profile, setProfile] = useAtom(gs_profile); + useShallowEffect(() => { + g_getProfile(setProfile); + }, []); + + + async function onUpdate() { + const body = profile; + 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"); + return router.push("/dev/katalog/view"); + } else { + return toast("Gagal update !!!"); + } + }); + } + + return ( + <> + {/* {JSON.stringify(profile)} */} + + + + + { + setProfile({ + ...profile, + name: val.target.value, + }); + }} + /> + + { + myConsole(val.target.value); + setProfile({ + ...profile, + email: val.target.value, + }); + }} + /> + + { + myConsole(val.target.value); + setProfile({ + ...profile, + alamat: val.target.value, + }); + }} + /> + +