diff --git a/public/img/2eef80a1-f811-4769-980a-63bfe97e1a6e.webp b/public/img/2eef80a1-f811-4769-980a-63bfe97e1a6e.webp new file mode 100644 index 00000000..e0c75142 Binary files /dev/null and b/public/img/2eef80a1-f811-4769-980a-63bfe97e1a6e.webp differ diff --git a/public/img/68adba2f-db46-4074-82ea-7d2ea5f5bd35.png b/public/img/68adba2f-db46-4074-82ea-7d2ea5f5bd35.png new file mode 100644 index 00000000..b4ef2a39 Binary files /dev/null and b/public/img/68adba2f-db46-4074-82ea-7d2ea5f5bd35.png differ diff --git a/src/app/api/auth/validasi/route.ts b/src/app/api/auth/validasi/route.ts index 98d57f05..ba849d0e 100644 --- a/src/app/api/auth/validasi/route.ts +++ b/src/app/api/auth/validasi/route.ts @@ -6,6 +6,7 @@ import { sealData, unsealData } from "iron-session"; import { getConfig } from "@/bin/config"; import yaml from "yaml"; import fs from "fs"; +import { revalidatePath } from "next/cache"; const config = yaml.parse(fs.readFileSync("config.yaml").toString()); export async function POST(req: Request) { @@ -47,6 +48,8 @@ export async function POST(req: Request) { maxAge: 60 * 60 * 24 * 7, }); + revalidatePath("/dev/home") + return NextResponse.json({ status: 200, data }); } diff --git a/src/app/dev/home/page.tsx b/src/app/dev/home/page.tsx index ce7a8440..98c88a72 100644 --- a/src/app/dev/home/page.tsx +++ b/src/app/dev/home/page.tsx @@ -4,22 +4,23 @@ import { unsealData } from "iron-session"; import _ from "lodash"; import { redirect } from "next/navigation"; +import yaml from "yaml"; +import fs from "fs"; +const config = yaml.parse(fs.readFileSync("config.yaml").toString()); + export default async function Page() { const c = cookies().get("ssn"); - // const tkn = !c - // ? null - // : JSON.parse( - // await unsealData(c.value as string, { - // password: process.env.PWD as string, - // }) - // ); - // if (!c?.value) return redirect("/dev/auth/login"); + if (!c?.value) return redirect("/dev/auth/login"); + const usr = JSON.parse( + await unsealData(c?.value as string, { + password: config.server.password, + }) + ); return ( <> - {/* {JSON.stringify(tkn)} */} - + ); } diff --git a/src/app/dev/katalog/view/page.tsx b/src/app/dev/katalog/view/page.tsx index 7d34f1a6..f4a3c15d 100644 --- a/src/app/dev/katalog/view/page.tsx +++ b/src/app/dev/katalog/view/page.tsx @@ -1,14 +1,33 @@ +import prisma from "@/app/lib/prisma"; import { loadListPortofolio } from "@/app_modules/katalog/portofolio/fun/fun_get_all_portofolio"; import { getProfile } from "@/app_modules/katalog/profile"; import { KatalogView } from "@/app_modules/katalog/view"; +import { url } from "inspector"; +import { unsealData } from "iron-session"; +import _, { get } from "lodash"; +import { cookies } from "next/headers"; +import { redirect } from "next/navigation"; +import { funGetUserProfile } from "@/app_modules/fun/get_user_profile"; +import yaml from "yaml"; +import fs from "fs"; +const config = yaml.parse(fs.readFileSync("config.yaml").toString()); export default async function Page() { const data = await getProfile(); - const listPorto = await loadListPortofolio(data?.id as string) + + const u = cookies().get("ssn"); + const usr = JSON.parse( + await unsealData(u?.value as string, { + password: config.server.password, + }) + ); + + const user = await funGetUserProfile(usr.id); + return ( <> {/* {JSON.stringify(data)} */} - + ); } diff --git a/src/app_modules/auth/validasi/view.tsx b/src/app_modules/auth/validasi/view.tsx index ff5b02db..f3ac68da 100644 --- a/src/app_modules/auth/validasi/view.tsx +++ b/src/app_modules/auth/validasi/view.tsx @@ -18,6 +18,7 @@ import { IconCircleLetterH } from "@tabler/icons-react"; import toast from "react-simple-toasts"; import { ApiHipmi } from "@/app/lib/api"; import { useRouter } from "next/navigation"; +import { funGetUserProfile } from "@/app_modules/fun/get_user_profile"; export default function Validasi() { const router = useRouter(); @@ -48,7 +49,8 @@ export default function Validasi() { myConsole(val); if (val.status == 200) { toast("Berhasil Login"); - return router.push("/dev/home"); + setTimeout(() => router.push("/dev/home"), 2000); + funGetUserProfile(val.data.id); } else { toast("Silahkan Registrasi"); return router.push("/dev/auth/register"); diff --git a/src/app_modules/fun/get_user_profile.ts b/src/app_modules/fun/get_user_profile.ts new file mode 100644 index 00000000..a96295a8 --- /dev/null +++ b/src/app_modules/fun/get_user_profile.ts @@ -0,0 +1,34 @@ +"use server"; +import prisma from "@/app/lib/prisma"; +import { revalidatePath } from "next/cache"; + +export async function funGetUserProfile(userId: string) { + const user = await prisma.user.findUnique({ + where: { + id: userId, + }, + select: { + id: true, + username: true, + nomor: true, + Profile: { + select: { + alamat: true, + email: true, + jenisKelamin: true, + name: true, + ImageProfile: { + select: { + url: true, + }, + }, + }, + }, + }, + }); + + revalidatePath("/dev/home"); + revalidatePath("/dev/katalog/view") + + return user; +} diff --git a/src/app_modules/home/view.tsx b/src/app_modules/home/view.tsx index c44594b9..f2a11035 100644 --- a/src/app_modules/home/view.tsx +++ b/src/app_modules/home/view.tsx @@ -45,6 +45,8 @@ import { gs_ListPortofolio } from "../katalog/portofolio/state/global_state"; import { myConsole } from "@/app/fun/my_console"; import { getFotoProfile } from "../katalog/profile/api/get-foto-profile"; import getListPortofolio from "../katalog/portofolio/api/get-portofolio"; +import { funGetUserProfile } from "../fun/get_user_profile"; +import { USER_PROFILE } from "../models/user_profile"; const listHalaman = [ { @@ -89,63 +91,43 @@ const listHalaman = [ }, ]; -export default function HomeView() { +// export const dynamic = "force-dynamic" +// export const revalidate = 0 + +export default function HomeView({ user }: { user: USER_PROFILE }) { const router = useRouter(); + const [stateUser, setStateUser] = useState(user); - const [token, setToken] = useAtom(gs_token); - useShallowEffect(() => { - getUserId(); - }, []); - async function getUserId() { - const get = await getToken(); - if(!get) return myConsole("Data Kosong") - setToken(get); - } - - const [profile, setProfile] = useAtom(gs_profile); - useShallowEffect(() => { - loadProfile(); - }, []); - async function loadProfile() { - const get = await getProfile(); - if(!get) return myConsole("Data Kosong") - setProfile(get); - } - - const [foto, setFoto] = useAtom(gs_fotoProfile); - useShallowEffect(() => { - getFoto(profile?.imagesId); - }, [profile?.imagesId]); - - async function getFoto(id: string) { - if(id === undefined){ - return myConsole("Waiting data") - } else { - const data = await getFotoProfile(id); - setFoto(data?.url); - } - } - - // const [listPorto, setListPorto] = useAtom(gs_ListPortofolio); + // const [token, setToken] = useAtom(gs_token); // useShallowEffect(() => { - // getListPorto(profile?.id); - // }, [profile?.id]); - // async function getListPorto(id: string) { - // const data = await getListPortofolio(id); - // setListPorto(data); + // getUserId(); + // }, []); + // async function getUserId() { + // const get = await getToken(); + // if (!get) return myConsole("Data Kosong"); + // setToken(get); + // } + + // const [profile, setProfile] = useAtom(gs_profile); + // useShallowEffect(() => { + // loadProfile(); + // }, []); + // async function loadProfile() { + // const get = await getProfile(); + // if (!get) return myConsole("Data Kosong"); + // setProfile(get); // } return ( <> - {/*
{JSON.stringify(foto, null, 2)}
*/} -
+ {/*
*/} { - if (profile === null) { + if (stateUser.Profile === null) { return router.push("/dev/katalog/profile/create"); } else { return router.push("/dev/katalog/view"); @@ -156,13 +138,17 @@ export default function HomeView() { - Welcome to I,{" "} - {token?.username ? token?.username : } + Welcome to ,{" "} + {stateUser.username ? stateUser.username : } + logo + + {/*
{JSON.stringify(stateUser, null, 2)}
*/} + {listHalaman.map((e, i) => ( diff --git a/src/app_modules/katalog/portofolio/list_view/view.tsx b/src/app_modules/katalog/portofolio/list_view/view.tsx index fec26322..3310c534 100644 --- a/src/app_modules/katalog/portofolio/list_view/view.tsx +++ b/src/app_modules/katalog/portofolio/list_view/view.tsx @@ -10,25 +10,24 @@ import { useAtom } from "jotai"; import { gs_profile } from "../../profile/state/global_state"; import getListPortofolio from "../api/get-portofolio"; import { gs_ListPortofolio } from "../state/global_state"; +import { myConsole } from "@/app/fun/my_console"; +import { getProfile } from "../../profile"; -export default function PortofolioView({ - profileId, - porto, -}: { - profileId: any; - porto: any; -}) { +export default function PortofolioView() { const [profile, setProfile] = useAtom(gs_profile); useShallowEffect(() => { - loadDataProfile(setProfile); + loadProfile(); }, []); - - const [listPorto, setListPorto] = useAtom(gs_ListPortofolio) + async function loadProfile() { + const get = await getProfile(); + if (!get) return myConsole("Data Kosong"); + setProfile(get); + } + const [listPorto, setListPorto] = useAtom(gs_ListPortofolio); useShallowEffect(() => { loadListPortofolio(profile?.id).then((res) => setListPorto(res)); }, [profile?.id]); - return ( <> {/* {JSON.stringify(profile.id)} @@ -37,13 +36,13 @@ export default function PortofolioView({
Portofolio
- + {(() => { if (listPorto) { return ( <> {_.map(listPorto).map((e: any) => ( - + {e.namaBisnis} diff --git a/src/app_modules/katalog/profile/view/view.tsx b/src/app_modules/katalog/profile/view/view.tsx index 3157037f..ede47bae 100644 --- a/src/app_modules/katalog/profile/view/view.tsx +++ b/src/app_modules/katalog/profile/view/view.tsx @@ -31,25 +31,39 @@ import { ApiHipmi } from "@/app/lib/api"; import { loadDataProfile } from "../fun/fun_get_profile"; import { getFotoProfile } from "../api/get-foto-profile"; import { gs_fotoProfile, gs_profile } from "../state/global_state"; +import { getProfile } from ".."; +import { USER_PROFILE } from "@/app_modules/models/user_profile"; +import { funGetUserProfile } from "@/app_modules/fun/get_user_profile"; -export default function ProfileView({ data }: { data: any }) { +export default function ProfileView({ user }: { user: USER_PROFILE }) { const router = useRouter(); + const [stateUser, setStateUser] = useState(user); //Get data profile const [profile, setProfile] = useAtom(gs_profile); useShallowEffect(() => { - loadDataProfile(setProfile); + loadProfile(); }, []); + async function loadProfile() { + const get = await getProfile(); + if (!get) return myConsole("Data Kosong"); + setProfile(get); + } const [foto, setFoto] = useAtom(gs_fotoProfile); - useShallowEffect(() => { - if (profile?.imagesId === undefined) { - return myConsole("Waiting data"); - } else { - getFotoProfile(profile?.imagesId).then((v) => setFoto(v?.url)); - } - }, [profile?.imagesId]); + // useShallowEffect(() => { + // if (profile?.imagesId === undefined) { + // return myConsole("Waiting data"); + // } else { + // getFotoProfile(profile?.imagesId).then((v) => setFoto(v?.url)); + // } + // }, [profile?.imagesId]); + useShallowEffect(() => { + funGetUserProfile(user.id ?? "").then(setStateUser as any); + }, []); + + if (!stateUser) return <>; return ( <> {/* {JSON.stringify(data)} */} @@ -74,18 +88,21 @@ export default function ProfileView({ data }: { data: any }) { }} >
- + /> + )}
diff --git a/src/app_modules/katalog/view/view.tsx b/src/app_modules/katalog/view/view.tsx index 36fd5ff1..ca406fae 100644 --- a/src/app_modules/katalog/view/view.tsx +++ b/src/app_modules/katalog/view/view.tsx @@ -33,13 +33,14 @@ import { loadDataProfile } from "../profile/fun/fun_get_profile"; import { getFotoProfile } from "../profile/api/get-foto-profile"; import { ApiHipmi } from "@/app/lib/api"; import { PortofolioView } from "../portofolio"; +import { User } from "@prisma/client"; +import { USER_PROFILE } from "@/app_modules/models/user_profile"; -export default function KatalogView({ data, porto }: { data: any, porto: any }) { +export default function KatalogView({ user }: { user: USER_PROFILE }) { return ( <> - - - + + ); } diff --git a/src/app_modules/models/user_profile.ts b/src/app_modules/models/user_profile.ts new file mode 100644 index 00000000..3c64585b --- /dev/null +++ b/src/app_modules/models/user_profile.ts @@ -0,0 +1,14 @@ +export interface USER_PROFILE { + id: string; + username: string; + nomor: string; + Profile: { + alamat: string; + email: string; + jenisKelamin: string; + name: string; + ImageProfile: { + url: string; + } | null; + } | null; +}