From a6b1fa31e890b51b043c4211b14cd4be29ed6fba Mon Sep 17 00:00:00 2001 From: Michael Hunteman Date: Tue, 9 Jul 2024 18:24:15 -0700 Subject: Add success and error alerts --- client/src/features/auth/GuestLogin.tsx | 79 --------------------------------- client/src/features/auth/authSlice.ts | 31 ------------- 2 files changed, 110 deletions(-) delete mode 100644 client/src/features/auth/GuestLogin.tsx delete mode 100644 client/src/features/auth/authSlice.ts (limited to 'client/src/features/auth') diff --git a/client/src/features/auth/GuestLogin.tsx b/client/src/features/auth/GuestLogin.tsx deleted file mode 100644 index 4da7e45..0000000 --- a/client/src/features/auth/GuestLogin.tsx +++ /dev/null @@ -1,79 +0,0 @@ -import React from 'react'; -import { useNavigate } from 'react-router-dom'; -import { useDispatch } from 'react-redux'; -import { Button, Container, TextField, Typography } from '@mui/material'; -import { useForm } from 'react-hook-form'; -import { setCredentials } from './authSlice'; -import { useLoginMutation } from '../../apiSlice'; -import type { LoginRequest } from '../../apiSlice'; - -function GuestLogin() { - const dispatch = useDispatch(); - const navigate = useNavigate(); - const [login] = useLoginMutation(); - - const { - register, - handleSubmit, - formState: { errors }, - } = useForm({ - defaultValues: { - firstName: '', - lastName: '', - }, - }); - - const onSubmit = async (data: LoginRequest) => { - try { - dispatch(setCredentials(await login(data).unwrap())); - navigate('/rsvp'); - } catch (e) { - console.log(e); - } - }; - - return ( - -
- Guest Login - - - -
-
- ); -} - -export default GuestLogin; diff --git a/client/src/features/auth/authSlice.ts b/client/src/features/auth/authSlice.ts deleted file mode 100644 index 878de0c..0000000 --- a/client/src/features/auth/authSlice.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { createSlice } from '@reduxjs/toolkit'; -import type { PayloadAction } from '@reduxjs/toolkit'; -import type { RootState } from '../../store'; -import type { Guest } from '../../apiSlice'; - -type AuthState = { - guest?: Guest; - token?: string; -}; - -const authSlice = createSlice({ - name: 'auth', - initialState: { guest: undefined, token: undefined } as AuthState, - reducers: { - setCredentials: ( - state, - { - payload: { guest, token }, - }: PayloadAction<{ guest: Guest; token: string }> - ) => { - state.guest = guest; - state.token = token; - }, - }, -}); - -export const { setCredentials } = authSlice.actions; - -export default authSlice.reducer; - -export const selectCurrentGuest = (state: RootState) => state.auth.guest; -- cgit v1.2.3