fix
Desc: - Perubahan metode pengambilan data dari API ke use server
This commit is contained in:
BIN
public/img/77a5d35a-5bc0-46ca-857d-c4008c3a2f44.png
Normal file
BIN
public/img/77a5d35a-5bc0-46ca-857d-c4008c3a2f44.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 94 KiB |
BIN
public/img/f8e8f088-441a-4b7c-b081-7c2695399c09.jpeg
Normal file
BIN
public/img/f8e8f088-441a-4b7c-b081-7c2695399c09.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
@@ -1,9 +0,0 @@
|
||||
import { UploadFotoProfile } from "@/app_modules/katalog/profile";
|
||||
|
||||
export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<UploadFotoProfile />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { KatalogLayout } from "@/app_modules/katalog/view";
|
||||
import { KatalogLayout } from "@/app_modules/katalog/main";
|
||||
|
||||
export default async function Layout({ children }: { children: any }) {
|
||||
return (
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
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 { KatalogView } from "@/app_modules/katalog/main";
|
||||
import { url } from "inspector";
|
||||
import { unsealData } from "iron-session";
|
||||
import _, { get } from "lodash";
|
||||
import _ 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";
|
||||
import { funGetListPortofolio } from "@/app_modules/katalog/portofolio/fun/get_list_portofolio";
|
||||
const config = yaml.parse(fs.readFileSync("config.yaml").toString());
|
||||
|
||||
export default async function Page() {
|
||||
const data = await getProfile();
|
||||
|
||||
|
||||
const u = cookies().get("ssn");
|
||||
const usr = JSON.parse(
|
||||
await unsealData(u?.value as string, {
|
||||
@@ -24,10 +24,11 @@ export default async function Page() {
|
||||
|
||||
const user = await funGetUserProfile(usr.id);
|
||||
|
||||
const listPorto = await funGetListPortofolio(user?.Profile?.id)
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* {JSON.stringify(data)} */}
|
||||
<KatalogView user={user as any} />
|
||||
<KatalogView user={user as any} listPorto={listPorto as any} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { myConsole } from "@/app/fun/my_console";
|
||||
import { CreatePortofolio } from "@/app_modules/katalog/portofolio";
|
||||
import { getBidangBisnis } from "@/app_modules/katalog/portofolio/api/get-bidang-bisnis";
|
||||
import { getBidangBisnis } from "@/app_modules/katalog/portofolio/fun/get_list_bidang_bisnis";
|
||||
import { getProfile } from "@/app_modules/katalog/profile";
|
||||
|
||||
export default async function Page() {
|
||||
@@ -10,7 +10,6 @@ export default async function Page() {
|
||||
|
||||
return (
|
||||
<>
|
||||
{JSON.stringify(profileId)}
|
||||
<CreatePortofolio data={bidangBisnis} profileId={profileId} />
|
||||
</>
|
||||
);
|
||||
29
src/app/dev/profile/upload/page.tsx
Normal file
29
src/app/dev/profile/upload/page.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { UploadFotoProfile } from "@/app_modules/katalog/profile";
|
||||
import { unsealData } from "iron-session";
|
||||
import { cookies } from "next/headers";
|
||||
import yaml from "yaml";
|
||||
import fs from "fs";
|
||||
import { funGetUserProfile } from "@/app_modules/fun/get_user_profile";
|
||||
const config = yaml.parse(fs.readFileSync("config.yaml").toString());
|
||||
|
||||
|
||||
export default async function Page() {
|
||||
const c = cookies().get("ssn")
|
||||
const usr = JSON.parse(
|
||||
await unsealData(c?.value as string, {
|
||||
password: config.server.password,
|
||||
})
|
||||
);
|
||||
|
||||
console.log(usr)
|
||||
|
||||
const imageUrl = await funGetUserProfile(usr.id).then((res) => res?.Profile?.ImageProfile?.url)
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
<UploadFotoProfile imageUrl={imageUrl} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -13,6 +13,7 @@ export async function funGetUserProfile(userId: string) {
|
||||
nomor: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
alamat: true,
|
||||
email: true,
|
||||
jenisKelamin: true,
|
||||
|
||||
@@ -40,11 +40,9 @@ import {
|
||||
gs_fotoProfile,
|
||||
gs_profile,
|
||||
} from "../katalog/profile/state/global_state";
|
||||
import { loadListPortofolio } from "../katalog/portofolio/fun/fun_get_all_portofolio";
|
||||
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";
|
||||
|
||||
@@ -128,7 +126,7 @@ export default function HomeView({ user }: { user: USER_PROFILE }) {
|
||||
variant="transparent"
|
||||
onClick={() => {
|
||||
if (stateUser.Profile === null) {
|
||||
return router.push("/dev/katalog/profile/create");
|
||||
return router.push("/dev/profile/create");
|
||||
} else {
|
||||
return router.push("/dev/katalog/view");
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export default function KatalogLayout({ children }: { children: any }) {
|
||||
Katalog
|
||||
</Text>
|
||||
<Group spacing={"sm"}>
|
||||
<ActionIcon variant="transparent" onClick={() => router.push("/dev/katalog/portofolio/create")}>
|
||||
<ActionIcon variant="transparent" onClick={() => router.push("/dev/portofolio/create")}>
|
||||
<IconPencilPlus />
|
||||
</ActionIcon>
|
||||
{/* <Logout /> */}
|
||||
@@ -32,15 +32,16 @@ import { useAtom } from "jotai";
|
||||
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 { ListPortofolioView } from "../portofolio";
|
||||
import { User } from "@prisma/client";
|
||||
import { USER_PROFILE } from "@/app_modules/models/user_profile";
|
||||
import { LIST_PORTOFOLIO } from "@/app_modules/models/portofolio";
|
||||
|
||||
export default function KatalogView({ user }: { user: USER_PROFILE }) {
|
||||
export default function KatalogView({ user, listPorto }: { user: USER_PROFILE, listPorto: LIST_PORTOFOLIO }) {
|
||||
return (
|
||||
<>
|
||||
<ProfileView user={user} />
|
||||
<PortofolioView />
|
||||
<ListPortofolioView listPorto={listPorto} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ export default function CreatePortofolio({
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* {JSON.stringify(data)} */}
|
||||
|
||||
<Stack px={"sm"}>
|
||||
<TextInput
|
||||
label="Nama Bisnis"
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import toast from "react-simple-toasts";
|
||||
import getListPortofolio from "../api/get-portofolio";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id - profileId
|
||||
* @returns load list portofolio by Id
|
||||
*/
|
||||
export async function loadListPortofolio(id: string) {
|
||||
if (id === null) {
|
||||
return toast("Id null");
|
||||
} else {
|
||||
const data = await getListPortofolio(id).then((res) => res);
|
||||
return data
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,11 @@
|
||||
"use server";
|
||||
|
||||
import { myConsole } from "@/app/fun/my_console";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id - profileId
|
||||
* @returns list portofolio by Id
|
||||
*/
|
||||
export default async function getListPortofolio(id: string) {
|
||||
// myConsole(id);
|
||||
|
||||
export async function funGetListPortofolio(profileId: any) {
|
||||
const data = await prisma.katalog.findMany({
|
||||
where: {
|
||||
profileId: id,
|
||||
profileId: profileId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -21,14 +13,10 @@ export default async function getListPortofolio(id: string) {
|
||||
alamatKantor: true,
|
||||
tlpn: true,
|
||||
deskripssi: true,
|
||||
active: true,
|
||||
masterBidangBisnisId: true,
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
throw new Error("Failed to fetch data");
|
||||
}
|
||||
|
||||
return data;
|
||||
return data
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import CreatePortofolio from "./create/view";
|
||||
import PortofolioLayout from "./create/layout";
|
||||
import PortofolioView from "./list_view/view";
|
||||
import ListPortofolioView from "./list_view/view";
|
||||
|
||||
export {CreatePortofolio, PortofolioLayout, PortofolioView}
|
||||
export {CreatePortofolio, PortofolioLayout, ListPortofolioView}
|
||||
@@ -2,46 +2,36 @@
|
||||
import { Box, Center, Grid, Paper, Text, Title } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useState } from "react";
|
||||
import { loadListPortofolio } from "../fun/fun_get_all_portofolio";
|
||||
import _ from "lodash";
|
||||
import { IconCaretRightFilled } from "@tabler/icons-react";
|
||||
import { loadDataProfile } from "../../profile/fun/fun_get_profile";
|
||||
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";
|
||||
import { LIST_PORTOFOLIO } from "@/app_modules/models/portofolio";
|
||||
|
||||
export default function PortofolioView() {
|
||||
const [profile, setProfile] = useAtom(gs_profile);
|
||||
useShallowEffect(() => {
|
||||
loadProfile();
|
||||
}, []);
|
||||
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]);
|
||||
export default function ListPortofolioView({
|
||||
listPorto,
|
||||
}: {
|
||||
listPorto: LIST_PORTOFOLIO;
|
||||
}) {
|
||||
const [porto, setPorto] = useState(listPorto);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* {JSON.stringify(profile.id)}
|
||||
<br />
|
||||
{JSON.stringify(listPorto)} */}
|
||||
{/* <pre>{JSON.stringify(porto, null, 2)}</pre> */}
|
||||
<Center>
|
||||
<Title order={4}>Portofolio</Title>
|
||||
</Center>
|
||||
<Box mt={"md"}>
|
||||
{(() => {
|
||||
if (listPorto) {
|
||||
if (porto) {
|
||||
return (
|
||||
<>
|
||||
{_.map(listPorto).map((e: any) => (
|
||||
{" "}
|
||||
{_.map(porto as any).map((e: any) => (
|
||||
<Paper key={e.id} h={50} bg={"gray"} my={"md"}>
|
||||
<Grid h={50} align="center" px={"md"}>
|
||||
<Grid.Col span={10}>
|
||||
|
||||
@@ -5,7 +5,7 @@ import EditProfileLayout from "./edit/layout";
|
||||
import EditProfileView from "./edit/view";
|
||||
import UploadFotoProfile from "./upload/view";
|
||||
import UploadFotoProfileLayout from "./upload/layout"
|
||||
import ProfileView from "./view/view";
|
||||
import ProfileView from "./main/view";
|
||||
|
||||
export {
|
||||
ProfileLayout,
|
||||
|
||||
@@ -38,27 +38,6 @@ import { funGetUserProfile } from "@/app_modules/fun/get_user_profile";
|
||||
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(() => {
|
||||
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(() => {
|
||||
funGetUserProfile(user.id ?? "").then(setStateUser as any);
|
||||
}, []);
|
||||
@@ -114,7 +93,7 @@ export default function ProfileView({ user }: { user: USER_PROFILE }) {
|
||||
variant="transparent"
|
||||
bg={"gray"}
|
||||
radius={50}
|
||||
onClick={() => router.push("/dev/katalog/profile/upload")}
|
||||
onClick={() => router.push("/dev/profile/upload")}
|
||||
sx={{ position: "relative" }}
|
||||
>
|
||||
<IconCamera color="black" size={20} />
|
||||
@@ -126,14 +105,14 @@ export default function ProfileView({ user }: { user: USER_PROFILE }) {
|
||||
<Group position="apart">
|
||||
<Flex direction={"column"} mt={"lg"}>
|
||||
<Text fz={"lg"} fw={"bold"}>
|
||||
{profile?.name}
|
||||
{stateUser.Profile?.name}
|
||||
</Text>
|
||||
<Text fz={"xs"}>@{profile?.User?.username}</Text>
|
||||
<Text fz={"xs"}>@{stateUser.username}</Text>
|
||||
</Flex>
|
||||
<ActionIcon
|
||||
variant="transparent"
|
||||
onClick={() => {
|
||||
router.push("/dev/katalog/profile/edit");
|
||||
router.push("/dev/profile/edit");
|
||||
}}
|
||||
>
|
||||
<IconEditCircle color={Warna.hijau_muda} size={20} />
|
||||
@@ -149,7 +128,7 @@ export default function ProfileView({ user }: { user: USER_PROFILE }) {
|
||||
<Grid.Col span={"auto"}>
|
||||
<Text>
|
||||
{" "}
|
||||
<Text>+{profile?.User.nomor}</Text>
|
||||
<Text>+{stateUser.nomor}</Text>
|
||||
</Text>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
@@ -161,7 +140,7 @@ export default function ProfileView({ user }: { user: USER_PROFILE }) {
|
||||
<Grid.Col span={"auto"}>
|
||||
<Text>
|
||||
{" "}
|
||||
<Text> {profile?.email}</Text>
|
||||
<Text> {stateUser.Profile?.email}</Text>
|
||||
</Text>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
@@ -171,12 +150,12 @@ export default function ProfileView({ user }: { user: USER_PROFILE }) {
|
||||
<IconHome />
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Text> {profile?.alamat}</Text>
|
||||
<Text> {stateUser.Profile?.alamat}</Text>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
|
||||
{(() => {
|
||||
if (profile?.jenisKelamin === "Laki - laki") {
|
||||
if (stateUser.Profile?.jenisKelamin === "Laki - laki") {
|
||||
return (
|
||||
<>
|
||||
<Grid>
|
||||
@@ -184,7 +163,7 @@ export default function ProfileView({ user }: { user: USER_PROFILE }) {
|
||||
<IconGenderMale />
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Text> {profile?.jenisKelamin}</Text>
|
||||
<Text> {stateUser.Profile?.jenisKelamin}</Text>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</>
|
||||
@@ -197,7 +176,7 @@ export default function ProfileView({ user }: { user: USER_PROFILE }) {
|
||||
<IconGenderFemale />
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Text> {profile?.jenisKelamin}</Text>
|
||||
<Text> {stateUser.Profile?.jenisKelamin}</Text>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</>
|
||||
@@ -10,27 +10,15 @@ import { useState } from "react";
|
||||
import { ApiHipmi } from "@/app/lib/api";
|
||||
import { myConsole } from "@/app/fun/my_console";
|
||||
|
||||
export default function UploadFotoProfile() {
|
||||
const [profile, setProfile] = useAtom(gs_profile);
|
||||
useShallowEffect(() => {
|
||||
loadDataProfile(setProfile);
|
||||
}, []);
|
||||
|
||||
const [foto, setFoto] = useAtom(gs_fotoProfile)
|
||||
useShallowEffect(() => {
|
||||
if (profile?.imagesId === undefined || profile?.imagesId === null) {
|
||||
myConsole("Waiting data");
|
||||
} else {
|
||||
getFotoProfile(profile?.imagesId).then((res) => setFoto(res?.url));
|
||||
}
|
||||
}, [profile?.imagesId]);
|
||||
export default function UploadFotoProfile({imageUrl}: {imageUrl: any}) {
|
||||
const [img, setImg] = useState(imageUrl)
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* {JSON.stringify(foto)} */}
|
||||
<AspectRatio ratio={1 / 1} >
|
||||
<Paper p={"lg"} shadow="xl">
|
||||
{foto ? <Image alt="" src={ApiHipmi.get_foto + `${foto}`} /> : <Image alt="" src={"/aset/avatar.png"} />}
|
||||
{img ? <Image alt="" src={`/img/${img}`} /> : <Image alt="" src={"/aset/avatar.png"} />}
|
||||
</Paper>
|
||||
</AspectRatio>
|
||||
{/* {JSON.stringify(profile)} */}
|
||||
|
||||
9
src/app_modules/models/portofolio.ts
Normal file
9
src/app_modules/models/portofolio.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface LIST_PORTOFOLIO {
|
||||
id: string;
|
||||
namaBisnis: string;
|
||||
alamatKantor: string;
|
||||
tlpn: string;
|
||||
deskripssi: string;
|
||||
masterBidangBisnisId: string;
|
||||
active: boolean;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ export interface USER_PROFILE {
|
||||
username: string;
|
||||
nomor: string;
|
||||
Profile: {
|
||||
id: string;
|
||||
alamat: string;
|
||||
email: string;
|
||||
jenisKelamin: string;
|
||||
|
||||
Reference in New Issue
Block a user