fix create profile

This commit is contained in:
2025-06-16 17:54:46 +08:00
parent 48baf26ead
commit 6c612a5bf6

View File

@@ -1,15 +1,21 @@
"use client"; "use client";
import { MainColor } from "@/app_modules/_global/color"; import { MainColor } from "@/app_modules/_global/color";
import { ComponentGlobal_ErrorInput } from "@/app_modules/_global/component"; import {
ComponentGlobal_BoxInformation,
ComponentGlobal_ErrorInput,
} from "@/app_modules/_global/component";
import { apiNewGetUserIdByToken } from "@/app_modules/_global/lib/api_fetch_global";
import { apiGetUserById } from "@/app_modules/_global/lib/api_user";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { Select, Stack, TextInput } from "@mantine/core"; import { Select, Stack, TextInput } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import { IconAt } from "@tabler/icons-react"; import { IconAt } from "@tabler/icons-react";
import { useState } from "react"; import { useState } from "react";
import { emailRegex } from "../../component/regular_expressions"; import { emailRegex } from "../../component/regular_expressions";
import { Profile_ComponentCreateNewProfile } from "../_component"; import { Profile_ComponentCreateNewProfile } from "../_component";
import Profile_ViewUploadBackground from "./view_upload_background"; import Profile_ViewUploadBackground from "./view_upload_background";
import Profile_ViewUploadFoto from "./view_upload_foto"; import Profile_ViewUploadFoto from "./view_upload_foto";
import { masterJenisKelamin } from "@/app_modules/_global/lib/master_jenis_kelamin";
export default function CreateProfile() { export default function CreateProfile() {
const [filePP, setFilePP] = useState<File | null>(null); const [filePP, setFilePP] = useState<File | null>(null);
@@ -24,8 +30,43 @@ export default function CreateProfile() {
jenisKelamin: "", jenisKelamin: "",
}); });
const [userLoginId, setUserLoginId] = useState<any | null>();
const [dataProfile, setDataProfile] = useState<any | null>();
// const router = useRouter();
useShallowEffect(() => {
handleGetUserLoginId();
}, []);
async function handleGetUserLoginId() {
try {
const response = await apiNewGetUserIdByToken();
if (response.success) {
// console.log("response", response);
setUserLoginId(response.userId);
const responseProfile = await apiGetUserById({
id: response.userId,
});
// console.log("responseProfile", responseProfile?.data);
if (responseProfile?.success) {
setDataProfile(responseProfile?.data);
}
}
} catch (error) {
console.log("Error get user login id", error);
}
}
// console.log("userLoginId", userLoginId);
// console.log("dataProfile", dataProfile);
if (!dataProfile) return <CustomSkeleton height={400} />;
return ( return (
<> <>
{dataProfile?.Profile ? (
<ComponentGlobal_BoxInformation informasi="Anda telah memiliki Profile, Kembali ke Home" />
) : (
<Stack px={"sm"} spacing={40}> <Stack px={"sm"} spacing={40}>
<Profile_ViewUploadFoto <Profile_ViewUploadFoto
imgPP={imgPP} imgPP={imgPP}
@@ -131,6 +172,7 @@ export default function CreateProfile() {
/> />
</Stack> </Stack>
</Stack> </Stack>
)}
</> </>
); );
} }