-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added resume field in Application Page (#103)
* Created button and label * Minor style changes * Changed to correct html input element * Added error checking for file upload * Drag and drop works * Added visual indication for drag and drop * Moved output feedback to its own component * Made resume required * Removed drag and drop * Style changes * Form actually sends file with multipart * File is reset on page load * Removed unnecessary import from layout * Added to upload feedback * Update apps/site/src/app/apply/sections/Form/ResumeOutputFeedback.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Style changes to ResumeOutputFeedback * Added back action endpoint for form
- Loading branch information
1 parent
44ff58a
commit 34534c2
Showing
9 changed files
with
143 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
apps/site/src/app/apply/sections/Form/ResumeInformation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
"use client"; | ||
|
||
import { ChangeEvent, useEffect, useState, useRef } from "react"; | ||
|
||
import RequiredAsterisk from "@/app/apply/sections/Components/RequiredAsterisk"; | ||
import OutputFeedBack from "./ResumeOutputFeedback"; | ||
|
||
import uploadImage from "@/assets/icons/upload-resume-icon.svg"; | ||
import Image from "next/image"; | ||
|
||
import styles from "./Form.module.scss"; | ||
|
||
class InvalidFile extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = "InvalidFile"; | ||
} | ||
} | ||
|
||
export default function ResumeInformation() { | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
const [resumePath, setResumePath] = useState(""); | ||
const [errorMessage, setErrorMessage] = useState(""); | ||
|
||
useEffect(() => { | ||
if (inputRef.current) { | ||
inputRef.current.value = ""; | ||
} | ||
}, []); | ||
|
||
const handleFileUpload = (event: ChangeEvent<HTMLInputElement>) => { | ||
event.preventDefault(); | ||
|
||
setErrorMessage(""); | ||
setResumePath(""); | ||
|
||
let file = event.target.files ? event.target.files[0] : null; | ||
try { | ||
handleFile(file); | ||
} catch (error) { | ||
event.target.value = ""; | ||
} | ||
}; | ||
|
||
const handleFile = (file: File | null) => { | ||
if (!file) throw TypeError; | ||
|
||
let path = file.name; | ||
|
||
let extension = path.split(".").pop(); | ||
if (extension != "pdf") { | ||
setErrorMessage("Invalid file format"); | ||
throw new InvalidFile("Invalid file format"); | ||
} | ||
|
||
if (file.size > 500000) { | ||
setErrorMessage("Invalid file size (file size exceeds 0.5 MB)"); | ||
throw new InvalidFile("Invalid file size"); | ||
} | ||
setResumePath(path); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col items-start w-11/12"> | ||
<label className={styles.label}> | ||
Resume (PDF, 0.5 MB max) <RequiredAsterisk /> | ||
</label> | ||
<label | ||
htmlFor="resume_upload" | ||
className={`${styles.upload} cursor-pointer mb-3`} | ||
> | ||
<Image src={uploadImage} width="100" alt="Upload resume icon" /> | ||
<h2 className="text-center">Upload file</h2> | ||
</label> | ||
<input | ||
ref={inputRef} | ||
className="opacity-0 absolute" | ||
name="resume_upload" | ||
id="resume_upload" | ||
type="file" | ||
accept="application/pdf" | ||
onChange={handleFileUpload} | ||
required | ||
></input> | ||
<OutputFeedBack | ||
errorMessage={errorMessage} | ||
resumePath={resumePath} | ||
/> | ||
</div> | ||
); | ||
} |
19 changes: 19 additions & 0 deletions
19
apps/site/src/app/apply/sections/Form/ResumeOutputFeedback.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
interface OutputFeedbackProps { | ||
errorMessage: string; | ||
resumePath: string; | ||
} | ||
|
||
export default function OutputFeedBack({ | ||
errorMessage, | ||
resumePath, | ||
}: OutputFeedbackProps) { | ||
if (errorMessage) { | ||
return <span className="text-[#FF2222] text-xl">{errorMessage}</span>; | ||
} | ||
|
||
return ( | ||
<span className="text-xl"> | ||
{resumePath ? "Successfully uploaded " + resumePath : ""} | ||
</span> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.