diff --git a/components/Form.tsx b/components/Form.tsx index 3e0f722..73044cb 100644 --- a/components/Form.tsx +++ b/components/Form.tsx @@ -1,8 +1,10 @@ 'use client' -import { useState, ChangeEvent } from "react"; +import { useState, useRef, ChangeEvent } from "react"; import { useRouter } from "next/navigation"; import { Button, Label } from 'flowbite-react'; import { AiOutlineLoading } from 'react-icons/ai'; +import { HiOutlineX } from "react-icons/hi"; + import { Events, FormData, FormProps } from "@/types/form" @@ -527,6 +529,80 @@ export default function Form({ title, questions, listingId, includeEventsAttende ) }; + const renderFileInput = ( + id: keyof FormData, + label: string, + type: string = "file", + required: boolean = false + ) => { + // Create a ref to hold the reference to the input element + const fileInputRef = useRef(null); + + // Function to clear the input value + const clearFileInput = (e: React.MouseEvent) => { + console.log("clearing file") + e.stopPropagation(); + if (fileInputRef.current) { + // update resume/image name variables + if (fileInputRef.current.id === "resume") { + setResumeFileName("") + } else if (fileInputRef.current.id === "image") { + setImageFileName("") + } + fileInputRef.current.value = ''; // Clear the input value + handleFileChange({ target: { id, files: null } } as ChangeEvent); + } + }; + + return ( +
+ +
+ + +
+ {/* render either resume or image depending on id */} + {id === 'resume' ? + resumeFileName && +
+

{resumeFileName}

+ clearFileInput(e)} + disabled={isSubmitting} + /> +
+ : + imageFileName && +
+

{imageFileName}

+ clearFileInput(e)} + disabled={isSubmitting} + /> +
+ } +
+ ); + } + const textStyles = { title: "text-4xl font-bold dark:text-white mb-6 mt-4 text-purple-800", @@ -570,48 +646,9 @@ export default function Form({ title, questions, listingId, includeEventsAttende {renderInput("phone", "Phone Number (xxx-xxx-xxxx)", "text", true)} {renderInput("linkedin", "LinkedIn Profile", "text")} {renderInput("website", "Website / Portfolio", "text")} + {renderFileInput("resume", "Upload Your Resume (PDF)", "file", true)} + {renderFileInput("image", "Upload Profile Picture (PNG/JPG/JPEG)", "file", true)} -
- -
- - - {resumeFileName &&

{resumeFileName}

} -
-
- -
- -
- - - {imageFileName &&

{imageFileName}

} -
-
{includeEventsAttended && renderEventsAttendedSection()}