Skip to content

Commit

Permalink
Feat: Sort by Date, Filter by Status on dashboard table
Browse files Browse the repository at this point in the history
  • Loading branch information
CRSantiago committed Apr 9, 2024
1 parent c1971e3 commit 939e5ff
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 122 deletions.
107 changes: 54 additions & 53 deletions client/src/features/Dashboard/CreateJobApplicationForm.jsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
import React, { useState } from 'react'
import { FormLabel, FormInput, FormButton } from '../components'
import x_solid from './assets/xmark_solid.svg'
import SuccessAnimation from './SuccessAnimation'
import { createJobApplication } from './api'
import React, { useState } from "react"
import { FormLabel, FormInput, FormButton } from "../components"
import x_solid from "./assets/xmark_solid.svg"
import SuccessAnimation from "./SuccessAnimation"
import { createJobApplication } from "./api"

const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
const statusEnum = [
'Applied',
'Phone Screen',
'Onsite',
'Offer',
'Accepted',
'Rejected',
"Applied",
"Assessment",
"Phone Screen",
"Interviewing",
"Offer",
"Accepted",
"Rejected",
]
const [formData, setFormData] = useState({
company: '',
jobTitle: '',
dateApplied: '',
company: "",
jobTitle: "",
dateApplied: "",
status: statusEnum[0],
source: '',
location: '',
notes: '',
contactEmail: '',
contactPhone: '',
source: "",
location: "",
notes: "",
contactEmail: "",
contactPhone: "",
interviewDates: [],
})
const [fieldErrors, setFieldErrors] = useState({
company: '',
jobTitle: '',
dateApplied: '',
status: '',
source: '',
location: '',
notes: '',
contactEmail: '',
contactPhone: '',
company: "",
jobTitle: "",
dateApplied: "",
status: "",
source: "",
location: "",
notes: "",
contactEmail: "",
contactPhone: "",
interviewDates: [],
})

Expand Down Expand Up @@ -93,34 +94,34 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
}

const validateFormData = () => {
if (formData.company === '') {
if (formData.company === "") {
setFieldErrors((prevState) => ({
...prevState,
company: 'Company name is required',
company: "Company name is required",
}))
return false
} else {
setFieldErrors((prevState) => ({ ...prevState, company: '' }))
setFieldErrors((prevState) => ({ ...prevState, company: "" }))
}

if (formData.jobTitle === '') {
if (formData.jobTitle === "") {
setFieldErrors((prevState) => ({
...prevState,
jobTitle: 'Job title is required',
jobTitle: "Job title is required",
}))
return false
} else {
setFieldErrors((prevState) => ({ ...prevState, jobTitle: '' }))
setFieldErrors((prevState) => ({ ...prevState, jobTitle: "" }))
}

if (formData.dateApplied === '') {
if (formData.dateApplied === "") {
setFieldErrors((prevState) => ({
...prevState,
dateApplied: 'Date applied is required',
dateApplied: "Date applied is required",
}))
return false
} else {
setFieldErrors((prevState) => ({ ...prevState, dateApplied: '' }))
setFieldErrors((prevState) => ({ ...prevState, dateApplied: "" }))
}

return true
Expand All @@ -138,15 +139,15 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
}, 2000)
})
.catch((error) => {
console.error('Error creating job application', error)
console.error("Error creating job application", error)
})
}
}

return (
<>
{isSubmitted ? (
<SuccessAnimation message={'Form Submitted Successfully!'} />
<SuccessAnimation message={"Form Submitted Successfully!"} />
) : (
<form
className="w-1/3 max-h-[90vh] overflow-y-auto fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-50 bg-white p-5 rounded-md shadow-md"
Expand Down Expand Up @@ -211,8 +212,8 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
src={x_solid}
alt="Close"
onClick={() => {
handleFieldVisibility('source')
setFormData({ ...formData, source: '' })
handleFieldVisibility("source")
setFormData({ ...formData, source: "" })
}}
className="w-2 cursor-pointer"
/>
Expand All @@ -229,7 +230,7 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
{!fieldVisibility.source && (
<button
type="button"
onClick={() => handleFieldVisibility('source')}
onClick={() => handleFieldVisibility("source")}
className="bg-green-600 rounded-md p-1 my-2 cursor-pointer hover:opacity-50 text-white"
>
Add Source
Expand All @@ -243,8 +244,8 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
src={x_solid}
alt="Close"
onClick={() => {
handleFieldVisibility('location')
setFormData({ ...formData, location: '' })
handleFieldVisibility("location")
setFormData({ ...formData, location: "" })
}}
className="w-2 cursor-pointer"
/>
Expand All @@ -261,7 +262,7 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
{!fieldVisibility.location && (
<button
type="button"
onClick={() => handleFieldVisibility('location')}
onClick={() => handleFieldVisibility("location")}
className="bg-green-600 rounded-md p-1 my-2 cursor-pointer hover:opacity-50 text-white"
>
Add Location
Expand All @@ -275,8 +276,8 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
src={x_solid}
alt="Close"
onClick={() => {
handleFieldVisibility('contactEmail')
setFormData({ ...formData, contactEmail: '' })
handleFieldVisibility("contactEmail")
setFormData({ ...formData, contactEmail: "" })
}}
className="w-2 cursor-pointer"
/>
Expand All @@ -293,7 +294,7 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
{!fieldVisibility.contactEmail && (
<button
type="button"
onClick={() => handleFieldVisibility('contactEmail')}
onClick={() => handleFieldVisibility("contactEmail")}
className="bg-green-600 rounded-md p-1 my-2 cursor-pointer hover:opacity-50 text-white"
>
Add Contact Email
Expand All @@ -307,7 +308,7 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
src={x_solid}
alt="Close"
onClick={() => {
handleFieldVisibility('interviewDates')
handleFieldVisibility("interviewDates")
setFormData({ ...formData, interviewDates: [] })
}}
className="w-2 cursor-pointer"
Expand Down Expand Up @@ -342,7 +343,7 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
{!fieldVisibility.interviewDates && (
<button
type="button"
onClick={() => handleFieldVisibility('interviewDates')}
onClick={() => handleFieldVisibility("interviewDates")}
className="bg-green-600 rounded-md p-1 my-2 cursor-pointer hover:opacity-50 text-white"
>
Add Interview Dates
Expand All @@ -356,8 +357,8 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
src={x_solid}
alt="Close"
onClick={() => {
handleFieldVisibility('notes')
setFormData({ ...formData, notes: '' })
handleFieldVisibility("notes")
setFormData({ ...formData, notes: "" })
}}
className="w-2 cursor-pointer"
/>
Expand All @@ -376,7 +377,7 @@ const CreateJobApplicationForm = ({ setIsCreating, fetchUserData }) => {
{!fieldVisibility.notes && (
<button
type="button"
onClick={() => handleFieldVisibility('notes')}
onClick={() => handleFieldVisibility("notes")}
className="bg-green-600 rounded-md p-1 my-2 cursor-pointer hover:opacity-50 text-white"
>
Add Notes
Expand Down
Loading

0 comments on commit 939e5ff

Please sign in to comment.