diff --git a/src/app/business/apply/page.tsx b/src/app/business/apply/page.tsx index d366983..f423147 100644 --- a/src/app/business/apply/page.tsx +++ b/src/app/business/apply/page.tsx @@ -36,8 +36,8 @@ export default function Apply() { .string({ required_error: "Please provide a brief description for your project", }) - .min(40, { - message: "Short description must be at least 40 characters.", + .min(10, { + message: "Short description must be at least 10 characters.", }), projectPitchDeck: pitchDeckSchema, projectLogo: z @@ -133,23 +133,7 @@ export default function Apply() { businessPitchDeck: pitchDeckSchema, }); let supabase = createSupabaseClient(); - const { - register: registerBusiness, - handleSubmit: handleSubmitBusiness, - setValue: setValueBusiness, - formState: { errors: errorsBusiness }, - } = useForm({ - resolver: zodResolver(businessFormSchema), - }); - const { - register: registerProject, - handleSubmit: handleSubmitProject, - setValue: setValueProject, - formState: { errors: errorsProject }, - } = useForm({ - resolver: zodResolver(projectFormSchema), - }); const [industry, setIndustry] = useState([]); const [isInUS, setIsInUS] = useState(""); const [isForSale, setIsForSale] = useState(""); @@ -159,6 +143,23 @@ export default function Apply() { const [projectPitch, setProjectPitch] = useState(""); const [applyProject, setApplyProject] = useState(false); const [selectedImages, setSelectedImages] = useState([]); + const { + register, + handleSubmit, + setValue, + setValue: setValueBusiness, + formState: { errors: errorsBusiness }, + } = useForm({ + resolver: zodResolver(businessFormSchema), + }); + const { + register: registerSecondForm, + handleSubmit: handleSecondSubmit, + formState: { errors: errorsProject }, + setValue: setValueProject, + } = useForm({ + resolver: zodResolver(projectFormSchema), + }); const communitySize = [ "N/A", @@ -171,11 +172,11 @@ export default function Apply() { ]; useEffect(() => { - registerBusiness("industry"); - registerBusiness("isInUS"); - registerBusiness("isForSale"); - registerBusiness("isGenerating"); - }, [registerBusiness]); + register("industry"); + register("isInUS"); + register("isForSale"); + register("isGenerating"); + }, [register]); const handleRemoveImage = (index: number) => { const updatedImages = selectedImages.filter((_, i) => i !== index); @@ -185,10 +186,11 @@ export default function Apply() { if (event.target.files) { const filesArray = Array.from(event.target.files); setSelectedImages((prevImages) => [...prevImages, ...filesArray]); + setValueProject("projectPhotos", filesArray); } }; - const onSubmit = (data: any) => { + const transformChoice = (data: any) => { // console.table(data); // convert any yes and no to true or false const transformedData = Object.entries(data).reduce( @@ -209,13 +211,7 @@ export default function Apply() { }, {} ); - if (data.pitchDeck instanceof File) { - console.log("File Uploaded:", data.pitchDeck.name); - } else { - console.log("URL Provided:", data.pitchDeck); - } - console.table(transformedData); - alert(JSON.stringify(transformedData)); + return transformedData; }; const handleBusinessPitchChange = (type: string) => { setBusinessPitch(type); @@ -223,7 +219,7 @@ export default function Apply() { setValueBusiness("pitchDeck", ""); }; - const handleFieldChange = (fieldName: string, value: any) => { + const handleBusinessFieldChange = (fieldName: string, value: any) => { switch (fieldName) { case "isInUS": setIsInUS(value); @@ -237,6 +233,12 @@ export default function Apply() { } setValueBusiness(fieldName, value); }; + const handleProjectFieldChange = (fieldName: string, value: any) => { + switch (fieldName) { + } + setValueProject(fieldName, value); + }; + const fetchIndustry = async () => { let { data: BusinessType, error } = await supabase .from("BusinessType") @@ -251,6 +253,27 @@ export default function Apply() { } } }; + + const onSubmitSingleForm = (data: any) => { + alert(JSON.stringify(data)); + }; + + const onSubmitBothForms = (firstFormData: any, secondFormData: any) => { + alert(JSON.stringify(firstFormData)); + alert(JSON.stringify(secondFormData)); + console.log("Both forms submitted:", { firstFormData, secondFormData }); + }; + + const handleSubmitForms = (firstFormData: any) => { + const transformedData = transformChoice(firstFormData); + if (applyProject) { + handleSecondSubmit((secondFormData: any) => { + onSubmitBothForms(transformedData, secondFormData); + })(); + } else { + onSubmitSingleForm(transformedData); + } + }; const fetchProjectType = async () => { let { data: ProjectType, error } = await supabase .from("ProjectType") @@ -287,7 +310,7 @@ export default function Apply() { {/* form */} -
+

About your company

@@ -306,7 +329,7 @@ export default function Apply() { type="text" id="companyName" className="w-96" - {...registerBusiness("companyName")} + {...register("companyName")} /> This should be the name your company uses on your
@@ -329,7 +352,7 @@ export default function Apply() { header={<>Industry} fieldName="industry" choices={industry} - handleFunction={handleFieldChange} + handleFunction={handleBusinessFieldChange} description={ <>Choose the industry that best aligns with your business. } @@ -352,7 +375,7 @@ export default function Apply() { id="totalRaised" className="w-96" placeholder="$ 1,000,000" - {...registerBusiness("totalRaised", { + {...register("totalRaised", { valueAsNumber: true, })} /> @@ -379,7 +402,7 @@ export default function Apply() { name="isInUS" choice1="Yes" choice2="No" - handleFunction={handleFieldChange} + handleFunction={handleBusinessFieldChange} description={ <> Only companies that are incorporated or formed in the US are{" "} @@ -408,7 +431,7 @@ export default function Apply() { name="isForSale" choice1="Yes" choice2="No" - handleFunction={handleFieldChange} + handleFunction={handleBusinessFieldChange} description={ <> Only check this box if customers can access, use, or buy your{" "} @@ -430,7 +453,7 @@ export default function Apply() { name="isGenerating" choice1="Yes" choice2="No" - handleFunction={handleFieldChange} + handleFunction={handleBusinessFieldChange} description={ <> Only check this box if your company is making money.
@@ -478,7 +501,7 @@ export default function Apply() { : "https:// " } accept={businessPitch === "file" ? ".md" : undefined} - {...registerBusiness("businessPitchDeck", { required: true })} + {...register("businessPitchDeck", { required: true })} /> @@ -508,7 +531,7 @@ export default function Apply() { } fieldName="communitySize" choices={communitySize} - handleFunction={handleFieldChange} + handleFunction={handleBusinessFieldChange} description={ <> {" "} @@ -555,231 +578,289 @@ export default function Apply() { {/* apply first project */} {applyProject && (

- - {/* header */} -
-

- Begin Your First Fundraising Project -

-

- Starting a fundraising project is mandatory for all - businesses. This step is crucial
- to begin your journey and unlock the necessary tools for - raising funds. -

+ {/* header */} +
+

+ Begin Your First Fundraising Project +

+

+ Starting a fundraising project is mandatory for all businesses. + This step is crucial
+ to begin your journey and unlock the necessary tools for raising + funds. +

- {/* project's name */} -
- -
- -
-
- - {/* project type */} - Project type} - fieldName="projectType" - choices={projectType} - handleFunction={handleFieldChange} - description={ - <>Please specify the primary purpose of the funds - } - placeholder="Select a Project type" - selectLabel="Project type" - /> - - {/* short description */} -
- -
-