From a064689aced498a1c110d6a2570736c0afedb387 Mon Sep 17 00:00:00 2001 From: Aakashuu Date: Sat, 20 Jul 2024 20:18:51 +0530 Subject: [PATCH 1/3] feat: Implemented Sign Up Organsiation Page for isse 15 --- app/routes/OrganizationSignUpPage.tsx | 291 ++++++++++++++++++++++++++ 1 file changed, 291 insertions(+) create mode 100644 app/routes/OrganizationSignUpPage.tsx diff --git a/app/routes/OrganizationSignUpPage.tsx b/app/routes/OrganizationSignUpPage.tsx new file mode 100644 index 00000000..72c10ad8 --- /dev/null +++ b/app/routes/OrganizationSignUpPage.tsx @@ -0,0 +1,291 @@ +import { MetaFunction, ActionFunction, json } from "@remix-run/node"; +import { Link, Form, useActionData } from "@remix-run/react"; +import { useState } from "react"; +import { Button } from "~/components/ui/button"; + +// Define the types for the form fields +interface FormData { + companyName: string; + companyEmail: string; + industry: string; + organizationType: string; + country: string; + state: string; + address: string; + lga: string; +} + +interface FormErrors { + companyName?: string; + companyEmail?: string; + industry?: string; + organizationType?: string; + country?: string; + state?: string; + address?: string; + lga?: string; +} + +export const meta: MetaFunction = () => { + return [{ title: "Sign Up" }]; +}; + +export const action: ActionFunction = async ({ request }) => { + const formData = await request.formData(); + const data = Object.fromEntries(formData) as unknown as FormData; + + const errors = validateForm(data); + if (Object.keys(errors).length > 0) { + return json({ errors }, { status: 400 }); + } + + console.log(data); + + // Process the valid data (e.g., save to database) + // ... + + return json({ success: true }); +}; + +const validateForm = (data: FormData): FormErrors => { + const errors: FormErrors = {}; + if (!data.companyName) { + errors.companyName = "Company name is required."; + } + if (!data.companyEmail) { + errors.companyEmail = "Company email is required."; + } else if (!/\S+@\S+\.\S+/.test(data.companyEmail)) { + errors.companyEmail = "Email address is invalid."; + } else { + delete errors.companyEmail; + } + if (!data.industry) { + errors.industry = "Industry is required."; + } + if (!data.organizationType) { + errors.organizationType = "Organization type is required."; + } + if (!data.country) { + errors.country = "Country is required."; + } + if (!data.state) { + errors.state = "State is required."; + } + if (!data.address) { + errors.address = "Address is required."; + } + if (!data.lga) { + errors.lga = "LGA is required."; + } + return errors; +}; + +export default function Signup() { + const actionData = useActionData<{ errors?: FormErrors; success?: boolean }>(); + const [clientErrors, setClientErrors] = useState({}); + const [formData, setFormData] = useState({ + companyName: "", + companyEmail: "", + industry: "", + organizationType: "", + country: "", + state: "", + address: "", + lga: "", + }); + + const handleInputChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setFormData({ ...formData, [name]: value }); + + if (name === 'companyEmail' && /\S+@\S+\.\S+/.test(value)) { + const newErrors = { ...clientErrors }; + delete newErrors.companyEmail; + setClientErrors(newErrors); + } else if (clientErrors[name as keyof FormErrors]) { + const newErrors = { ...clientErrors }; + delete newErrors[name as keyof FormErrors]; + setClientErrors(newErrors); + } + }; + + + const handleSubmit = (event: React.FormEvent) => { + const form = event.currentTarget; + const formData = new FormData(form); + const data = Object.fromEntries(formData) as unknown as FormData; + const errors = validateForm(data); + + if (Object.keys(errors).length > 0) { + event.preventDefault(); + setClientErrors(errors); + } + + console.log(data) + }; + + return ( + <> +
+
+

Create Organisation Account

+

Sign up

+

Create an account to get started with us.

+
+
+ + + {(clientErrors.companyName || actionData?.errors?.companyName) &&

{clientErrors.companyName || actionData?.errors?.companyName}

} +
+
+ + + {(clientErrors.companyEmail || actionData?.errors?.companyEmail) &&

{clientErrors.companyEmail || actionData?.errors?.companyEmail}

} +
+
+
+ + + {(clientErrors.industry || actionData?.errors?.industry) &&

{clientErrors.industry || actionData?.errors?.industry}

} +
+
+ + + {(clientErrors.organizationType || actionData?.errors?.organizationType) &&

{clientErrors.organizationType || actionData?.errors?.organizationType}

} +
+
+
+

Company Address

