import React, { useEffect, useState } from 'react';
import type { ReactElement } from 'react';
import Head from 'next/head';
import Link from 'next/link';
import { Field, Form, Formik } from 'formik';
import { mdiEye, mdiEyeOff } from '@mdi/js';
import { toast, ToastContainer } from 'react-toastify';
import { useRouter } from 'next/router';
import BaseIcon from '../components/BaseIcon';
import LayoutGuest from '../layouts/Guest';
import { getPageTitle } from '../config';
import { findMe, loginUser, resetAction } from '../stores/authSlice';
import { useAppDispatch, useAppSelector } from '../stores/hooks';
const ui = {
page: 'bg-[#fffdf9] text-[#19192d]',
banner: 'bg-[#19192d] text-white',
navShell: 'rounded-none bg-white ring-1 ring-[#19192d]/5',
ink: 'text-[#19192d]',
muted: 'text-[#72798a]',
accent: 'text-[#35b7a5]',
gold: 'text-[#35b7a5]',
border: 'border-[#19192d]/10',
surface: 'bg-white',
softSurface: 'bg-[#fffdf9]',
darkPanel: 'bg-[#19192d] text-white',
button: 'bg-[#35b7a5] text-white transition hover:brightness-105',
card: 'rounded-none border border-[#19192d]/10 bg-white ',
overline: 'text-sm font-bold uppercase tracking-[0.28em] text-[#35b7a5]',
heading: 'font-serif font-semibold tracking-tight text-[#19192d]',
};
type LoginValues = {
email: string;
password: string;
remember: boolean;
};
const demoAccounts = [
{
label: 'Admin',
description: 'Full workspace access',
email: 'admin@flatlogic.com',
password: 'f76d928f',
},
{
label: 'Coach',
description: 'Coach workspace access',
email: 'john@doe.com',
password: '2226f6026f52',
},
{
label: 'Client',
description: 'Client portal access',
email: 'client@hello.com',
password: '2226f6026f52',
},
];
function Nav() {
return (
);
}
export default function Login() {
const router = useRouter();
const dispatch = useAppDispatch();
const [showPassword, setShowPassword] = useState(false);
const {
currentUser,
isFetching,
errorMessage,
token,
notify: notifyState,
} = useAppSelector((state) => state.auth);
const initialValues: LoginValues = {
email: 'admin@flatlogic.com',
password: 'f76d928f',
remember: true,
};
useEffect(() => {
if (token) {
dispatch(findMe());
}
}, [token, dispatch]);
useEffect(() => {
if (currentUser?.id) {
if (currentUser?.app_role?.name === 'Client') {
router.push('/client-portal');
return;
}
router.push('/dashboard');
}
}, [currentUser?.id, currentUser?.app_role?.name, router]);
useEffect(() => {
if (errorMessage) {
toast(errorMessage, { type: 'error' });
}
}, [errorMessage]);
useEffect(() => {
if (notifyState?.showNotification) {
toast(notifyState?.textNotification, { type: 'success' });
dispatch(resetAction());
}
}, [notifyState?.showNotification, notifyState?.textNotification, dispatch]);
async function handleSubmit(values: LoginValues) {
const { remember, ...credentials } = values;
await dispatch(loginUser(credentials));
}
return (
<>
{getPageTitle('Login')}
Still human
AI is not a coach. Keep the real relationship at the center.
Welcome back
Return to your coaching workspace.
Review session memory, prepare for the next call, and keep client
commitments moving between sessions.
{[
['Session memory', 'Summaries, themes, and commitments.'],
['Prep briefs', 'Context before the next conversation.'],
['Client portal', 'Approved notes and resources.'],
].map(([title, copy]) => (
))}
Sign in
Open your workspace
Use your workspace credentials to continue.
handleSubmit(values)}
>
{({ setValues }) => (
)}
Don't have an account yet?{' '}
Create one
>
);
}
Login.getLayout = function getLayout(page: ReactElement) {
return {page} ;
};