|
|
@ -1,3 +1,4 @@ |
|
|
|
"use client" |
|
|
|
import React from "react"; |
|
|
|
import styles from "./loginPage.module.scss"; |
|
|
|
import Box from "@mui/material/Box"; |
|
|
@ -7,8 +8,42 @@ import { UTILITY_CONSTANT } from "@/utilities/utilityConstant"; |
|
|
|
import Link from "next/link"; |
|
|
|
import CustomizedInputsStyled from "@/ui/CustomizedInputsStyled"; |
|
|
|
import CustomizedButtons from "@/ui/customizedButtons"; |
|
|
|
import { useForm } from 'react-hook-form'; |
|
|
|
import { z } from 'zod'; |
|
|
|
import { zodResolver } from '@hookform/resolvers/zod'; |
|
|
|
import { useState } from 'react'; |
|
|
|
import { loginApi } from "@/services/api/loginApi"; |
|
|
|
import { FormControl } from '@mui/material'; |
|
|
|
import CustomTextField from "@/ui/CustomTextField"; |
|
|
|
|
|
|
|
const loginSchema = z.object({ |
|
|
|
username: z.string(), |
|
|
|
password: z.string(), |
|
|
|
}); |
|
|
|
|
|
|
|
type LoginFormValues = z.infer<typeof loginSchema>; |
|
|
|
|
|
|
|
export default function LoginPage() { |
|
|
|
|
|
|
|
const { register, handleSubmit, formState: { errors }, control } = useForm<LoginFormValues>({ |
|
|
|
resolver: zodResolver(loginSchema), |
|
|
|
}); |
|
|
|
console.log("errors", errors) |
|
|
|
const [error, setError] = useState(''); |
|
|
|
|
|
|
|
const onSubmit = async (data: LoginFormValues) => { |
|
|
|
try { |
|
|
|
const response = await loginApi(data); |
|
|
|
localStorage.setItem('token', response.token); |
|
|
|
localStorage.setItem('refreshToken', response.refreshToken); |
|
|
|
console.log("🚀 ~ response @@@ @@@ @@@ @@@ @@@@:", response) |
|
|
|
|
|
|
|
// router.push('/dashboard');
|
|
|
|
} catch (err) { |
|
|
|
setError('Invalid credentials'); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
return ( |
|
|
|
<main className={styles.loginPage}> |
|
|
|
<Grid container sx={{ height: "100%" }}> |
|
|
@ -40,7 +75,7 @@ export default function LoginPage() { |
|
|
|
paddingBlock={5} |
|
|
|
> |
|
|
|
<img src={UTILITY_CONSTANT.IMAGES.AUTH.HEADER_LOG} alt="logo" /> |
|
|
|
<Box width={"100%"}> |
|
|
|
<form onSubmit={handleSubmit(onSubmit)}> |
|
|
|
<Typography variant="h4">Welcome to Convexsol</Typography> |
|
|
|
<Typography variant="h4">Sign in to your account</Typography> |
|
|
|
<Box |
|
|
@ -51,17 +86,26 @@ export default function LoginPage() { |
|
|
|
flexDirection={"column"} |
|
|
|
gap={3} |
|
|
|
> |
|
|
|
<CustomizedInputsStyled label="User Name" type="text" /> |
|
|
|
<CustomizedInputsStyled |
|
|
|
<CustomTextField |
|
|
|
name="username" |
|
|
|
control={control} |
|
|
|
label="Username" |
|
|
|
error={!!errors.username} |
|
|
|
helperText={errors.username?.message} |
|
|
|
/> |
|
|
|
<CustomTextField |
|
|
|
name="password" |
|
|
|
control={control} |
|
|
|
label="Password" |
|
|
|
type="password" |
|
|
|
endAdornmentBoolean |
|
|
|
error={!!errors.password} |
|
|
|
helperText={errors.password?.message} |
|
|
|
/> |
|
|
|
</Box> |
|
|
|
<Box width={"100%"} marginBlockStart={"20px"}> |
|
|
|
<CustomizedButtons label={"Sign In"} /> |
|
|
|
<CustomizedButtons btnType="submit" label={"Sign In"} /> |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
</form> |
|
|
|
<Box |
|
|
|
width={"100%"} |
|
|
|
display={"flex"} |
|
|
|