import React, { useEffect, useState } from 'react'; import type { ReactElement } from 'react'; import Head from 'next/head'; import BaseButton from '../components/BaseButton'; import CardBox from '../components/CardBox'; import BaseIcon from "../components/BaseIcon"; import { mdiInformation, mdiEye, mdiEyeOff } from '@mdi/js'; import SectionFullScreen from '../components/SectionFullScreen'; import LayoutGuest from '../layouts/Guest'; import { Field, Form, Formik } from 'formik'; import FormField from '../components/FormField'; import FormCheckRadio from '../components/FormCheckRadio'; import BaseDivider from '../components/BaseDivider'; import BaseButtons from '../components/BaseButtons'; import { useRouter } from 'next/router'; import { getPageTitle } from '../config'; import { findMe, loginUser, resetAction } from '../stores/authSlice'; import { useAppDispatch, useAppSelector } from '../stores/hooks'; import Link from 'next/link'; import {toast, ToastContainer} from "react-toastify"; import { getPexelsImage, getPexelsVideo } from '../helpers/pexels' import { getPostLoginRoute } from '../helpers/workspace'; export default function Login() { const router = useRouter(); const dispatch = useAppDispatch(); const textColor = useAppSelector((state) => state.style.linkColor); const iconsColor = useAppSelector((state) => state.style.iconsColor); const notify = (type, msg) => toast(msg, { type }); const [ illustrationImage, setIllustrationImage ] = useState({ src: undefined, photographer: undefined, photographer_url: undefined, }) const [ illustrationVideo, setIllustrationVideo ] = useState({video_files: []}) const [contentType, setContentType] = useState('image'); const [contentPosition, setContentPosition] = useState('background'); const [showPassword, setShowPassword] = useState(false); const { currentUser, isFetching, errorMessage, token, notify:notifyState } = useAppSelector( (state) => state.auth, ); const [initialValues, setInitialValues] = React.useState({ email:'super_admin@flatlogic.com', password: '5e8f2960', remember: true }) const title = 'FDSU ERP' // Fetch Pexels image/video useEffect( () => { async function fetchData() { const image = await getPexelsImage() const video = await getPexelsVideo() setIllustrationImage(image); setIllustrationVideo(video); } fetchData(); }, []); // Fetch user data useEffect(() => { const existingToken = token || (typeof window !== 'undefined' ? localStorage.getItem('token') : ''); if (existingToken) { dispatch(findMe()); } }, [dispatch, token]); // Redirect to the intended deep link or the role workspace if user is logged in useEffect(() => { if (currentUser?.id) { router.replace(getPostLoginRoute(currentUser?.app_role?.name, router.query.redirect)); } }, [currentUser?.app_role?.name, currentUser?.id, router, router.query.redirect]); // Show error message if there is one useEffect(() => { if (errorMessage){ notify('error', errorMessage) } }, [errorMessage]) // Show notification if there is one useEffect(() => { if (notifyState?.showNotification) { notify('success', notifyState?.textNotification) dispatch(resetAction()); } }, [notifyState?.showNotification]) const togglePasswordVisibility = () => { setShowPassword(!showPassword); }; const handleSubmit = async (value) => { const {remember, ...rest} = value await dispatch(loginUser(rest)); }; const setLogin = (target: HTMLElement) => { setInitialValues(prev => ({ ...prev, email : target.innerText.trim(), password: target.dataset.password ?? '', })); }; const imageBlock = (image) => (
Photo by {image?.photographer} on Pexels
) const videoBlock = (video) => { if (video?.video_files?.length > 0) { return (
Video by {video.user.name} on Pexels
) } }; return (
{getPageTitle('Login')}
{contentType === 'image' && contentPosition !== 'background' ? imageBlock(illustrationImage) : null} {contentType === 'video' && contentPosition !== 'background' ? videoBlock(illustrationVideo) : null}

{title}

Use{' '} setLogin(e.target)}>super_admin@flatlogic.com{' / '} 5e8f2960{' / '} to login as Super Admin

Use{' '} setLogin(e.target)}>admin@flatlogic.com{' / '} 5e8f2960{' / '} to login as Admin

Use setLogin(e.target)}>client@hello.com{' / '} 242b5480541a{' / '} to login as User

handleSubmit(values)} >
Forgot password?

Don’t have an account yet?{' '} New Account

© 2026 {title}. © All rights reserved

Privacy Policy
); } Login.getLayout = function getLayout(page: ReactElement) { return {page}; };