fix
Desc: - Penambahan function - Perubahan tampilan
This commit is contained in:
BIN
public/img/2eef80a1-f811-4769-980a-63bfe97e1a6e.webp
Normal file
BIN
public/img/2eef80a1-f811-4769-980a-63bfe97e1a6e.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
BIN
public/img/68adba2f-db46-4074-82ea-7d2ea5f5bd35.png
Normal file
BIN
public/img/68adba2f-db46-4074-82ea-7d2ea5f5bd35.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 122 KiB |
@@ -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 });
|
||||
}
|
||||
|
||||
|
||||
@@ -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)} */}
|
||||
<HomeView />
|
||||
<HomeView user={usr} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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)} */}
|
||||
<KatalogView data={data} porto={listPorto} />
|
||||
<KatalogView user={user as any} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
34
src/app_modules/fun/get_user_profile.ts
Normal file
34
src/app_modules/fun/get_user_profile.ts
Normal 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;
|
||||
}
|
||||
@@ -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 (
|
||||
<>
|
||||
{/* <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>
|
||||
<Flex align={"center"} gap={"sm"}>
|
||||
<ActionIcon
|
||||
size={30}
|
||||
variant="transparent"
|
||||
onClick={() => {
|
||||
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() {
|
||||
</ActionIcon>
|
||||
|
||||
<Text>
|
||||
Welcome to I,{" "}
|
||||
{token?.username ? token?.username : <Loader size={"xs"} />}
|
||||
Welcome to ,{" "}
|
||||
{stateUser.username ? stateUser.username : <Loader size={"xs"} />}
|
||||
</Text>
|
||||
</Flex>
|
||||
|
||||
<Paper bg={"dark"} radius={5} my={"xs"}>
|
||||
<Image alt="logo" src={"/aset/logo.png"} />
|
||||
</Paper>
|
||||
|
||||
{/* <pre>{JSON.stringify(stateUser, null, 2)}</pre> */}
|
||||
|
||||
<Box my={"sm"}>
|
||||
<SimpleGrid cols={2}>
|
||||
{listHalaman.map((e, i) => (
|
||||
|
||||
@@ -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({
|
||||
<Center>
|
||||
<Title order={4}>Portofolio</Title>
|
||||
</Center>
|
||||
<Box mt={"md"} >
|
||||
<Box mt={"md"}>
|
||||
{(() => {
|
||||
if (listPorto) {
|
||||
return (
|
||||
<>
|
||||
{_.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.Col span={10}>
|
||||
<Text fw={"bold"}>{e.namaBisnis}</Text>
|
||||
|
||||
@@ -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 }) {
|
||||
}}
|
||||
>
|
||||
<Center h={101}>
|
||||
<Image
|
||||
src={ApiHipmi.get_foto + foto ?? ""}
|
||||
alt=""
|
||||
radius={100}
|
||||
width={100}
|
||||
height={100}
|
||||
sx={
|
||||
{
|
||||
// position: "fixed",
|
||||
{/* {stateUser.Profile?.ImageProfile?.url} */}
|
||||
{stateUser.Profile?.ImageProfile?.url && (
|
||||
<Image
|
||||
src={"/img/" + stateUser.Profile?.ImageProfile?.url}
|
||||
alt=""
|
||||
radius={100}
|
||||
width={100}
|
||||
height={100}
|
||||
sx={
|
||||
{
|
||||
// position: "fixed",
|
||||
}
|
||||
}
|
||||
}
|
||||
/>
|
||||
/>
|
||||
)}
|
||||
</Center>
|
||||
</Paper>
|
||||
</Center>
|
||||
|
||||
@@ -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 (
|
||||
<>
|
||||
|
||||
<ProfileView data={data} />
|
||||
<PortofolioView profileId={data.id} porto={porto}/>
|
||||
<ProfileView user={user} />
|
||||
<PortofolioView />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
14
src/app_modules/models/user_profile.ts
Normal file
14
src/app_modules/models/user_profile.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user