Desc:
- Penambahan function
- Perubahan tampilan
This commit is contained in:
2023-10-09 15:50:15 +08:00
parent 6281452441
commit ca66c3d2d8
12 changed files with 172 additions and 96 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

View File

@@ -6,6 +6,7 @@ import { sealData, unsealData } from "iron-session";
import { getConfig } from "@/bin/config"; import { getConfig } from "@/bin/config";
import yaml from "yaml"; import yaml from "yaml";
import fs from "fs"; import fs from "fs";
import { revalidatePath } from "next/cache";
const config = yaml.parse(fs.readFileSync("config.yaml").toString()); const config = yaml.parse(fs.readFileSync("config.yaml").toString());
export async function POST(req: Request) { export async function POST(req: Request) {
@@ -47,6 +48,8 @@ export async function POST(req: Request) {
maxAge: 60 * 60 * 24 * 7, maxAge: 60 * 60 * 24 * 7,
}); });
revalidatePath("/dev/home")
return NextResponse.json({ status: 200, data }); return NextResponse.json({ status: 200, data });
} }

View File

@@ -4,22 +4,23 @@ import { unsealData } from "iron-session";
import _ from "lodash"; import _ from "lodash";
import { redirect } from "next/navigation"; 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() { export default async function Page() {
const c = cookies().get("ssn"); 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 ( return (
<> <>
{/* {JSON.stringify(tkn)} */} <HomeView user={usr} />
<HomeView />
</> </>
); );
} }

View File

@@ -1,14 +1,33 @@
import prisma from "@/app/lib/prisma";
import { loadListPortofolio } from "@/app_modules/katalog/portofolio/fun/fun_get_all_portofolio"; import { loadListPortofolio } from "@/app_modules/katalog/portofolio/fun/fun_get_all_portofolio";
import { getProfile } from "@/app_modules/katalog/profile"; import { getProfile } from "@/app_modules/katalog/profile";
import { KatalogView } from "@/app_modules/katalog/view"; 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() { export default async function Page() {
const data = await getProfile(); 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 ( return (
<> <>
{/* {JSON.stringify(data)} */} {/* {JSON.stringify(data)} */}
<KatalogView data={data} porto={listPorto} /> <KatalogView user={user as any} />
</> </>
); );
} }

View File

