mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-19 05:54:06 +01:00
Refactor projectFormSchema in application.schema.ts
This commit is contained in:
parent
d6c967f0b4
commit
0e25a210fe
@ -1,310 +1,26 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import ProjectForm from "@/components/ProjectForm";
|
||||
import { projectFormSchema } from "@/types/schemas/application.schema";
|
||||
import { z } from "zod";
|
||||
import { SubmitHandler } from "react-hook-form";
|
||||
|
||||
type projectSchema = z.infer<typeof projectFormSchema>;
|
||||
export default function ApplyProject() {
|
||||
const [projectType, setProjectType] = useState<string[]>([]);
|
||||
const [projectPitch, setProjectPitch] = useState("text");
|
||||
const [applyProject, setApplyProject] = useState(false);
|
||||
const [selectedImages, setSelectedImages] = useState<File[]>([]);
|
||||
const [projectPitchFile, setProjectPitchFile] = useState("");
|
||||
|
||||
const onSubmit: SubmitHandler<projectSchema> = async (data) => {
|
||||
alert("มาแน้ววว");
|
||||
console.table(data);
|
||||
};
|
||||
return (
|
||||
<div>
|
||||
{" "}
|
||||
<div className="grid auto-rows-max w-3/4 ml-48 bg-zinc-100 dark:bg-zinc-900 mt-10 pt-12 pb-12">
|
||||
{/* header */}
|
||||
<div className="ml-[15%]">
|
||||
<h1 className="text-3xl font-bold mt-10">
|
||||
Begin Your First Fundraising Project
|
||||
</h1>
|
||||
<p className="mt-3 text-sm text-neutral-500">
|
||||
Starting a fundraising project is mandatory for all businesses. This
|
||||
step is crucial <br />
|
||||
to begin your journey and unlock the necessary tools for raising
|
||||
funds.
|
||||
</p>
|
||||
{/* project's name */}
|
||||
<div className="mt-10 space-y-5">
|
||||
<Label htmlFor="projectName" className="font-bold text-lg">
|
||||
Project name
|
||||
</Label>
|
||||
<div className="flex space-x-5">
|
||||
<Input
|
||||
type="text"
|
||||
id="projectName"
|
||||
className="w-96"
|
||||
{...registerSecondForm("projectName")}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{errorsProject.projectName && (
|
||||
<p className="text-red-500 text-sm">
|
||||
{errorsProject.projectName.message as string}
|
||||
</p>
|
||||
)}
|
||||
{/* project type */}
|
||||
{/* <MultipleOptionSelector
|
||||
header={<>Project type</>}
|
||||
fieldName="projectType"
|
||||
choices={projectType}
|
||||
// handleFunction={handleProjectFieldChange}
|
||||
description={<>Please specify the primary purpose of the funds</>}
|
||||
placeholder="Select a Project type"
|
||||
selectLabel="Project type"
|
||||
/> */}
|
||||
{errorsProject.projectType && (
|
||||
<p className="text-red-500 text-sm">
|
||||
{errorsProject.projectType.message as string}
|
||||
</p>
|
||||
)}
|
||||
{/* short description */}
|
||||
<div className="mt-10 space-y-5">
|
||||
<Label htmlFor="shortDescription" className="font-bold text-lg">
|
||||
Short description
|
||||
</Label>
|
||||
<div className="flex space-x-5">
|
||||
<Textarea
|
||||
id="shortDescription"
|
||||
className="w-96"
|
||||
{...registerSecondForm("shortDescription")}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
Could you provide a brief description of your project <br /> in
|
||||
one or two sentences?
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{errorsProject.shortDescription && (
|
||||
<p className="text-red-500 text-sm">
|
||||
{errorsProject.shortDescription.message as string}
|
||||
</p>
|
||||
)}
|
||||
{/* Pitch deck */}
|
||||
<div className="mt-10 space-y-5">
|
||||
<Label htmlFor="projectPitchDeck" className="font-bold text-lg">
|
||||
Pitch deck
|
||||
</Label>
|
||||
<div className="flex space-x-2 w-96">
|
||||
<Button
|
||||
type="button"
|
||||
variant={projectPitch === "text" ? "default" : "outline"}
|
||||
onClick={() => setProjectPitch("text")}
|
||||
className="w-32 h-12 text-base"
|
||||
>
|
||||
Paste URL
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={projectPitch === "file" ? "default" : "outline"}
|
||||
onClick={() => setProjectPitch("file")}
|
||||
className="w-32 h-12 text-base"
|
||||
>
|
||||
Upload a file
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex space-x-5">
|
||||
<Input
|
||||
type={projectPitch}
|
||||
id="projectPitchDeck"
|
||||
className="w-96"
|
||||
placeholder={
|
||||
projectPitch === "file"
|
||||
? "Upload your Markdown file"
|
||||
: "https:// "
|
||||
}
|
||||
accept={projectPitch === "file" ? ".md" : undefined}
|
||||
{...(projectPitch === "text"
|
||||
? registerSecondForm("projectPitchDeck", {
|
||||
required: true,
|
||||
})
|
||||
: {
|
||||
onChange: (e) => {
|
||||
const file = e.target.files?.[0];
|
||||
setValueProject("projectPitchDeck", file);
|
||||
setProjectPitchFile(file?.name || "");
|
||||
},
|
||||
})}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
Please upload a file or paste a link to your pitch, which should{" "}
|
||||
<br />
|
||||
cover key aspects of your project: what it will do, what
|
||||
investors <br /> can expect to gain, and any highlights that
|
||||
make it stand out.
|
||||
</span>
|
||||
</div>
|
||||
{projectPitchFile && (
|
||||
<div className="flex justify-between items-center border p-2 rounded w-96 text-sm text-foreground">
|
||||
<span>1. {projectPitchFile}</span>
|
||||
<Button
|
||||
className="ml-4"
|
||||
onClick={() => {
|
||||
setValueProject("projectPitchDeck", "");
|
||||
setProjectPitchFile("");
|
||||
}}
|
||||
>
|
||||
Remove
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{errorsProject.projectPitchDeck && (
|
||||
<p className="text-red-500 text-sm">
|
||||
{errorsProject.projectPitchDeck.message as string}
|
||||
</p>
|
||||
)}
|
||||
{/* project logo */}
|
||||
<div className="mt-10 space-y-5">
|
||||
<Label htmlFor="projectLogo" className="font-bold text-lg mt-10">
|
||||
Project logo
|
||||
</Label>
|
||||
<div className="flex space-x-5">
|
||||
<Input
|
||||
type="file"
|
||||
id="projectLogo"
|
||||
className="w-96"
|
||||
accept="image/*"
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
registerSecondForm("projectLogo").onChange({
|
||||
target: { name: "projectLogo", value: file },
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
Please upload the logo picture that best represents your
|
||||
project.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{errorsProject.projectLogo && (
|
||||
<p className="text-red-500 text-sm">
|
||||
{errorsProject.projectLogo.message as string}
|
||||
</p>
|
||||
)}
|
||||
<div className="mt-10 space-y-5">
|
||||
<Label htmlFor="projectPhotos" className="font-bold text-lg mt-10">
|
||||
Project photos
|
||||
</Label>
|
||||
<div className="flex space-x-5">
|
||||
<Input
|
||||
type="file"
|
||||
id="projectPhotos"
|
||||
multiple
|
||||
accept="image/*"
|
||||
className="w-96"
|
||||
{...registerSecondForm("projectPhotos", {
|
||||
required: true,
|
||||
onChange: handleFileChange,
|
||||
})}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
Feel free to upload any additional images that provide <br />
|
||||
further insight into your project.
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-5 space-y-2 w-96">
|
||||
{selectedImages.map((image, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="flex justify-between items-center border p-2 rounded"
|
||||
>
|
||||
<span>{image.name}</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => handleRemoveImage(index)}
|
||||
className="ml-4"
|
||||
type="reset"
|
||||
>
|
||||
Remove
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{errorsProject.projectPhotos && (
|
||||
<p className="text-red-500 text-sm">
|
||||
{errorsProject.projectPhotos.message as string}
|
||||
</p>
|
||||
)}
|
||||
{/* Minimum Investment */}
|
||||
<div className="space-y-5 mt-10">
|
||||
<Label htmlFor="minInvest" className="font-bold text-lg">
|
||||
Minimum investment
|
||||
</Label>
|
||||
<div className="flex space-x-5">
|
||||
<Input
|
||||
type="number"
|
||||
id="minInvest"
|
||||
className="w-96"
|
||||
placeholder="$ 500"
|
||||
{...registerSecondForm("minInvest", {
|
||||
valueAsNumber: true,
|
||||
})}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
This helps set clear expectations for investors
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{errorsProject.minInvest && (
|
||||
<p className="text-red-500 text-sm">
|
||||
{errorsProject.minInvest.message as string}
|
||||
</p>
|
||||
)}
|
||||
{/* Target Investment */}
|
||||
<div className="space-y-5 mt-10">
|
||||
<Label htmlFor="targetInvest" className="font-bold text-lg">
|
||||
Target investment
|
||||
</Label>
|
||||
<div className="flex space-x-5">
|
||||
<Input
|
||||
type="number"
|
||||
id="targetInvest"
|
||||
className="w-96"
|
||||
placeholder="$ 1,000,000"
|
||||
{...registerSecondForm("targetInvest", {
|
||||
valueAsNumber: true,
|
||||
})}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
We encourage you to set a specific target investment <br />{" "}
|
||||
amount that reflects your funding goals.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{errorsProject.targetInvest && (
|
||||
<p className="text-red-500 text-sm">
|
||||
{errorsProject.targetInvest.message as string}
|
||||
</p>
|
||||
)}
|
||||
{/* Deadline */}
|
||||
<div className="space-y-5 mt-10">
|
||||
<Label htmlFor="deadline" className="font-bold text-lg">
|
||||
Deadline
|
||||
</Label>
|
||||
<div className="flex space-x-5">
|
||||
<Input
|
||||
type="datetime-local"
|
||||
id="deadline"
|
||||
className="w-96"
|
||||
{...registerSecondForm("deadline")}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
What is the deadline for your fundraising project? Setting{" "}
|
||||
<br /> a clear timeline can help motivate potential investors.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{errorsProject.deadline && (
|
||||
<p className="text-red-500 text-sm">
|
||||
{errorsProject.deadline.message as string}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<ProjectForm onSubmit={onSubmit} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { SubmitHandler, useForm } from "react-hook-form";
|
||||
import { SubmitHandler, useForm, ControllerRenderProps } from "react-hook-form";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DualOptionSelector } from "@/components/dualSelector";
|
||||
import { MultipleOptionSelector } from "@/components/multipleSelector";
|
||||
import {
|
||||
Form,
|
||||
@ -16,17 +15,11 @@ import { projectFormSchema } from "@/types/schemas/application.schema";
|
||||
import { z } from "zod";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@radix-ui/react-tooltip";
|
||||
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
||||
import { Textarea } from "./ui/textarea";
|
||||
|
||||
type projectSchema = z.infer<typeof projectFormSchema>;
|
||||
type FieldType = ControllerRenderProps<any, "projectPhotos">;
|
||||
|
||||
interface ProjectFormProps {
|
||||
onSubmit: SubmitHandler<projectSchema>;
|
||||
@ -43,26 +36,31 @@ const ProjectForm = ({
|
||||
{ id: number; name: string }[]
|
||||
>([]);
|
||||
const [projectPitch, setProjectPitch] = useState("text");
|
||||
const [applyProject, setApplyProject] = useState(false);
|
||||
const [selectedImages, setSelectedImages] = useState<File[]>([]);
|
||||
const [projectPitchFile, setProjectPitchFile] = useState("");
|
||||
|
||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const handleFileChange = (
|
||||
event: React.ChangeEvent<HTMLInputElement>,
|
||||
field: FieldType
|
||||
) => {
|
||||
if (event.target.files) {
|
||||
const filesArray = Array.from(event.target.files);
|
||||
console.log("first file", filesArray);
|
||||
setSelectedImages((prevImages) => {
|
||||
const updatedImages = [...prevImages, ...filesArray];
|
||||
console.log("Updated Images Array:", updatedImages);
|
||||
field.onChange(updatedImages);
|
||||
return updatedImages;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveImage = (index: number) => {
|
||||
const handleRemoveImage = (index: number, field: FieldType) => {
|
||||
setSelectedImages((prevImages) => {
|
||||
const updatedImages = prevImages.filter((_, i) => i !== index);
|
||||
console.log("After removal - Updated Images:", updatedImages);
|
||||
field.onChange(updatedImages);
|
||||
|
||||
return updatedImages;
|
||||
});
|
||||
};
|
||||
@ -86,7 +84,7 @@ const ProjectForm = ({
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
fetchProjectType;
|
||||
fetchProjectType();
|
||||
}, []);
|
||||
return (
|
||||
<Form {...form}>
|
||||
@ -94,7 +92,6 @@ const ProjectForm = ({
|
||||
onSubmit={form.handleSubmit(onSubmit as SubmitHandler<projectSchema>)}
|
||||
className="space-y-8"
|
||||
>
|
||||
<div className="ml-[15%]">
|
||||
<h1 className="text-3xl font-bold mt-10">
|
||||
Begin Your First Fundraising Project
|
||||
</h1>
|
||||
@ -319,11 +316,13 @@ const ProjectForm = ({
|
||||
multiple
|
||||
accept="image/*"
|
||||
className="w-96"
|
||||
onChange={handleFileChange}
|
||||
onChange={(event) => {
|
||||
handleFileChange(event, field);
|
||||
}}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
Please upload the logo picture that best represents
|
||||
your project.
|
||||
Please upload the logo picture that best represents your
|
||||
project.
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-5 space-y-2 w-96">
|
||||
@ -335,7 +334,7 @@ const ProjectForm = ({
|
||||
<span>{image.name}</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => handleRemoveImage(index)}
|
||||
onClick={() => handleRemoveImage(index, field)}
|
||||
className="ml-4"
|
||||
type="reset"
|
||||
>
|
||||
@ -351,56 +350,103 @@ const ProjectForm = ({
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Community Size */}
|
||||
{/* Minimum investment */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="communitySize"
|
||||
render={({ field }) => (
|
||||
name="minInvest"
|
||||
render={({ field }: { field: any }) => (
|
||||
<FormItem>
|
||||
<div className="mt-10 space-y-5">
|
||||
<FormLabel className="font-bold text-lg">
|
||||
Minimum investment
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<MultipleOptionSelector
|
||||
header={<>What's the rough size of your community?</>}
|
||||
fieldName="communitySize"
|
||||
choices={communitySize}
|
||||
handleFunction={(selectedValues: any) => {
|
||||
field.onChange(selectedValues.name);
|
||||
<div className="flex space-x-5">
|
||||
<Input
|
||||
type="number"
|
||||
id="minInvest"
|
||||
placeholder="$ 500"
|
||||
className="w-96"
|
||||
{...field}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
field.onChange(value ? parseFloat(value) : null);
|
||||
}}
|
||||
description={
|
||||
<>
|
||||
Include your email list, social media following (e.g.,
|
||||
Instagram, Discord, Twitter).
|
||||
</>
|
||||
}
|
||||
placeholder="Select"
|
||||
selectLabel="Select"
|
||||
value={field.value}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
This helps set clear expectations for investors
|
||||
</span>
|
||||
</div>
|
||||
</FormControl>
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
{/* Target investment */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="targetInvest"
|
||||
render={({ field }: { field: any }) => (
|
||||
<FormItem>
|
||||
<div className="mt-10 space-y-5">
|
||||
<FormLabel className="font-bold text-lg">
|
||||
Target investment
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<div className="flex space-x-5">
|
||||
<Switch
|
||||
onCheckedChange={() => setApplyProject(!applyProject)}
|
||||
></Switch>
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<span className="text-[12px] text-neutral-500 self-center cursor-pointer">
|
||||
Would you like to apply for your first fundraising project
|
||||
as well?
|
||||
<Input
|
||||
type="number"
|
||||
id="targetInvest"
|
||||
className="w-96"
|
||||
placeholder="$ 1,000,000"
|
||||
{...field}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
field.onChange(value ? parseFloat(value) : null);
|
||||
}}
|
||||
value={field.value}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
We encourage you to set a specific target investment{" "}
|
||||
<br /> amount that reflects your funding goals.
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p className="text-[11px]">
|
||||
Toggling this option allows you to begin your first
|
||||
project, <br /> which is crucial for unlocking the tools
|
||||
necessary to raise funds.
|
||||
</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
</FormControl>
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
{/* Deadline */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="deadline"
|
||||
render={({ field }: { field: any }) => (
|
||||
<FormItem>
|
||||
<div className="mt-10 space-y-5">
|
||||
<FormLabel className="font-bold text-lg">Deadline</FormLabel>
|
||||
<FormControl>
|
||||
<div className="flex space-x-5">
|
||||
<Input
|
||||
type="datetime-local"
|
||||
id="deadline"
|
||||
className="w-96"
|
||||
{...field}
|
||||
/>
|
||||
<span className="text-[12px] text-neutral-500 self-center">
|
||||
What is the deadline for your fundraising project?
|
||||
Setting <br /> a clear timeline can help motivate
|
||||
potential investors.
|
||||
</span>
|
||||
</div>
|
||||
</FormControl>
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<center>
|
||||
<Button
|
||||
className="mt-12 mb-20 h-10 text-base font-bold py-6 px-5"
|
||||
@ -410,7 +456,6 @@ const ProjectForm = ({
|
||||
</Button>
|
||||
</center>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
|
||||
@ -53,10 +53,10 @@ const projectFormSchema = z.object({
|
||||
projectPhotos: z.custom(
|
||||
(value) => {
|
||||
if (value instanceof FileList || Array.isArray(value)) {
|
||||
if (value.length === 1) {
|
||||
return false;
|
||||
}
|
||||
return Array.from(value).every((item) => item instanceof File);
|
||||
return (
|
||||
value.length > 0 &&
|
||||
Array.from(value).every((item) => item instanceof File)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
@ -65,6 +65,7 @@ const projectFormSchema = z.object({
|
||||
"Must be a FileList or an array of File objects with at least one file.",
|
||||
}
|
||||
),
|
||||
|
||||
minInvest: z
|
||||
.number({
|
||||
required_error: "Minimum investment must be a number.",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user