From 87f68d7a784c0e8fdbc6e5bd78d237dd4a3c0794 Mon Sep 17 00:00:00 2001 From: Akhila Sunesh <140897461+AkhilaSunesh@users.noreply.github.com> Date: Mon, 17 Jun 2024 08:38:09 +0530 Subject: [PATCH] done --- src/app/contributors/ContributorsData.ts | 5 + src/components/shared/customerreviews.tsx | 167 ++++++++++++++-------- 2 files changed, 116 insertions(+), 56 deletions(-) diff --git a/src/app/contributors/ContributorsData.ts b/src/app/contributors/ContributorsData.ts index 2fde4dd..eb5d5fe 100644 --- a/src/app/contributors/ContributorsData.ts +++ b/src/app/contributors/ContributorsData.ts @@ -125,4 +125,9 @@ export const ContributorsData = [ github: "https://github.com/Vaibhavsg17", imageUrl: "https://avatars.githubusercontent.com/u/66477893?v=4", }, + { + name: "Akhila Sunesh", + github: "https://github.com/AkhilaSunesh", + imageUrl: "https://avatars.githubusercontent.com/u/140897461?s=400&v=4", + }, ]; diff --git a/src/components/shared/customerreviews.tsx b/src/components/shared/customerreviews.tsx index 3cc822f..aee5169 100644 --- a/src/components/shared/customerreviews.tsx +++ b/src/components/shared/customerreviews.tsx @@ -49,34 +49,47 @@ const testimonials2 = [ ]; const formSchema = z.object({ - name: z.string(), - email: z.string().email(), - feedback: z.string(), + name: z.string().nonempty("Name is required"), + email: z.string().email("Invalid email address"), + feedback: z.string().nonempty("Feedback is required"), + feedbackType: z.string().nonempty("Feedback type is required"), + otherFeedback: z.string().optional(), }); -export function TextareaForm() { - const form = useForm>({ - resolver: zodResolver(formSchema), - }); -} - -function onSubmit(values: z.infer) { - // Do something with the form values. - emailjs.send(process.env.NEXT_PUBLIC_EMAILJS_SERVICE_ID!,process.env.NEXT_PUBLIC_EMAILJS_TEMPLATE_ID!, values,{ - publicKey:process.env.NEXT_PUBLIC_EMAILJS_API_KEY, - }) -} - export default function Review() { + const [showOtherFeedback, setShowOtherFeedback] = React.useState(false); + const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { name: "", email: "", feedback: "", + feedbackType: "", + otherFeedback: "", }, }); - const handleSubmit = () => {}; + + const handleFeedbackTypeChange = (value: string) => { + setShowOtherFeedback(value === "Other"); + }; + + const onSubmit = async (values: z.infer) => { + try { + await emailjs.send( + process.env.NEXT_PUBLIC_EMAILJS_SERVICE_ID!, + process.env.NEXT_PUBLIC_EMAILJS_TEMPLATE_ID!, + values, + process.env.NEXT_PUBLIC_EMAILJS_API_KEY! + ); + alert("Thank you! Your review has been received."); + form.reset(); + } catch (error) { + console.error("Failed to send feedback:", error); + alert("Failed to send feedback. Please try again later."); + } + }; + return (
@@ -93,7 +106,7 @@ export default function Review() { Leave a Review 👇

-
+
{ - return ( - - Full Name - - - - - - ); - }} + render={({ field }) => ( + + Full Name + + + + + + )} /> { - return ( + render={({ field }) => ( + + Email Address + + + + + + )} + /> + + ( + + Feedback Type + + + + + + )} + /> + + {showOtherFeedback && ( + ( - Email Address + Other Feedback - ); - }} - /> + )} + /> + )} { - return ( - - Your Feedback - -