Desc:
- Perubahan tampilan
- Penambahan function
This commit is contained in:
2023-10-04 14:21:04 +08:00
parent 9b327f8bff
commit 286f7fabb1
7 changed files with 346 additions and 11 deletions

View File

@@ -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 EditProfileLayout({ children }: { children: any }) {
const router = useRouter()
return (
<>
<AppShell
header={
<Header height={50} px={"sm"}>
<Group position="apart" h={50}>
<ActionIcon variant="transparent" onClick={() => router.push("/dev/katalog/view")}>
<IconArrowLeft />
</ActionIcon>
<Text>Edit Profile</Text>
<ActionIcon variant="transparent"></ActionIcon>
</Group>
</Header>
}
>
{children}
</AppShell>
</>
);
}

View File

@@ -0,0 +1,122 @@
"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 { useShallowEffect } from "@mantine/hooks";
import { useAtom } from "jotai";
import _ from "lodash";
import { useRouter } from "next/navigation";
import { useState } from "react";
import toast from "react-simple-toasts";
import { gs_profile } from "../state/global_state";
import { g_getProfile } from "../fun/fun-get-profile";
export default function EditProfile({ data }: { data: any }) {
const router = useRouter();
//Get data profile
const [profile, setProfile] = useAtom(gs_profile);
useShallowEffect(() => {
g_getProfile(setProfile);
}, []);
async function onUpdate() {
const body = profile;
if (_.values(body).includes("")) return toast("Lengkapi data");
await fetch(ApiHipmi.edit_profile, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
})
.then((res) => res.json())
.then((val) => {
myConsole(val);
if (val.status == 200) {
toast("Data tersimpan");
return router.push("/dev/katalog/view");
} else {
return toast("Gagal update !!!");
}
});
}
return (
<>
{/* {JSON.stringify(profile)} */}
<Stack px={"sm"}>
<TextInput label="Username" disabled value={data.User.username} />
<TextInput label="Nomor" disabled value={data.User.nomor} />
<TextInput
label="Nama"
placeholder="username"
value={profile.name}
onChange={(val) => {
setProfile({
...profile,
name: val.target.value,
});
}}
/>
<TextInput
label="Email"
placeholder="email"
value={profile.email}
onChange={(val) => {
myConsole(val.target.value);
setProfile({
...profile,
email: val.target.value,
});
}}
/>
<TextInput
label="Alamat"
placeholder="alamat"
value={profile.alamat}
onChange={(val) => {
myConsole(val.target.value);
setProfile({
...profile,
alamat: val.target.value,
});
}}
/>
<Select
label="Jenis Kelamin"
value={profile.jenisKelamin}
data={[
{ value: "Laki-laki", label: "Laki-laki" },
{ value: "Perempuan", label: "Perempuan" },
]}
onChange={(val) => {
setProfile({
...profile,
jenisKelamin: val as string,
});
}}
/>
<Button
mt={"md"}
radius={50}
bg={Warna.biru}
color="cyan"
onClick={() => onUpdate()}
>
Update
</Button>
</Stack>
</>
);
}

View File

@@ -5,6 +5,11 @@ import prisma from "@/app/lib/prisma";
import { getToken } from "@/app_modules/home";
import { NextResponse } from "next/server";
/**
* @function api get data profile by user id
* @returns data profile
*/
export async function getProfile() {
const token = await getToken();
@@ -26,6 +31,12 @@ export async function getProfile() {
active: true,
},
},
User: {
select : {
username: true,
nomor: true
}
}
},
});

View File

@@ -0,0 +1,11 @@
import { getProfile } from "..";
/**
* @function get data profile
* @param setProfile
* @returns data profile
*/
export async function g_getProfile(setProfile: any) {
const data = await getProfile().then((res) => res);
setProfile(data)
}

View File

@@ -1,4 +1,8 @@
import ProfileLayout from "./create/layout";
import CreateProfile from "./create/view";
import {getProfile} from "./fun/get-profile";
export {ProfileLayout, CreateProfile, getProfile}
import {getProfile} from "./fun/api-get-profile";
import EditProfileLayout from './edit/layout';
import EditProfileView from './edit/view'
export {ProfileLayout, CreateProfile, getProfile, EditProfileView, EditProfileLayout}

View File

@@ -0,0 +1,6 @@
import { atomWithStorage } from "jotai/utils";
import { getProfile } from "..";
export const gs_profile = atomWithStorage<any | null>("gs_profile", null);