diff options
Diffstat (limited to 'src/features/auth')
-rw-r--r-- | src/features/auth/GuestLogin.tsx | 19 | ||||
-rw-r--r-- | src/features/auth/authSlice.ts | 7 |
2 files changed, 9 insertions, 17 deletions
diff --git a/src/features/auth/GuestLogin.tsx b/src/features/auth/GuestLogin.tsx index 2100a94..8585e61 100644 --- a/src/features/auth/GuestLogin.tsx +++ b/src/features/auth/GuestLogin.tsx @@ -1,12 +1,9 @@ -import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useDispatch } from 'react-redux'; -import { Button, Grid, Paper, TextField, Typography } from '@mui/material'; +import { Button, Stack, TextField, Typography } from '@mui/material'; import { useForm } from 'react-hook-form'; - import { setCredentials } from './authSlice'; -import { useLoginMutation } from '../../apiSlice'; -import type { LoginRequest } from './authSlice'; +import { useLoginMutation, LoginRequest } from '../../apiSlice'; function GuestLogin() { const dispatch = useDispatch(); @@ -33,34 +30,26 @@ function GuestLogin() { return ( <form onSubmit={handleSubmit(onSubmit)}> - <Grid container spacing={2}> - <Grid item xs={12} md={12} lg={12}> + <Stack spacing={2}> <Typography variant="h6"> Guest Login </Typography> - </Grid> - <Grid item xs={12} md={6} lg={6}> <TextField label="First Name" variant="outlined" required {...register("firstName", { required: true })} /> - </Grid> - <Grid item xs={12} md={6} lg={6}> <TextField label="Last Name" variant="outlined" required {...register("lastName", { required: true })} /> - </Grid> - <Grid item> <Button type="submit" variant="contained" disabled={!isDirty || !isValid}> Login </Button> - </Grid> - </Grid> + </Stack> </form> ); } diff --git a/src/features/auth/authSlice.ts b/src/features/auth/authSlice.ts index 9716131..04be93f 100644 --- a/src/features/auth/authSlice.ts +++ b/src/features/auth/authSlice.ts @@ -1,18 +1,21 @@ import { createSlice } from '@reduxjs/toolkit'; import type { RootState } from '../../store'; +import { User } from '../../apiSlice'; type AuthState = { user: User | null + id: number | null token: string | null } const authSlice = createSlice({ name: 'auth', - initialState: { user: null, token: null } as AuthState, + initialState: { user: null, token: null, id: null } as AuthState, reducers: { setCredentials: (state, action) => { - const { user, token } = action.payload; + const { user, token, id } = action.payload; state.user = user; + state.id = id; state.token = token; } } |