summaryrefslogtreecommitdiff
path: root/client/src/slices/api/guestSlice.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/slices/api/guestSlice.ts')
-rw-r--r--client/src/slices/api/guestSlice.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/client/src/slices/api/guestSlice.ts b/client/src/slices/api/guestSlice.ts
new file mode 100644
index 0000000..38deb9a
--- /dev/null
+++ b/client/src/slices/api/guestSlice.ts
@@ -0,0 +1,60 @@
+import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
+import type { RootState } from '../../store';
+
+export interface GuestLoginRequest {
+ firstName: string;
+ lastName: string;
+}
+
+export interface GuestLoginResponse {
+ guest: Guest;
+ token: string;
+}
+
+export interface Guest {
+ id: number;
+ firstName: string;
+ lastName: string;
+ attendance: string;
+ email: string;
+ message: string;
+ partySize: number;
+ partyList: Array<PartyGuest>;
+}
+
+export interface PartyGuest {
+ firstName: string;
+ lastName: string;
+}
+
+export const guestSlice = createApi({
+ reducerPath: 'guestApi',
+ baseQuery: fetchBaseQuery({
+ baseUrl: import.meta.env.VITE_BASE_URL + 'guest/',
+ prepareHeaders: (headers, { getState }) => {
+ const token = (getState() as RootState).guest.token;
+ if (token) {
+ headers.set('authorization', `${token}`);
+ }
+ return headers;
+ },
+ }),
+ endpoints: (builder) => ({
+ loginGuest: builder.mutation<GuestLoginResponse, GuestLoginRequest>({
+ query: (credentials) => ({
+ url: 'login',
+ method: 'POST',
+ body: credentials,
+ }),
+ }),
+ updateGuest: builder.mutation<Guest, Guest>({
+ query: (guest) => ({
+ url: `${guest?.id}`,
+ method: 'PUT',
+ body: guest,
+ }),
+ }),
+ }),
+});
+
+export const { useLoginGuestMutation, useUpdateGuestMutation } = guestSlice;