Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mentor Form confirmation #550

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/components/EmojiRain/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ const EmojiRain = () => {
}));

return (
<div className="fixed top-0 left-0 w-full h-full pointer-events-none z-50 overflow-hidden">
{emojis.map((emojiObj) => (
<div
key={emojiObj.id} // Using the unique ID as key
style={{
position: "absolute",
left: `${Math.random() * 100}vw`,
top: `-${Math.random() * 100}vh`,
animation: "fall 5s linear forwards",
}}
>
{emojiObj.emoji}
</div>
))}
</div>
<div className="fixed top-0 left-0 w-full h-full pointer-events-none z-50 overflow-hidden">
{emojis.map((emojiObj) => (
<div
key={emojiObj.id} // Using the unique ID as key
style={{
position: "absolute",
left: `${Math.random() * 100}%`,
top: `${Math.random() * 100}%`,
animation: "fall 5s linear forwards",
}}
>
{emojiObj.emoji}
</div>
))}
</div>
);
};

Expand Down
20 changes: 19 additions & 1 deletion src/components/forms/mentor-form.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import EmojiRain from "@components/EmojiRain";
import { useState } from "react";
import { useForm, SubmitHandler } from "react-hook-form";
import axios from "axios";
import Input from "@ui/form-elements/input";
import Button from "@ui/button";
import { hasKey } from "@utils/methods";
import Feedback from "@ui/form-elements/feedback";

interface IFormValues {
name: string;
Expand All @@ -17,6 +19,8 @@ interface IFormValues {

const MentorForm = () => {
const [message, setMessage] = useState("");
const [showEmojiRain, setShowEmojiRain] = useState<boolean>(false);

const {
register,
handleSubmit,
Expand All @@ -28,6 +32,10 @@ const MentorForm = () => {
try {
await axios.post("/api/mentor", data);
setMessage("Thank you for your registration!");
setShowEmojiRain(true);

setTimeout(() => setShowEmojiRain(false), 5000);

reset();
} catch (error) {
setMessage("Failed to submit the form. Please try again later.");
Expand All @@ -37,7 +45,6 @@ const MentorForm = () => {
return (
<div className="tw-px-4 md:tw-px-[250px]">
<h3 className="tw-text-h2 tw-mb-5">Register</h3>
{message && <p>{message}</p>}
<form onSubmit={handleSubmit(onSubmit)} noValidate>
<div className="tw-mb-7.5">
<label
Expand All @@ -49,6 +56,7 @@ const MentorForm = () => {
<Input
id="name"
placeholder="Jody Grinder"
bg="light"
feedbackText={errors?.name?.message}
state={hasKey(errors, "name") ? "error" : "success"}
showState={!!hasKey(errors, "name")}
Expand All @@ -67,6 +75,7 @@ const MentorForm = () => {
<Input
id="email"
placeholder="[email protected]"
bg="light"
feedbackText={errors?.email?.message}
state={hasKey(errors, "email") ? "error" : "success"}
showState={!!hasKey(errors, "email")}
Expand All @@ -89,6 +98,7 @@ const MentorForm = () => {
<Input
id="branch-of-service"
placeholder="Civilian"
bg="light"
feedbackText={errors?.["branch-of-service"]?.message}
state={
hasKey(errors, "branch-of-service")
Expand All @@ -111,6 +121,7 @@ const MentorForm = () => {
<Input
id="technical-expertise"
placeholder="Javascript, React, Node, etc."
bg="light"
feedbackText={errors?.["technical-expertise"]?.message}
state={
hasKey(errors, "technical-expertise")
Expand All @@ -133,6 +144,7 @@ const MentorForm = () => {
<Input
id="github-portfolio-or-linkedin"
placeholder="github.com/jody-fake-profile"
bg="light"
feedbackText={
errors?.["github-portfolio-or-linkedin"]?.message
}
Expand Down Expand Up @@ -160,6 +172,7 @@ const MentorForm = () => {
<Input
id="location"
placeholder="Washington, DC"
bg="light"
feedbackText={errors?.location?.message}
state={hasKey(errors, "location") ? "error" : "success"}
showState={!!hasKey(errors, "location")}
Expand All @@ -178,6 +191,7 @@ const MentorForm = () => {
<Input
id="employer-restrictions"
placeholder="None"
bg="light"
feedbackText={
errors?.["employer-restrictions"]?.message
}
Expand All @@ -200,6 +214,10 @@ const MentorForm = () => {
>
Register
</Button>
{message && (
<Feedback state="success">{message}</Feedback>
)}
{showEmojiRain && <EmojiRain />}
</form>
</div>
);
Expand Down
Loading