From 9a914bb5130008abd58d7b2547d6ee7684400040 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Tue, 3 Oct 2023 11:56:33 +0800 Subject: [PATCH 1/6] feat Desc: - Fitur config untuk error pada server di bagian .env PWD - Fitur home dan tampilan menu --- public/{img => aset}/logo.png | Bin src/app/dev/home/layout.tsx | 9 ++ src/app_modules/auth/login/view.tsx | 53 +++++------ src/app_modules/auth/register/view.tsx | 3 + src/app_modules/auth/validasi/view.tsx | 4 + src/app_modules/home/fun/get-token.ts | 3 + src/app_modules/home/index.ts | 4 +- src/app_modules/home/layout.tsx | 35 ++++++++ src/app_modules/home/view.tsx | 117 ++++++++++++++++++++++--- 9 files changed, 186 insertions(+), 42 deletions(-) rename public/{img => aset}/logo.png (100%) create mode 100644 src/app/dev/home/layout.tsx create mode 100644 src/app_modules/home/layout.tsx diff --git a/public/img/logo.png b/public/aset/logo.png similarity index 100% rename from public/img/logo.png rename to public/aset/logo.png diff --git a/src/app/dev/home/layout.tsx b/src/app/dev/home/layout.tsx new file mode 100644 index 00000000..6d14346a --- /dev/null +++ b/src/app/dev/home/layout.tsx @@ -0,0 +1,9 @@ +import { HomeLayout } from "@/app_modules/home"; + +export default async function Layout({children}: {children: any}) { + return <> + {children} + + + +} \ No newline at end of file diff --git a/src/app_modules/auth/login/view.tsx b/src/app_modules/auth/login/view.tsx index fe2c12ba..1d85d77c 100644 --- a/src/app_modules/auth/login/view.tsx +++ b/src/app_modules/auth/login/view.tsx @@ -64,34 +64,35 @@ export default function Login() { align={"center"} gap={"lg"} > - <> - - Login + + Login - { - setNomor(val.target.value); - }} - /> + { + setNomor(val.target.value); + }} + /> - - + ); diff --git a/src/app_modules/auth/register/view.tsx b/src/app_modules/auth/register/view.tsx index 77138810..7a416909 100644 --- a/src/app_modules/auth/register/view.tsx +++ b/src/app_modules/auth/register/view.tsx @@ -60,6 +60,7 @@ export default function Register() { { @@ -70,6 +71,8 @@ export default function Register() { Nomor : {nomor} + + onLogout()}/> + ); } diff --git a/src/app_modules/home/layout.tsx b/src/app_modules/home/layout.tsx index fa4a674d..dc479717 100644 --- a/src/app_modules/home/layout.tsx +++ b/src/app_modules/home/layout.tsx @@ -2,6 +2,7 @@ import { ActionIcon, AppShell, Flex, Group, Header, Text } from "@mantine/core"; import { HomeView } from "."; import { IconUserSearch, IconAward, IconQrcode } from "@tabler/icons-react"; +import { Logout } from "../auth"; export default function HomeLayout({ children }: { children: any }) { return ( @@ -10,20 +11,23 @@ export default function HomeLayout({ children }: { children: any }) { header={
- - - - - HIPMI - - + + + + + + + HIPMI + + - + +
} diff --git a/src/app_modules/home/view.tsx b/src/app_modules/home/view.tsx index cb6bbc51..f19bd1ff 100644 --- a/src/app_modules/home/view.tsx +++ b/src/app_modules/home/view.tsx @@ -95,7 +95,7 @@ export default function HomeView() { - Welcome to, {token?.username} + Welcome to, {token?.username ? token?.username : "SERVER ERROR"}
logo From b505e5813e0409eebdcc45611f28bc31d57c2dcb Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Tue, 3 Oct 2023 17:46:15 +0800 Subject: [PATCH 3/6] fix Desc: - Perubahan tampilan --- src/app_modules/auth/logout/view.tsx | 4 + src/app_modules/home/index.ts | 3 +- src/app_modules/home/state/global_state.ts | 3 + src/app_modules/home/view.tsx | 52 ++++++-- .../katalog/component/header_transparent.tsx | 27 +++++ src/app_modules/katalog/index.ts | 3 + .../katalog/profile/create/layout.tsx | 36 ++++++ .../katalog/profile/create/view.tsx | 112 ++++++++++++++++++ .../katalog/profile/fun/get-profile.ts | 33 ++++++ src/app_modules/katalog/profile/index.ts | 4 + src/app_modules/katalog/view/index.ts | 4 + src/app_modules/katalog/view/layout.tsx | 41 +++++++ src/app_modules/katalog/view/view.tsx | 13 ++ 13 files changed, 321 insertions(+), 14 deletions(-) create mode 100644 src/app_modules/home/state/global_state.ts create mode 100644 src/app_modules/katalog/component/header_transparent.tsx create mode 100644 src/app_modules/katalog/index.ts create mode 100644 src/app_modules/katalog/profile/create/layout.tsx create mode 100644 src/app_modules/katalog/profile/create/view.tsx create mode 100644 src/app_modules/katalog/profile/fun/get-profile.ts create mode 100644 src/app_modules/katalog/profile/index.ts create mode 100644 src/app_modules/katalog/view/index.ts create mode 100644 src/app_modules/katalog/view/layout.tsx create mode 100644 src/app_modules/katalog/view/view.tsx diff --git a/src/app_modules/auth/logout/view.tsx b/src/app_modules/auth/logout/view.tsx index a9c5fd12..9da7b017 100644 --- a/src/app_modules/auth/logout/view.tsx +++ b/src/app_modules/auth/logout/view.tsx @@ -7,11 +7,14 @@ import { useAtom } from "jotai"; import { gs_nomor, gs_otp } from "../state/state"; import { IconLogout } from "@tabler/icons-react"; import { Warna } from "@/app/lib/warna"; +import { gs_token } from "@/app_modules/home/state/global_state"; export default function Logout() { const router = useRouter(); const [nomor, setnomor] = useAtom(gs_nomor); const [code, setCode] = useAtom(gs_otp); + const [token, setToken] = useAtom(gs_token); + const onLogout = async () => { // MyConsole("keluar"); @@ -22,6 +25,7 @@ export default function Logout() { if (val.status == 200) { setnomor(null); setCode(null); + setToken(null) return router.push("/dev/auth/login"); } diff --git a/src/app_modules/home/index.ts b/src/app_modules/home/index.ts index 7de0b72b..30db04bb 100644 --- a/src/app_modules/home/index.ts +++ b/src/app_modules/home/index.ts @@ -1,3 +1,4 @@ import HomeView from "./view"; import HomeLayout from "./layout"; -export {HomeView, HomeLayout} \ No newline at end of file +import { getToken } from "./fun/get-token"; +export {HomeView, HomeLayout, getToken} \ No newline at end of file diff --git a/src/app_modules/home/state/global_state.ts b/src/app_modules/home/state/global_state.ts new file mode 100644 index 00000000..638d7246 --- /dev/null +++ b/src/app_modules/home/state/global_state.ts @@ -0,0 +1,3 @@ +import { atomWithStorage } from "jotai/utils"; + +export const gs_token = atomWithStorage("gs_token", null); diff --git a/src/app_modules/home/view.tsx b/src/app_modules/home/view.tsx index f19bd1ff..b04768cc 100644 --- a/src/app_modules/home/view.tsx +++ b/src/app_modules/home/view.tsx @@ -1,6 +1,16 @@ "use client"; -import { ActionIcon, Box, Flex, Image, Paper, SimpleGrid, Text, Title } from "@mantine/core"; +import { + ActionIcon, + Box, + Flex, + Image, + Loader, + Paper, + SimpleGrid, + Text, + Title, +} from "@mantine/core"; import { Logout } from "../auth"; import { useState } from "react"; import { ApiHipmi } from "@/app/lib/api"; @@ -18,8 +28,12 @@ import { IconShoppingBag, IconUserCircle, } from "@tabler/icons-react"; -import router from "next/router"; + import toast from "react-simple-toasts"; +import { getProfile } from "../katalog/profile"; +import { useRouter } from "next/navigation"; +import { useAtom } from "jotai"; +import { gs_token } from "./state/global_state"; const listHalaman = [ { @@ -65,7 +79,9 @@ const listHalaman = [ ]; export default function HomeView() { - const [token, setToken] = useState(null); + const router = useRouter(); + const [token, setToken] = useAtom(gs_token); + const [profile, setProfile] = useState(null); useShallowEffect(() => { getUserId(); @@ -75,27 +91,37 @@ export default function HomeView() { setToken(data); } + useShallowEffect(() => { + getUserProfile(); + }, []); + async function getUserProfile() { + const data = await getProfile(); + setProfile(data); + } + return ( <> - {/*
{JSON.stringify(token, null, 2)}
*/} - + {/*
{JSON.stringify(profile, null, 2)}
*/} { - // if (valToken?.data?.Profile === null) { - // return router.push("/dev/katalog/profile/create"); - // } else { - // return router.push("/dev/katalog/view"); - // } - // }} + onClick={() => { + if (profile === null) { + return router.push("/dev/katalog/profile/create"); + } else { + return router.push("/dev/katalog/view"); + } + }} > - Welcome to, {token?.username ? token?.username : "SERVER ERROR"} + + Welcome to,{" "} + {token?.username ? token?.username : } + logo diff --git a/src/app_modules/katalog/component/header_transparent.tsx b/src/app_modules/katalog/component/header_transparent.tsx new file mode 100644 index 00000000..05b1feb2 --- /dev/null +++ b/src/app_modules/katalog/component/header_transparent.tsx @@ -0,0 +1,27 @@ +"use client"; + +import { Header, Group, ActionIcon, Text } from "@mantine/core"; +import { IconArrowLeft } from "@tabler/icons-react"; +import React from "react"; + +export default function headerTransparent({ + icon1, + icon2, + title, +}: { + icon1: React.ReactNode; + icon2: React.ReactNode; + title: string; +}) { + return ( + <> +
+ + {icon1} + {title} + {icon2} + +
+ + ); +} diff --git a/src/app_modules/katalog/index.ts b/src/app_modules/katalog/index.ts new file mode 100644 index 00000000..740fbc1b --- /dev/null +++ b/src/app_modules/katalog/index.ts @@ -0,0 +1,3 @@ +import headerTransparent from "./component/header_transparent"; + +export {headerTransparent} \ No newline at end of file diff --git a/src/app_modules/katalog/profile/create/layout.tsx b/src/app_modules/katalog/profile/create/layout.tsx new file mode 100644 index 00000000..4d726bde --- /dev/null +++ b/src/app_modules/katalog/profile/create/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 ProfileLayout({ children }: { children: any }) { + const router = useRouter() + return ( + <> + + + router.push("/dev/home")}> + + + Create Profile + + + + } + > + {children} + + + ); +} diff --git a/src/app_modules/katalog/profile/create/view.tsx b/src/app_modules/katalog/profile/create/view.tsx new file mode 100644 index 00000000..ce8f9ffd --- /dev/null +++ b/src/app_modules/katalog/profile/create/view.tsx @@ -0,0 +1,112 @@ +"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 { useAtom } from "jotai"; +import _ from "lodash"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import toast from "react-simple-toasts"; + +export default function CreateProfile() { + const router = useRouter(); + const [token, setToken] = useAtom(gs_token); + + const [value, setValue] = useState({ + name: "", + email: "", + alamat: "", + jenisKelamin: "", + }); + + async function onSubmit() { + const body = { + userId: token?.id, + name: value.name, + email: value.email, + alamat: value.alamat, + jenisKelamin: value.jenisKelamin, + }; + + myConsole(body); + + 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!!!") + } + }); + } + + return ( + <> + + { + setValue({ + ...value, + name: val.target.value, + }); + }} + /> + { + setValue({ + ...value, + email: val.target.value, + }); + }} + /> + { + setValue({ + ...value, + alamat: val.target.value, + }); + }} + /> +