-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
555 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<React.SetStateAction<boolean>>, | ||
setShowErrorAlert:React.Dispatch<React.SetStateAction<boolean>> }) => { | ||
|
||
const formSchema = z.object({ | ||
type: z.string(), | ||
name: z.optional(z.string()), | ||
email: z.string().email(), | ||
message: z.string().min(15), | ||
}) | ||
|
||
const form = useForm<z.infer<typeof formSchema>>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues: { | ||
type: 'General', | ||
email: currUser + '@hawaii.edu' | ||
} | ||
}); | ||
|
||
async function onSubmit(values: z.infer<typeof formSchema>) { | ||
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 ( | ||
<Form {...form}> | ||
<> | ||
<div className='col-span-7 pl-5 pt-5'> | ||
<form id='feedbackForm' onSubmit={form.handleSubmit(onSubmit)} className='space-y-8'> | ||
<FormField control={form.control} name='type' | ||
render={({field}) => ( | ||
<FormItem> | ||
<FormLabel htmlFor='type' className='text-base'>Feedback Type: | ||
<span className='text-red-500'>*</span></FormLabel> | ||
<FormControl> | ||
<select id='type' | ||
className='w-full px-3 py-1 border | ||
border-gray-300 rounded-md focus:accent-blue-500 | ||
focus:border-blue-500' {...field}> | ||
<option value='General' defaultValue='true'>General</option> | ||
<option value='Problem'>Problem</option> | ||
<option value='Feature'>Feature</option> | ||
<option value='Question'>Question</option> | ||
</select> | ||
</FormControl> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField control={form.control} name='name' | ||
render={({field}) => ( | ||
<FormItem> | ||
<FormLabel htmlFor='name' className='text-base'>Your Name (Optional):</FormLabel> | ||
<FormControl> | ||
<Input id='name' className='text-base' placeholder='John Doe' {...field} /> | ||
</FormControl> | ||
<FormMessage/> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField control={form.control} name='email' | ||
render={({field}) => ( | ||
<FormItem> | ||
<FormLabel htmlFor='email' className='text-base'>Email Address: | ||
<span className='text-red-500'>*</span></FormLabel> | ||
<FormControl> | ||
<Input id='email' className='text-base' | ||
placeholder='Enter your email here' {...field} /> | ||
</FormControl> | ||
<FormMessage/> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField control={form.control} name='message' | ||
render={({field}) => ( | ||
<FormItem> | ||
<FormLabel htmlFor='message' className='text-base'>Your Feedback: | ||
<span className='text-red-500'>*</span></FormLabel> | ||
<FormControl> | ||
<textarea id='message' className='w-full px-3 py-1 border | ||
border-gray-300 rounded-md' rows={6} {...field} /> | ||
</FormControl> | ||
<FormMessage/> | ||
</FormItem> | ||
)} | ||
/> | ||
<Button className='text-white bg-uh-teal hover:bg-green-blue focus:ring-4 | ||
focus:ring-blue-300 rounded-md text-base dark:bg-blue-600 | ||
dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800 shadow-2xl' | ||
type='submit'>Submit</Button> | ||
</form> | ||
</div> | ||
</> | ||
</Form> | ||
) | ||
} | ||
|
||
export default FeedbackForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use client' | ||
import React, {useState} from 'react'; | ||
import ErrorAlert from '@/components/layout/alerts/ErrorAlert'; | ||
import SuccessAlert from '@/components/layout/alerts/SuccessAlert'; | ||
import FeedbackForm from '@/app/feedback/components/FeedbackForm'; | ||
import {getCurrentUser} from '@/access/AuthenticationService'; | ||
|
||
async function getUser() { | ||
return await getCurrentUser(); | ||
} | ||
const Feedback = () => { | ||
const [showSuccessAlert, setShowSuccessAlert] = useState(false); | ||
const [showErrorAlert, setShowErrorAlert] = useState(false); | ||
|
||
const [userUid, setUserUid] = useState<string>(''); | ||
|
||
// Calling an async function to get the user's uid | ||
getUser().then(res => setUserUid(res.uid)) | ||
|
||
return ( | ||
<> | ||
<div id="successAlert" hidden={!showSuccessAlert} className="container"> | ||
<SuccessAlert isActive={showSuccessAlert}></SuccessAlert> | ||
</div> | ||
<div id="errorAlert" hidden={!showErrorAlert} className="container"> | ||
<ErrorAlert isActive={showErrorAlert}></ErrorAlert> | ||
</div> | ||
<div className="container grid grid-cols-12 pt-5 pb-4"> | ||
<div className="col-span-5 pt-5"> | ||
<h1 className="text-md-left text-3xl font-bold">Feedback</h1> | ||
<p className="text-md-left text-xl mt-3"> | ||
Helps us to understand where improvements are needed. Please let us know.</p> | ||
</div> | ||
<div className="col-span-7 pl-5 pt-5"> | ||
<FeedbackForm currUser={userUid} setShowSuccessAlert={setShowSuccessAlert} | ||
setShowErrorAlert={setShowErrorAlert} ></FeedbackForm> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default Feedback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
Alert, | ||
AlertDescription, | ||
AlertTitle, | ||
} from '@/components/ui/alert' | ||
import {XCircle} from 'lucide-react'; | ||
import React from 'react'; | ||
|
||
export const ErrorAlert = ({ isActive } : { isActive:boolean }) => { | ||
return ( | ||
<section className="errorAlert"> | ||
{isActive ? ( | ||
<Alert variant="destructive" className="bg-red-100"> | ||
<XCircle className="h-4 w-4" /> | ||
<AlertTitle>Error</AlertTitle> | ||
<AlertDescription className="text-base text-red-500"> | ||
Email feedback was unsuccessful. Please try again. | ||
</AlertDescription> | ||
</Alert> | ||
) : null } | ||
</section> | ||
)} | ||
|
||
export default ErrorAlert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
Alert, | ||
AlertDescription, | ||
AlertTitle, | ||
} from '@/components/ui/alert' | ||
import {CheckCircle2} from 'lucide-react'; | ||
import React from 'react'; | ||
|
||
export const SuccessAlert = ({ isActive } : { isActive:boolean }) => { | ||
return ( | ||
<section className="successAlert"> | ||
{isActive ? ( | ||
<Alert variant="default" className="bg-green-100"> | ||
<CheckCircle2 className="h-4 w-4" /> | ||
<AlertTitle>Thank you!</AlertTitle> | ||
<AlertDescription> | ||
<div className="text-base alert-success-test-color"> | ||
Your feedback has successfully been submitted. | ||
</div> | ||
</AlertDescription> | ||
</Alert> | ||
) : null } | ||
</section> | ||
)} | ||
|
||
export default SuccessAlert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.