From 9e6c97e532ef9970fc975123abaca86c4ce9b6b1 Mon Sep 17 00:00:00 2001 From: Michael Hunteman Date: Sat, 31 Aug 2024 16:09:58 -0700 Subject: Update type names --- client/src/components/AdminLogin.tsx | 6 +++--- client/src/components/GuestLogin.tsx | 6 +++--- client/src/components/RsvpForm.tsx | 20 ++++++++++---------- client/src/models.ts | 10 +++++----- client/src/slices/api/adminSlice.ts | 4 ++-- client/src/slices/api/guestSlice.ts | 12 ++++-------- 6 files changed, 27 insertions(+), 31 deletions(-) (limited to 'client/src') diff --git a/client/src/components/AdminLogin.tsx b/client/src/components/AdminLogin.tsx index 92e5335..4f53566 100644 --- a/client/src/components/AdminLogin.tsx +++ b/client/src/components/AdminLogin.tsx @@ -5,7 +5,7 @@ import { Button, Paper, TextField, Typography } from '@mui/material'; import { useForm } from 'react-hook-form'; import { setAdmin } from '../slices/auth/adminSlice'; import { useLoginAdminMutation } from '../slices/api/adminSlice'; -import type { AdminLoginRequest } from '../models'; +import type { Credentials } from '../models'; function GuestLogin() { const dispatch = useDispatch(); @@ -16,14 +16,14 @@ function GuestLogin() { register, handleSubmit, formState: { errors }, - } = useForm({ + } = useForm({ defaultValues: { username: '', password: '', }, }); - const onSubmit = async (data: AdminLoginRequest) => { + const onSubmit = async (data: Credentials) => { try { dispatch(setAdmin(await login(data).unwrap())); navigate('/dashboard'); diff --git a/client/src/components/GuestLogin.tsx b/client/src/components/GuestLogin.tsx index 0e47384..f42c1d6 100644 --- a/client/src/components/GuestLogin.tsx +++ b/client/src/components/GuestLogin.tsx @@ -5,7 +5,7 @@ import { Button, Paper, TextField, Typography } from '@mui/material'; import { useForm } from 'react-hook-form'; import { setGuest } from '../slices/auth/guestSlice'; import { useLoginGuestMutation } from '../slices/api/guestSlice'; -import type { GuestLoginRequest } from '../slices/api/guestSlice'; +import type { Name } from '../models'; function GuestLogin() { const dispatch = useDispatch(); @@ -16,14 +16,14 @@ function GuestLogin() { register, handleSubmit, formState: { errors }, - } = useForm({ + } = useForm({ defaultValues: { firstName: '', lastName: '', }, }); - const onSubmit = async (data: GuestLoginRequest) => { + const onSubmit = async (data: Name) => { try { dispatch(setGuest(await login(data).unwrap())); navigate('/rsvp'); diff --git a/client/src/components/RsvpForm.tsx b/client/src/components/RsvpForm.tsx index c7c30f4..b3ed3b3 100644 --- a/client/src/components/RsvpForm.tsx +++ b/client/src/components/RsvpForm.tsx @@ -37,10 +37,10 @@ const Status = ({ isError, setOpen }: StatusProps) => { }; function RsvpForm() { - const [updateGuest, { isLoading, isSuccess, isError, error }] = + const [updateGuest, { isLoading, isSuccess, isError }] = useUpdateGuestMutation(); const guest: Guest = useOutletContext(); - const previousPartySize = useRef(guest?.partySize - 1); + const previousPartySize = useRef(guest.partySize ?? 1 - 1); const [open, setOpen] = useState(false); useEffect(() => { @@ -55,14 +55,14 @@ function RsvpForm() { formState: { errors }, } = useForm({ defaultValues: { - id: guest?.id, - firstName: guest?.firstName, - lastName: guest?.lastName, - attendance: guest?.attendance, - email: guest?.email, - message: guest?.message, - partySize: guest?.partySize, - partyList: guest?.partyList, + id: guest.id, + firstName: guest.firstName, + lastName: guest.lastName, + attendance: guest.attendance, + email: guest.email, + message: guest.message, + partySize: guest.partySize, + partyList: guest.partyList, }, }); diff --git a/client/src/models.ts b/client/src/models.ts index 2580d90..6840a46 100644 --- a/client/src/models.ts +++ b/client/src/models.ts @@ -6,25 +6,25 @@ export interface Guest { email?: string; message?: string; partySize?: number; - partyList?: Array; + partyList?: Array; } -export interface GuestLoginRequest { +export interface Name { firstName: string; lastName: string; } -export interface GuestLoginResponse { +export interface GuestLogin { guest: Guest; token: string; } -export interface AdminLoginRequest { +export interface Credentials { username: string; password: string; } -export interface AdminLoginResponse { +export interface AdminLogin { guests: Guest[]; token: string; } diff --git a/client/src/slices/api/adminSlice.ts b/client/src/slices/api/adminSlice.ts index bd69502..5de5c4d 100644 --- a/client/src/slices/api/adminSlice.ts +++ b/client/src/slices/api/adminSlice.ts @@ -1,6 +1,6 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; import type { RootState } from '../../store'; -import type { AdminLoginRequest, AdminLoginResponse } from '../../models'; +import type { Credentials, AdminLogin } from '../../models'; export const adminSlice = createApi({ reducerPath: 'adminApi', @@ -15,7 +15,7 @@ export const adminSlice = createApi({ }, }), endpoints: (builder) => ({ - loginAdmin: builder.mutation({ + loginAdmin: builder.mutation({ query: (credentials) => ({ url: 'admin/login', method: 'POST', diff --git a/client/src/slices/api/guestSlice.ts b/client/src/slices/api/guestSlice.ts index a7dbcc4..312a665 100644 --- a/client/src/slices/api/guestSlice.ts +++ b/client/src/slices/api/guestSlice.ts @@ -1,10 +1,6 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; import type { RootState } from '../../store'; -import type { - Guest, - GuestLoginRequest, - GuestLoginResponse, -} from '../../models'; +import type { Guest, Name, GuestLogin } from '../../models'; export const guestSlice = createApi({ reducerPath: 'guestApi', @@ -19,11 +15,11 @@ export const guestSlice = createApi({ }, }), endpoints: (builder) => ({ - loginGuest: builder.mutation({ - query: (credentials) => ({ + loginGuest: builder.mutation({ + query: (name) => ({ url: 'login', method: 'POST', - body: credentials, + body: name, }), }), updateGuest: builder.mutation({ -- cgit v1.2.3