From f2312e79e6a5400e20be596ef571e613995592b2 Mon Sep 17 00:00:00 2001 From: Jordan Wong Date: Thu, 22 Feb 2024 18:37:26 -1000 Subject: [PATCH] Create EmailService.ts --- ui/.env | 1 + ui/src/components/layout/footer/Footer.tsx | 2 +- ui/src/components/layout/navbar/Navbar.tsx | 4 +- ui/src/services/EmailService.ts | 29 ++++++++++++++ ui/src/services/FetchService.ts | 8 ++-- .../components/layout/footer/Footer.test.tsx | 3 +- .../components/layout/navbar/Navbar.test.tsx | 8 ++-- ui/tests/services/EmailService.test.ts | 38 +++++++++++++++++++ 8 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 ui/src/services/EmailService.ts create mode 100644 ui/tests/services/EmailService.test.ts diff --git a/ui/.env b/ui/.env index e6464568..442e8ee5 100644 --- a/ui/.env +++ b/ui/.env @@ -1,5 +1,6 @@ # ========================================================================= NEXT_PUBLIC_BASE_URL=http://localhost:8080/uhgroupings +NEXT_PUBLIC_API_BASE_URL=http://localhost:8081/uhgroupingsapi NEXT_PUBLIC_API_2_1_BASE_URL=http://localhost:8081/uhgroupingsapi/api/groupings/v2.1 # ========================================================================= diff --git a/ui/src/components/layout/footer/Footer.tsx b/ui/src/components/layout/footer/Footer.tsx index e367f64d..da1ef2ce 100644 --- a/ui/src/components/layout/footer/Footer.tsx +++ b/ui/src/components/layout/footer/Footer.tsx @@ -6,7 +6,7 @@ const Footer = () => (
UH System logo diff --git a/ui/src/components/layout/navbar/Navbar.tsx b/ui/src/components/layout/navbar/Navbar.tsx index 197f112a..f70aa1e1 100644 --- a/ui/src/components/layout/navbar/Navbar.tsx +++ b/ui/src/components/layout/navbar/Navbar.tsx @@ -15,7 +15,7 @@ const Navbar = async () => {
UH Groupings Logo @@ -24,7 +24,7 @@ const Navbar = async () => { UH Groupings Logo diff --git a/ui/src/services/EmailService.ts b/ui/src/services/EmailService.ts new file mode 100644 index 00000000..9ac99b22 --- /dev/null +++ b/ui/src/services/EmailService.ts @@ -0,0 +1,29 @@ +'use server'; + +import { getCurrentUser } from '@/access/AuthenticationService'; +import { ApiError } from '@/groupings/GroupingsApiResults'; +import { postRequest } from './FetchService'; + +const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL as string; + +export type Feedback = { + name?: string, + email: string, + type: string, + message: string, + exceptionMessage?: string +}; + +export type EmailResult = { + resultCode: string, + recipient: string, + from: string, + subject: string, + text: string +} + +export const sendFeedback = async (feedback: Feedback): Promise => { + const currentUser = await getCurrentUser(); + const endpoint = `${baseUrl}/email/send/feedback`; + return postRequest(endpoint, currentUser.uid, feedback); +} diff --git a/ui/src/services/FetchService.ts b/ui/src/services/FetchService.ts index 37653c77..fd2cfe93 100644 --- a/ui/src/services/FetchService.ts +++ b/ui/src/services/FetchService.ts @@ -64,7 +64,7 @@ export const getRequest = async ( export const postRequest = async ( endpoint: string, currentUserKey: string, - body?: string | string[], + body?: object | string | string[], ): Promise => await fetch(endpoint, { method: 'POST', @@ -130,7 +130,7 @@ export const postRequestRetry = async ( export const putRequest = async ( endpoint: string, currentUserKey: string, - body?: string | string[] + body?: object | string | string[] ): Promise => await fetch(endpoint, { method: 'PUT', @@ -170,7 +170,7 @@ export const putRequestAsync = async ( export const deleteRequest = async ( endpoint: string, currentUserKey: string, - body?: string | string[] + body?: object | string | string[] ): Promise => await fetch(endpoint, { method: 'DELETE', headers: { 'current_user': currentUserKey }, body: JSON.stringify(body) }) .then(res => res.json()) @@ -189,7 +189,7 @@ export const deleteRequest = async ( export const deleteRequestAsync = async ( endpoint: string, currentUserKey: string, - body?: string | string[] + body?: object | string | string[] ): Promise => await fetch(endpoint, { method: 'DELETE', diff --git a/ui/tests/components/layout/footer/Footer.test.tsx b/ui/tests/components/layout/footer/Footer.test.tsx index 22398483..810e8896 100644 --- a/ui/tests/components/layout/footer/Footer.test.tsx +++ b/ui/tests/components/layout/footer/Footer.test.tsx @@ -7,7 +7,8 @@ describe ('Footer', () => { render(