Merge pull request #278 from bipproduction/bagas/5-feb-25

Bagas/5 feb 25
This commit is contained in:
Bagasbanuna02
2025-02-05 17:53:56 +08:00
committed by GitHub
59 changed files with 917 additions and 1547 deletions

View File

@@ -1,7 +1,7 @@
"use server";
import { cookies } from "next/headers";
import { decrypt } from "../../../../app/auth/_lib/decrypt";
import { decrypt } from "../../../../app/(auth)/_lib/decrypt";
export async function funGetUserIdByToken() {
const SESSION_KEY = process.env.NEXT_PUBLIC_BASE_SESSION_KEY!;

View File

@@ -3,6 +3,7 @@ export {
apiGetCheckCodeOtp,
apiPostVerifikasiCodeOtp,
apiDeleteAktivasiKodeOtpByNomor,
apiFetchRegister,
};
const apiFetchLogin = async ({ nomor }: { nomor: string }) => {
@@ -35,14 +36,38 @@ const apiPostVerifikasiCodeOtp = async ({ nomor }: { nomor: string }) => {
return await respone.json().catch(() => null);
};
const apiDeleteAktivasiKodeOtpByNomor = async ({
nomor,
}: {
nomor: string;
}) => {
const respone = await fetch(`/api/auth/delete/${nomor}`, {
const apiDeleteAktivasiKodeOtpByNomor = async ({ id }: { id: string }) => {
const respone = await fetch(`/api/auth/code/${id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
});
return await respone.json().catch(() => null);
};
const apiFetchRegister = async ({
nomor,
username,
}: {
nomor: string;
username: string;
}) => {
const data = {
username: username,
nomor: nomor,
};
const respone = await fetch("/api/auth/register", {
method: "POST",
body: JSON.stringify({ data }),
headers: {
"Content-Type": "application/json",
},
});
const result = await respone.json();
return result;
// return await respone.json().catch(() => null);
};

View File

@@ -14,8 +14,13 @@ import { useState } from "react";
import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id";
import Register_SkeletonView from "./skeleton";
import { clientLogger } from "@/util/clientLogger";
import { apiGetCheckCodeOtp } from "../_lib/api_fetch_auth";
import {
apiDeleteAktivasiKodeOtpByNomor,
apiFetchRegister,
apiGetCheckCodeOtp,
} from "../_lib/api_fetch_auth";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global";
export default function Register() {
const router = useRouter();
@@ -24,82 +29,52 @@ export default function Register() {
const [isValue, setIsValue] = useState(false);
const focusTrapRef = useFocusTrap();
const [loading, setLoading] = useState(false);
const [idCode, setIdCode] = useState("");
useShallowEffect(() => {
const kodeId = localStorage.getItem("hipmi_auth_code_id");
if (kodeId != null) {
onCheckAuthCode({ kodeId: kodeId as string, onSetData: setNomor });
onCheckAuthCode({ kodeId: kodeId as string });
} else {
console.log("code id not found");
}
}, [setNomor]);
}, []);
async function onCheckAuthCode({
kodeId,
onSetData,
}: {
kodeId: string;
onSetData: any;
}) {
async function onCheckAuthCode({ kodeId }: { kodeId: string }) {
try {
const respone = await apiGetCheckCodeOtp({ id: kodeId });
if (respone) {
onSetData(respone.nomor);
setIdCode(kodeId);
setNomor(respone.nomor);
}
} catch (error) {
clientLogger.error("Error onCheckAuthCode:", error);
}
// const res = await fetch(`/api/auth/check?id=${kodeId}`);
// const result = await res.json();
}
async function onRegistarsi() {
const data = {
username: value,
nomor: nomor,
};
try {
setLoading(true);
const res = await fetch("/api/auth/register", {
method: "POST",
body: JSON.stringify({
data,
}),
headers: {
"Content-Type": "application/json",
},
});
const result = await res.json();
if (res.status === 200) {
ComponentGlobal_NotifikasiBerhasil(result.message);
localStorage.removeItem("hipmi_auth_code_id");
await auth_funDeleteAktivasiKodeOtpByNomor({
nomor: data.nomor,
});
const respone = await apiFetchRegister({ nomor: nomor, username: value });
if (respone.success) {
router.push("/waiting-room", { scroll: false });
return;
}
ComponentGlobal_NotifikasiBerhasil(respone.message);
if (res.status === 400) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
}
try {
const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({
id: idCode,
});
if (res.status === 405) {
if (responeDelete) {
localStorage.removeItem("hipmi_auth_code_id");
}
} catch (error) {
clientLogger.error("Error apiDeleteAktivasiKodeOtpByNomor:", error);
}
} else {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
}
if (res.status === 500) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
ComponentGlobal_NotifikasiPeringatan(respone.message);
}
} catch (error) {
setLoading(false);
@@ -162,6 +137,7 @@ export default function Register() {
value.length < 5 ||
_.values(value).includes(" ")
}
style={{ transition: "0.5s" }}
loading={loading ? true : false}
loaderPosition="center"
radius={"md"}

View File

@@ -1,7 +1,6 @@
"use client";
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
import {
AccentColor,
MainColor,
@@ -26,12 +25,9 @@ import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global";
import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id";
import Validasi_SkeletonView from "./skeleton";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { clientLogger } from "@/util/clientLogger";
import { IconChevronLeft } from "@tabler/icons-react";
import _ from "lodash";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import {
apiDeleteAktivasiKodeOtpByNomor,
apiGetCheckCodeOtp,
@@ -46,6 +42,7 @@ export default function Validasi() {
const [counter, setCounter] = useState(60);
const [loadingResend, setLoadingResend] = useState(false);
const [triggerOtp, setTriggerOtp] = useState(false);
const [idCode, setIdCode] = useState("");
const [data, setData] = useState({
nomor: "",
@@ -74,7 +71,9 @@ export default function Validasi() {
async function onCheckAuthCode({ kodeId }: { kodeId: string }) {
try {
const respone = await apiGetCheckCodeOtp({ id: kodeId });
if (respone) {
setIdCode(kodeId);
setData({
nomor: respone.nomor,
code: respone.otp,
@@ -101,21 +100,21 @@ export default function Validasi() {
if (respone && respone.success == true) {
if (respone.roleId == "1") {
router.push("/login", { scroll: false });
ComponentGlobal_NotifikasiBerhasil(respone.message);
localStorage.removeItem("hipmi_auth_code_id");
router.push(RouterHome.main_home, { scroll: false });
} else if (respone.roleId != "1") {
ComponentGlobal_NotifikasiBerhasil("Admin berhasil login");
localStorage.removeItem("hipmi_auth_code_id");
router.push(RouterAdminDashboard.splash_admin, { scroll: false });
ComponentGlobal_NotifikasiBerhasil("Admin berhasil login");
}
try {
const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({
nomor: data.nomor,
id: idCode,
});
if (responeDelete) {
localStorage.removeItem("hipmi_auth_code_id");
}
} catch (error) {
clientLogger.error("Error apiDeleteAktivasiKodeOtpByNomor:", error);
}
@@ -123,47 +122,6 @@ export default function Validasi() {
router.push("/register", { scroll: false });
ComponentGlobal_NotifikasiBerhasil(respone.message);
}
// if (respone.status === 200 && result.roleId == "1") {
// ComponentGlobal_NotifikasiBerhasil(result.message);
// localStorage.removeItem("hipmi_auth_code_id");
// await auth_funDeleteAktivasiKodeOtpByNomor({
// nomor: data.nomor,
// });
// router.push(RouterHome.main_home, { scroll: false });
// return;
// }
// if (respone.status === 200 && result.roleId != "1") {
// ComponentGlobal_NotifikasiBerhasil("Admin Logged in");
// localStorage.removeItem("hipmi_auth_code_id");
// await auth_funDeleteAktivasiKodeOtpByNomor({
// nomor: data.nomor,
// });
// router.push(RouterAdminDashboard.splash_admin, { scroll: false });
// return;
// }
// if (respone.status === 404) {
// setLoading(false);
// router.push("/register", { scroll: false });
// ComponentGlobal_NotifikasiBerhasil(result.message);
// return;
// }
// if (respone.status === 400) {
// setLoading(false);
// ComponentGlobal_NotifikasiPeringatan(result.message);
// return;
// }
// if (respone.status == 500) {
// setLoading(false);
// ComponentGlobal_NotifikasiGagal(result.message);
// return;
// }
} catch (error) {
setLoading(false);
clientLogger.error("Error validasi:", error);
@@ -171,9 +129,18 @@ export default function Validasi() {
}
async function onBack() {
localStorage.removeItem("hipmi_auth_code_id");
await auth_funDeleteAktivasiKodeOtpByNomor({ nomor: data.nomor });
router.back();
try {
router.back();
const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({
id: idCode,
});
if (responeDelete) {
localStorage.removeItem("hipmi_auth_code_id");
}
} catch (error) {
clientLogger.error("Error apiDeleteAktivasiKodeOtpByNomor:", error);
}
}
async function onResendCode() {
@@ -197,13 +164,12 @@ export default function Validasi() {
setTriggerOtp(true);
setCounter(60);
setLoadingResend(false);
// router.push("/validasi", { scroll: false });
} else {
setLoadingResend(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
}
} catch (error) {
console.error(error);
clientLogger.error(" Error onResend", error);
setLoadingResend(false);
ComponentGlobal_NotifikasiGagal("Terjadi Kesalahan");
}
@@ -213,7 +179,7 @@ export default function Validasi() {
<>
<UIGlobal_LayoutDefault>
<Stack h={"100vh"}>
{/* <Box
<Box
pt={"md"}
px={"md"}
style={{
@@ -222,9 +188,13 @@ export default function Validasi() {
}}
>
<ActionIcon variant="transparent" onClick={() => onBack()}>
<IconChevronLeft color="white" />
{data && data.nomor !== "" ? (
<IconChevronLeft color="white" />
) : (
""
)}
</ActionIcon>
</Box> */}
</Box>
<Stack align="center" justify="center" h={"100vh"} spacing={50}>
<Title order={2} color={MainColor.yellow}>
@@ -260,31 +230,40 @@ export default function Validasi() {
</Center>
<Stack h={"5vh"} align="center" justify="center">
<Text fs="italic" c={MainColor.white}>
Tidak menerima kode ?{" "}
{counter > 0 ? (
<Text fw={"bold"} inherit span>
{counter + "s"}
</Text>
) : loadingResend ? (
<Loader ml={"sm"} size={"xs"} color="yellow" />
<Group position="center">
<Text fs="italic" c={MainColor.white}>
Tidak menerima kode ?{" "}
</Text>
{data && data.nomor !== "" ? (
counter > 0 ? (
<Text fw={"bold"} c={MainColor.white}>
{counter + "s"}
</Text>
) : loadingResend ? (
<Loader ml={"sm"} size={"xs"} color="yellow" />
) : (
<Text
c={MainColor.white}
onClick={() => {
onResendCode();
}}
fw={"bold"}
>
Kirim ulang
</Text>
)
) : (
<Text
inherit
span
onClick={() => {
onResendCode();
}}
fw={"bold"}
>
Kirim ulang
</Text>
<CustomSkeleton height={20} radius={"xl"} width={20} />
)}
</Text>
</Group>
</Stack>
</Stack>
<Button
w={300}
disabled={inputCode.length < 4 ? true : false}
style={{
transition: "all ease 0.3s",
}}
loading={loading ? true : false}
loaderPosition="center"
radius={"md"}
@@ -293,9 +272,6 @@ export default function Validasi() {
c={"black"}
bg={MainColor.yellow}
color={"yellow"}
style={{
borderColor: AccentColor.yellow,
}}
onClick={() => {
data.nomor == "" && data.code == ""
? null
@@ -305,8 +281,6 @@ export default function Validasi() {
<Text>VERIFIKASI</Text>
</Button>
</Stack>
{/* {data.nomor == "" && data.code == "" ? <Validasi_SkeletonView /> : ""} */}
</Stack>
</UIGlobal_LayoutDefault>
</>