"use client"; import React, { useState } from "react"; import Link from "next/link"; import Cookies from "js-cookie"; import { useRouter } from "next/navigation"; import withReactContent from "sweetalert2-react-content"; import { Input } from "../ui/input"; import { Label } from "../ui/label"; import Swal from "sweetalert2"; import { EyeFilledIcon, EyeSlashFilledIcon } from "../icons"; import { Button } from "../ui/button"; import { error, loading } from "@/lib/swal"; import { doLogin, getProfile } from "@/service/auth"; export default function Login() { const router = useRouter(); const [isVisible, setIsVisible] = useState(false); const [isVisibleSetup, setIsVisibleSetup] = useState([false, false]); const [oldEmail, setOldEmail] = useState(""); const [newEmail, setNewEmail] = useState(""); const [passwordSetup, setPasswordSetup] = useState(""); const [confPasswordSetup, setConfPasswordSetup] = useState(""); const toggleVisibility = () => setIsVisible(!isVisible); const [needOtp, setNeedOtp] = useState(false); const [isFirstLogin, setFirstLogin] = useState(false); const [otpValue, setOtpValue] = useState(""); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [accessData, setAccessData] = useState(); const [profile, setProfile] = useState(); const [isValidEmail, setIsValidEmail] = useState(false); const [isResetPassword, setIsResetPassword] = useState(false); const [checkUsernameValue, setCheckUsernameValue] = useState(""); const MySwal = withReactContent(Swal); const setValUsername = (e: any) => { const uname = e.replaceAll(/[^\w.-]/g, ""); setUsername(uname.toLowerCase()); }; const onSubmit = async () => { const data = { username: username, password: password, }; if (!username || !password) { error("Username & Password Wajib Diisi !"); } else { loading(); const response = await doLogin(data); if (response?.error) { error("Username / Password Tidak Sesuai"); } else { const profile = await getProfile(response?.data?.data?.access_token); const dateTime: any = new Date(); const newTime: any = dateTime.getTime() + 10 * 60 * 1000; Cookies.set("access_token", response?.data?.data?.access_token, { expires: 1, }); Cookies.set("refresh_token", response?.data?.data?.refresh_token, { expires: 1, }); Cookies.set("time_refresh", newTime, { expires: 1, }); Cookies.set("is_first_login", "true", { secure: true, sameSite: "strict", }); // await saveActivity( // { // activityTypeId: 1, // url: "https://dev.mikulnews.com/auth", // userId: profile?.data?.data?.id, // }, // response?.data?.data?.access_token // ); Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { expires: 1, }); Cookies.set("uie", profile?.data?.data?.id, { expires: 1, }); Cookies.set("ufne", profile?.data?.data?.fullname, { expires: 1, }); Cookies.set("ulie", profile?.data?.data?.userLevelGroup, { expires: 1, }); Cookies.set("username", profile?.data?.data?.username, { expires: 1, }); Cookies.set("urie", profile?.data?.data?.userRoleId, { expires: 1, }); console.log( "RRR", profile?.data?.data?.role.id, "TTTT", profile?.data?.data?.roleId ); Cookies.set("roleName", profile?.data?.data?.roleName, { expires: 1, }); Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { expires: 1, }); Cookies.set("ulne", profile?.data?.data?.userLevelId, { expires: 1, }); Cookies.set("urce", profile?.data?.data?.roleCode, { expires: 1, }); Cookies.set("email", profile?.data?.data?.email, { expires: 1, }); // router.push("/admin/dashboard"); console.log("OOO", profile?.data?.data); Cookies.set("status", "login", { expires: 1, }); close(); } } }; return (
Mikul News Logo

Portal Jaecoo

Platform beyond classic

Mikul News Logo
{isFirstLogin ? (

Setup Akun

Lengkapi informasi email Anda

setOldEmail(e.target.value)} />
setNewEmail(e.target.value)} />
) : needOtp ? (

Verifikasi OTP

Masukkan kode OTP yang telah dikirim

) : isResetPassword ? (

Reset Password

Masukkan username untuk reset password

setCheckUsernameValue(e.target.value.trim()) } onPaste={(e) => setCheckUsernameValue(e.currentTarget.value.trim()) } onCopy={(e) => setCheckUsernameValue(e.currentTarget.value.trim()) } />
Beranda
) : (
netidhub Logo

MENYATUKAN INDONESIA

setValUsername(e.target.value.trim())} onPaste={(e) => setValUsername(e.currentTarget.value.trim()) } onCopy={(e) => setValUsername(e.currentTarget.value.trim())} />
setPassword(e.target.value)} />

Lupa Kata Sandi?

{/*

Informasi Portal

Akses informasi terkini dan status permintaan informasi yang telah diajukan.

*/}
)}
); }