+
+
+
+ + + {(clientErrors.country || actionData?.errors?.country) &&

{clientErrors.country || actionData?.errors?.country}

} +
+
+ + + {(clientErrors.state || actionData?.errors?.state) &&

{clientErrors.state || actionData?.errors?.state}

} +
+
+ + + {(clientErrors.address || actionData?.errors?.address) &&

{clientErrors.address || actionData?.errors?.address}

} +
+
+ + + {(clientErrors.lga || actionData?.errors?.lga) &&

{clientErrors.lga || actionData?.errors?.lga}

} +
+
+ +
+

Already Have An Account?Login

+
+
+
+
+ + ); +} From 50e212f0b88e85ecd222019a516541170b91be0f Mon Sep 17 00:00:00 2001 From: Aakash kumar <76447347+itsAakashz@users.noreply.github.com> Date: Sun, 21 Jul 2024 00:19:11 +0530 Subject: [PATCH 2/3] feat: Implemented Sign Up Organsiation Page for isse 15 --- app/routes/OrganizationSignUpPage.tsx | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/routes/OrganizationSignUpPage.tsx b/app/routes/OrganizationSignUpPage.tsx index 72c10ad8..d676fa70 100644 --- a/app/routes/OrganizationSignUpPage.tsx +++ b/app/routes/OrganizationSignUpPage.tsx @@ -2,6 +2,8 @@ import { MetaFunction, ActionFunction, json } from "@remix-run/node"; import { Link, Form, useActionData } from "@remix-run/react"; import { useState } from "react"; import { Button } from "~/components/ui/button"; +import { Label } from "~/components/ui/label"; +import { Input } from "~/components/ui/input"; // Define the types for the form fields interface FormData { @@ -39,10 +41,8 @@ export const action: ActionFunction = async ({ request }) => { return json({ errors }, { status: 400 }); } - console.log(data); - // Process the valid data (e.g., save to database) - // ... + return json({ success: true }); }; @@ -128,13 +128,13 @@ export default function Signup() { <>
-

Create Organisation Account

+

Create Organisation Account

Sign up

Create an account to get started with us.

- - Company's Name + {clientErrors.companyName || actionData?.errors?.companyName}

}
- - Company's Email Address +
- +
- + {clientErrors.state || actionData?.errors?.state}

}
- - Address + {clientErrors.address || actionData?.errors?.address}

}
- + - {(clientErrors.companyName || actionData?.errors?.companyName) &&

{clientErrors.companyName || actionData?.errors?.companyName}

} + {(clientErrors.companyName || + actionData?.errors?.companyName) && ( +

+ {clientErrors.companyName || actionData?.errors?.companyName} +

+ )}
- + - {(clientErrors.companyEmail || actionData?.errors?.companyEmail) &&

{clientErrors.companyEmail || actionData?.errors?.companyEmail}

} + {(clientErrors.companyEmail || + actionData?.errors?.companyEmail) && ( +

+ {clientErrors.companyEmail || + actionData?.errors?.companyEmail} +

+ )}
-
+
- + - {(clientErrors.industry || actionData?.errors?.industry) &&

{clientErrors.industry || actionData?.errors?.industry}

} + {(clientErrors.industry || actionData?.errors?.industry) && ( +

+ {clientErrors.industry || actionData?.errors?.industry} +

+ )}
- + - {(clientErrors.organizationType || actionData?.errors?.organizationType) &&

{clientErrors.organizationType || actionData?.errors?.organizationType}

} + {(clientErrors.organizationType || + actionData?.errors?.organizationType) && ( +

+ {clientErrors.organizationType || + actionData?.errors?.organizationType} +

+ )}
-

Company Address

+

+ Company Address +

-
+
- + - {(clientErrors.country || actionData?.errors?.country) &&

{clientErrors.country || actionData?.errors?.country}

} + {(clientErrors.country || actionData?.errors?.country) && ( +

+ {clientErrors.country || actionData?.errors?.country} +

+ )}
- + - {(clientErrors.state || actionData?.errors?.state) &&

{clientErrors.state || actionData?.errors?.state}

} + {(clientErrors.state || actionData?.errors?.state) && ( +

+ {clientErrors.state || actionData?.errors?.state} +

+ )}
- + - {(clientErrors.address || actionData?.errors?.address) &&

{clientErrors.address || actionData?.errors?.address}

} + {(clientErrors.address || actionData?.errors?.address) && ( +

+ {clientErrors.address || actionData?.errors?.address} +

+ )}
- + - {(clientErrors.lga || actionData?.errors?.lga) &&

{clientErrors.lga || actionData?.errors?.lga}

} + {(clientErrors.lga || actionData?.errors?.lga) && ( +

+ {clientErrors.lga || actionData?.errors?.lga} +

+ )}
-

Already Have An Account?Login

+

+ Already Have An Account? + + Login + +