@@ -18,6 +18,7 @@ import { IconCircleLetterH } from "@tabler/icons-react";
import toast from "react-simple-toasts"; import toast from "react-simple-toasts";
import { ApiHipmi } from "@/app/lib/api"; import { ApiHipmi } from "@/app/lib/api";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { funGetUserProfile } from "@/app_modules/fun/get_user_profile";
export default function Validasi() { export default function Validasi() {
const router = useRouter(); const router = useRouter();
@@ -48,7 +49,8 @@ export default function Validasi() {
myConsole(val); myConsole(val);
if (val.status == 200) { if (val.status == 200) {
toast("Berhasil Login"); toast("Berhasil Login");
return router.push("/dev/home"); setTimeout(() => router.push("/dev/home"), 2000);
funGetUserProfile(val.data.id);
} else { } else {
toast("Silahkan Registrasi"); toast("Silahkan Registrasi");
return router.push("/dev/auth/register"); return router.push("/dev/auth/register");

View File

@@ -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;
}

View File

@@ -45,6 +45,8 @@ import { gs_ListPortofolio } from "../katalog/portofolio/state/global_state";
import { myConsole } from "@/app/fun/my_console"; import { myConsole } from "@/app/fun/my_console";
import { getFotoProfile } from "../katalog/profile/api/get-foto-profile"; import { getFotoProfile } from "../katalog/profile/api/get-foto-profile";
import getListPortofolio from "../katalog/portofolio/api/get-portofolio"; import getListPortofolio from "../katalog/portofolio/api/get-portofolio";
import { funGetUserProfile } from "../fun/get_user_profile";
import { USER_PROFILE } from "../models/user_profile";
const listHalaman = [ 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 router = useRouter();
const [stateUser, setStateUser] = useState(user);
const [token, setToken] = useAtom(gs_token); // 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);
// useShallowEffect(() => { // useShallowEffect(() => {
// getListPorto(profile?.id); // getUserId();
// }, [profile?.id]); // }, []);
// async function getListPorto(id: string) { // async function getUserId() {
// const data = await getListPortofolio(id); // const get = await getToken();
// setListPorto(data); // 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 ( return (
<> <>
{/* <pre>{JSON.stringify(foto, null, 2)}</pre> */} {/* <Center><Image src={ApiHipmi.get_foto + foto ?? ""} alt="" height={100} width={100}/></Center> */}
<Center><Image src={ApiHipmi.get_foto + foto ?? ""} alt="" height={100} width={100}/></Center>
<Box> <Box>
<Flex align={"center"} gap={"sm"}> <Flex align={"center"} gap={"sm"}>
<ActionIcon <ActionIcon
size={30} size={30}
variant="transparent" variant="transparent"
onClick={() => { onClick={() => {
if (profile === null) { if (stateUser.Profile === null) {
return router.push("/dev/katalog/profile/create"); return router.push("/dev/katalog/profile/create");
} else { } else {
return router.push("/dev/katalog/view"); return router.push("/dev/katalog/view");
@@ -156,13 +138,17 @@ export default function HomeView() {
</ActionIcon> </ActionIcon>
<Text> <Text>
Welcome to I,{" "} Welcome to ,{" "}
{token?.username ? token?.username : <Loader size={"xs"} />} {stateUser.username ? stateUser.username : <Loader size={"xs"} />}
</Text> </Text>
</Flex> </Flex>
<Paper bg={"dark"} radius={5} my={"xs"}> <Paper bg={"dark"} radius={5} my={"xs"}>
<Image alt="logo" src={"/aset/logo.png"} /> <Image alt="logo" src={"/aset/logo.png"} />
</Paper> </Paper>
{/* <pre>{JSON.stringify(stateUser, null, 2)}</pre> */}
<Box my={"sm"}> <Box my={"sm"}>
<SimpleGrid cols={2}> <SimpleGrid cols={2}>
{listHalaman.map((e, i) => ( {listHalaman.map((e, i) => (

View File

@@ -10,25 +10,24 @@ import { useAtom } from "jotai";
import { gs_profile } from "../../profile/state/global_state"; import { gs_profile } from "../../profile/state/global_state";
import getListPortofolio from "../api/get-portofolio"; import getListPortofolio from "../api/get-portofolio";
import { gs_ListPortofolio } from "../state/global_state"; import { gs_ListPortofolio } from "../state/global_state";
import { myConsole } from "@/app/fun/my_console";
import { getProfile } from "../../profile";
export default function PortofolioView({ export default function PortofolioView() {
profileId,
porto,
}: {
profileId: any;
porto: any;
}) {
const [profile, setProfile] = useAtom(gs_profile); const [profile, setProfile] = useAtom(gs_profile);
useShallowEffect(() => { useShallowEffect(() => {
loadDataProfile(setProfile); loadProfile();
}, []); }, []);
async function loadProfile() {
const [listPorto, setListPorto] = useAtom(gs_ListPortofolio) const get = await getProfile();
if (!get) return myConsole("Data Kosong");
setProfile(get);
}
const [listPorto, setListPorto] = useAtom(gs_ListPortofolio);
useShallowEffect(() => { useShallowEffect(() => {
loadListPortofolio(profile?.id).then((res) => setListPorto(res)); loadListPortofolio(profile?.id).then((res) => setListPorto(res));
}, [profile?.id]); }, [profile?.id]);
return ( return (
<> <>
{/* {JSON.stringify(profile.id)} {/* {JSON.stringify(profile.id)}
@@ -37,13 +36,13 @@ export default function PortofolioView({
<Center> <Center>
<Title order={4}>Portofolio</Title> <Title order={4}>Portofolio</Title>
</Center> </Center>
<Box mt={"md"} > <Box mt={"md"}>
{(() => { {(() => {
if (listPorto) { if (listPorto) {
return ( return (
<> <>
{_.map(listPorto).map((e: any) => ( {_.map(listPorto).map((e: any) => (
<Paper key={e.id} h={50} bg={"gray"} my={"md"} > <Paper key={e.id} h={50} bg={"gray"} my={"md"}>
<Grid h={50} align="center" px={"md"}> <Grid h={50} align="center" px={"md"}>
<Grid.Col span={10}> <Grid.Col span={10}>
<Text fw={"bold"}>{e.namaBisnis}</Text> <Text fw={"bold"}>{e.namaBisnis}</Text>

View File

@@ -31,25 +31,39 @@ import { ApiHipmi } from "@/app/lib/api";
import { loadDataProfile } from "../fun/fun_get_profile"; import { loadDataProfile } from "../fun/fun_get_profile";
import { getFotoProfile } from "../api/get-foto-profile"; import { getFotoProfile } from "../api/get-foto-profile";
import { gs_fotoProfile, gs_profile } from "../state/global_state"; 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 router = useRouter();
const [stateUser, setStateUser] = useState(user);
//Get data profile //Get data profile
const [profile, setProfile] = useAtom(gs_profile); const [profile, setProfile] = useAtom(gs_profile);
useShallowEffect(() => { 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); const [foto, setFoto] = useAtom(gs_fotoProfile);
useShallowEffect(() => { // useShallowEffect(() => {
if (profile?.imagesId === undefined) { // if (profile?.imagesId === undefined) {
return myConsole("Waiting data"); // return myConsole("Waiting data");
} else { // } else {
getFotoProfile(profile?.imagesId).then((v) => setFoto(v?.url)); // getFotoProfile(profile?.imagesId).then((v) => setFoto(v?.url));
} // }
}, [profile?.imagesId]); // }, [profile?.imagesId]);
useShallowEffect(() => {
funGetUserProfile(user.id ?? "").then(setStateUser as any);
}, []);
if (!stateUser) return <></>;
return ( return (
<> <>
{/* {JSON.stringify(data)} */} {/* {JSON.stringify(data)} */}
@@ -74,18 +88,21 @@ export default function ProfileView({ data }: { data: any }) {
}} }}
> >
<Center h={101}> <Center h={101}>
<Image {/* {stateUser.Profile?.ImageProfile?.url} */}
src={ApiHipmi.get_foto + foto ?? ""} {stateUser.Profile?.ImageProfile?.url && (
alt="" <Image
radius={100} src={"/img/" + stateUser.Profile?.ImageProfile?.url}
width={100} alt=""
height={100} radius={100}
sx={ width={100}
{ height={100}
// position: "fixed", sx={
{
// position: "fixed",
}
} }
} />
/> )}
</Center> </Center>
</Paper> </Paper>
</Center> </Center>

View File

@@ -33,13 +33,14 @@ import { loadDataProfile } from "../profile/fun/fun_get_profile";
import { getFotoProfile } from "../profile/api/get-foto-profile"; import { getFotoProfile } from "../profile/api/get-foto-profile";
import { ApiHipmi } from "@/app/lib/api"; import { ApiHipmi } from "@/app/lib/api";
import { PortofolioView } from "../portofolio"; 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 ( return (
<> <>
<ProfileView user={user} />
<ProfileView data={data} /> <PortofolioView />
<PortofolioView profileId={data.id} porto={porto}/>
</> </>
); );
} }

View File

@@ -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;
}