summaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
authorMichael Hunteman <michael@huntm.net>2024-08-31 16:09:58 -0700
committerMichael Hunteman <michael@huntm.net>2024-08-31 16:09:58 -0700
commit9e6c97e532ef9970fc975123abaca86c4ce9b6b1 (patch)
tree340f5f00ecbed20be9a18964b17487dbd427b85a /client/src
parentdf22d74076e3af98c2ddf1b5f7b44c71f1972640 (diff)
Update type names
Diffstat (limited to 'client/src')
-rw-r--r--client/src/components/AdminLogin.tsx6
-rw-r--r--client/src/components/GuestLogin.tsx6
-rw-r--r--client/src/components/RsvpForm.tsx20
-rw-r--r--client/src/models.ts10
-rw-r--r--client/src/slices/api/adminSlice.ts4
-rw-r--r--client/src/slices/api/guestSlice.ts12
6 files changed, 27 insertions, 31 deletions
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<AdminLoginRequest>({
+ } = useForm<Credentials>({
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<GuestLoginRequest>({
+ } = useForm<Name>({
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<boolean>(false);
useEffect(() => {
@@ -55,14 +55,14 @@ function RsvpForm() {
formState: { errors },
} = useForm<Guest>({
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<Guest>;
+ partyList?: Array<Name>;
}
-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<AdminLoginResponse, AdminLoginRequest>({
+ loginAdmin: builder.mutation<AdminLogin, Credentials>({
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<GuestLoginResponse, GuestLoginRequest>({
- query: (credentials) => ({
+ loginGuest: builder.mutation<GuestLogin, Name>({
+ query: (name) => ({
url: 'login',
method: 'POST',
- body: credentials,
+ body: name,
}),
}),
updateGuest: builder.mutation<Guest, Guest>({