diff options
author | Michael Hunteman <michael@huntm.net> | 2024-08-25 12:44:32 -0700 |
---|---|---|
committer | Michael Hunteman <michael@huntm.net> | 2024-08-25 12:44:32 -0700 |
commit | 096a08708e2310becba56a237ef63b5cf6e3c4c4 (patch) | |
tree | 2924f9aecdcf035599558552cfdb20c2cc18f7d1 /client/src/slices/api | |
parent | 6aee47e76d7e25206b3778aeebcc341d7b705035 (diff) |
Add admin dashboard
Diffstat (limited to 'client/src/slices/api')
-rw-r--r-- | client/src/slices/api/adminSlice.ts | 53 | ||||
-rw-r--r-- | client/src/slices/api/guestSlice.ts | 60 |
2 files changed, 113 insertions, 0 deletions
diff --git a/client/src/slices/api/adminSlice.ts b/client/src/slices/api/adminSlice.ts new file mode 100644 index 0000000..cd1638d --- /dev/null +++ b/client/src/slices/api/adminSlice.ts @@ -0,0 +1,53 @@ +import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; +import type { RootState } from '../../store'; + +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 interface AdminLoginRequest { + username: string; + password: string; +} + +export interface AdminLoginResponse { + guests: Guest[]; + token: string; +} + +export const adminSlice = createApi({ + reducerPath: 'adminApi', + baseQuery: fetchBaseQuery({ + baseUrl: import.meta.env.VITE_BASE_URL, + prepareHeaders: (headers, { getState }) => { + const token = (getState() as RootState).admin.token; + if (token) { + headers.set('authorization', `${token}`); + } + return headers; + }, + }), + endpoints: (builder) => ({ + loginAdmin: builder.mutation<AdminLoginResponse, AdminLoginRequest>({ + query: (credentials) => ({ + url: 'admin/login', + method: 'POST', + body: credentials, + }), + }), + }), +}); + +export const { useLoginAdminMutation } = adminSlice; 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; |