feat:executive create user form

This commit is contained in:
Rama Priyanto 2025-02-11 13:53:55 +07:00
parent 841859414d
commit 0b40accc49
3 changed files with 120 additions and 24 deletions

View File

@ -232,6 +232,10 @@ export default function CreateUserForm() {
id: "ADM-ID",
name: "Admin",
},
{
id: "EXE-ID",
name: "Eksekutif",
},
{
id: "APP-ID",
name: "Approver",

View File

@ -21,7 +21,9 @@ import { useTranslations } from "next-intl";
// Schema validasi menggunakan zod
const schema = z.object({
username: z.string().min(1, { message: "Judul diperlukan" }),
password: z.string().min(4, { message: "Password must be at least 4 characters." }),
password: z
.string()
.min(4, { message: "Password must be at least 4 characters." }),
});
// Tipe untuk form values
@ -37,7 +39,9 @@ const LoginForm = () => {
const t = useTranslations("LandingPage");
const togglePasswordType = () => {
setPasswordType((prevType) => (prevType === "password" ? "text" : "password"));
setPasswordType((prevType) =>
prevType === "password" ? "text" : "password"
);
};
const {
@ -86,18 +90,29 @@ const LoginForm = () => {
const profile = await getProfile(access_token);
console.log("PROFILE : ", profile?.data?.data);
if (profile?.data?.data?.isInternational == true || profile?.data?.data?.isActive == false || profile?.data?.data?.isDelete == true) {
if (
profile?.data?.data?.isInternational == true ||
profile?.data?.data?.isActive == false ||
profile?.data?.data?.isDelete == true
) {
Object.keys(Cookies.get()).forEach((cookieName) => {
Cookies.remove(cookieName);
});
warning("Akun Anda tidak dapat digunakan untuk masuk ke MediaHub Polri", "/auth/login");
warning(
"Akun Anda tidak dapat digunakan untuk masuk ke MediaHub Polri",
"/auth/login"
);
} else {
Cookies.set("home_path", profile?.data?.data?.homePath, {
expires: 1,
});
Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, {
expires: 1,
});
Cookies.set(
"profile_picture",
profile?.data?.data?.profilePictureUrl,
{
expires: 1,
}
);
Cookies.set("state", profile?.data?.data?.userLevel?.name, {
expires: 1,
});
@ -113,12 +128,20 @@ const LoginForm = () => {
setCookiesEncrypt("ulie", profile?.data?.data?.userLevel?.id, {
expires: 1,
});
setCookiesEncrypt("uplie", profile?.data?.data?.userLevel?.parentLevelId, {
expires: 1,
});
setCookiesEncrypt("ulne", profile?.data?.data?.userLevel?.levelNumber, {
expires: 1,
});
setCookiesEncrypt(
"uplie",
profile?.data?.data?.userLevel?.parentLevelId,
{
expires: 1,
}
);
setCookiesEncrypt(
"ulne",
profile?.data?.data?.userLevel?.levelNumber,
{
expires: 1,
}
);
setCookiesEncrypt("ufne", profile?.data?.data?.fullname, {
expires: 1,
});
@ -128,7 +151,7 @@ const LoginForm = () => {
setCookiesEncrypt("uinse", profile?.data?.data?.instituteId, {
expires: 1,
});
console.log("ssaddd", profile?.data?.data?.roleId);
if (
Number(profile?.data?.data?.roleId) == 2 ||
Number(profile?.data?.data?.roleId) == 3 ||
@ -136,9 +159,19 @@ const LoginForm = () => {
Number(profile?.data?.data?.roleId) == 9 ||
Number(profile?.data?.data?.roleId) == 10 ||
Number(profile?.data?.data?.roleId) == 11 ||
Number(profile?.data?.data?.roleId) == 12
Number(profile?.data?.data?.roleId) == 12 ||
Number(profile?.data?.data?.roleId) == 18
) {
if (profile?.data?.data?.userLevel?.id == 761 || profile?.data?.data?.userLevel?.parentLevelId == 761) {
if (profile?.data?.data?.roleId === 18) {
window.location.href = "/in/dashboard/executive";
// router.push('/admin/dashboard');
Cookies.set("status", "login", {
expires: 1,
});
} else if (
profile?.data?.data?.userLevel?.id == 761 ||
profile?.data?.data?.userLevel?.parentLevelId == 761
) {
window.location.href = "/in/welcome";
Cookies.set("status", "login", {
expires: 1,
@ -182,7 +215,11 @@ const LoginForm = () => {
"border-destructive": errors.username,
})}
/>
{errors.username?.message && <div className="text-destructive mt-2 text-sm">{errors.username.message}</div>}
{errors.username?.message && (
<div className="text-destructive mt-2 text-sm">
{errors.username.message}
</div>
)}
</div>
<div className="mt-3.5 space-y-2">
@ -190,12 +227,33 @@ const LoginForm = () => {
{t("password")}
</Label>
<div className="relative">
<Input size="lg" disabled={isPending} {...register("password")} id="password" type={passwordType} className="peer" />
<div className="absolute top-1/2 -translate-y-1/2 ltr:right-4 rtl:left-4 cursor-pointer" onClick={togglePasswordType}>
{passwordType === "password" ? <Icon icon="heroicons:eye" className="w-5 h-5 text-default-400" /> : <Icon icon="heroicons:eye-slash" className="w-5 h-5 text-default-400" />}
<Input
size="lg"
disabled={isPending}
{...register("password")}
id="password"
type={passwordType}
className="peer"
/>
<div
className="absolute top-1/2 -translate-y-1/2 ltr:right-4 rtl:left-4 cursor-pointer"
onClick={togglePasswordType}
>
{passwordType === "password" ? (
<Icon icon="heroicons:eye" className="w-5 h-5 text-default-400" />
) : (
<Icon
icon="heroicons:eye-slash"
className="w-5 h-5 text-default-400"
/>
)}
</div>
</div>
{errors.password?.message && <div className="text-destructive mt-2 text-sm">{errors.password.message}</div>}
{errors.password?.message && (
<div className="text-destructive mt-2 text-sm">
{errors.password.message}
</div>
)}
</div>
<div className="flex justify-between">
@ -203,7 +261,10 @@ const LoginForm = () => {
<Checkbox id="checkbox" defaultChecked />
<Label htmlFor="checkbox">{t("rememberMe")}</Label>
</div>
<Link href="/auth/forgot-password" className="text-sm text-default-800 dark:text-default-400 leading-6 font-medium">
<Link
href="/auth/forgot-password"
className="text-sm text-default-800 dark:text-default-400 leading-6 font-medium"
>
{t("forgotPass")}
</Link>
</div>

View File

@ -1607,7 +1607,10 @@ export function getMenuList(pathname: string, t: any): Group[] {
],
},
];
} else if ((Number(roleId) == 3 || Number(roleId) == 4) && Number(levelNumber) == 2) {
} else if (
(Number(roleId) == 3 || Number(roleId) == 4) &&
Number(levelNumber) == 2
) {
if (Number(userLevelId) != 761) {
menusSelected = [
{
@ -1955,7 +1958,10 @@ export function getMenuList(pathname: string, t: any): Group[] {
},
];
}
} else if ((Number(roleId) == 3 || Number(roleId) == 4) && Number(levelNumber) == 3) {
} else if (
(Number(roleId) == 3 || Number(roleId) == 4) &&
Number(levelNumber) == 3
) {
if (Number(userParentLevelId) != 761) {
menusSelected = [
{
@ -3188,6 +3194,31 @@ export function getMenuList(pathname: string, t: any): Group[] {
},
];
}
} else if (Number(roleId) === 18) {
menusSelected = [
{
groupLabel: t("apps"),
id: "dashboard",
menus: [
{
id: "dashboard",
href: "/dashboard",
label: t("dashboard"),
active: pathname.includes("/dashboard"),
icon: "material-symbols:dashboard",
submenus: [
{
href: "/dashboard/executive",
label: "Executive",
active: pathname === "/dashboard/executive",
icon: "heroicons:arrow-trending-up",
children: [],
},
],
},
],
},
];
}
return menusSelected;