diff --git a/ui/package.json b/ui/package.json index 3d92dd95..0aaed138 100644 --- a/ui/package.json +++ b/ui/package.json @@ -14,7 +14,9 @@ }, "dependencies": { "@radix-ui/react-alert-dialog": "^1.0.5", + "@hookform/resolvers": "^3.3.4", "@radix-ui/react-dialog": "^1.0.5", + "@radix-ui/react-label": "^2.0.2", "@radix-ui/react-slot": "^1.0.2", "@radix-ui/react-tabs": "^1.0.4", "camaro": "^6.2.2", @@ -27,15 +29,19 @@ "react": "^18", "react-dom": "^18", "react-idle-timer": "^5.7.2", + "react-hook-form": "^7.50.1", + "react-router-dom": "^6.22.1", "tailwind-merge": "^2.2.1", "tailwindcss-animate": "^1.0.7", - "uniqid": "^5.4.0" + "uniqid": "^5.4.0", + "zod": "^3.22.4" }, "devDependencies": { "@stylistic/eslint-plugin": "^1.6.1", "@swc/core": "^1.3.106", "@testing-library/jest-dom": "^6.3.0", "@testing-library/react": "^14.1.2", + "@testing-library/user-event": "^14.5.2", "@types/jest": "^29.5.11", "@types/node": "^20", "@types/react": "^18", diff --git a/ui/src/app/feedback/components/FeedbackForm.tsx b/ui/src/app/feedback/components/FeedbackForm.tsx new file mode 100644 index 00000000..286d7230 --- /dev/null +++ b/ui/src/app/feedback/components/FeedbackForm.tsx @@ -0,0 +1,131 @@ +'use client' +import React from 'react'; +import {Input} from '@/components/ui/input'; +import {Button} from '@/components/ui/button' +import {Form, FormControl, FormField, FormItem, FormLabel, FormMessage,} from '@/components/ui/form' +import {z} from 'zod' +import {zodResolver} from '@hookform/resolvers/zod' +import {useForm} from 'react-hook-form' +import {EmailResult, Feedback, sendFeedback} from '@/services/EmailService'; + +const FeedbackForm = ({ currUser, setShowSuccessAlert, setShowErrorAlert } : +{ currUser:string, setShowSuccessAlert:React.Dispatch>, + setShowErrorAlert:React.Dispatch> }) => { + + const formSchema = z.object({ + type: z.string(), + name: z.optional(z.string()), + email: z.string().email(), + message: z.string().min(15), + }) + + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + type: 'General', + email: currUser + '@hawaii.edu' + } + }); + + async function onSubmit(values: z.infer) { + const input: Feedback = { + type: values.type, + name: values.name, + email: values.email, + message: values.message, + exceptionMessage: 'test exception message' + }; + const results = await sendFeedback(input); + const emailResult: EmailResult = { + resultCode: results.resultCode, + recipient: results.recipient, + from: results.from, + subject: results.subject, + text: results.text + }; + + (emailResult.resultCode == 'SUCCESS') ? setShowSuccessAlert(true) : setShowErrorAlert(true); + + if (emailResult.resultCode == 'SUCCESS') { + setShowSuccessAlert(true); + } else { + setShowErrorAlert(true); + } + + //will break without curly braces + form.reset({}); + } + + return ( +
+ <> +
+ + ( + + Feedback Type: + * + + + + + )} + /> + ( + + Your Name (Optional): + + + + + + )} + /> + ( + + Email Address: + * + + + + + + )} + /> + ( + + Your Feedback: + * + +