diff --git a/client/src/pages/UpdateApplicationPage/UpdateApplicationPage.tsx b/client/src/pages/UpdateApplicationPage/UpdateApplicationPage.tsx index 9c78a42..c26bb8d 100644 --- a/client/src/pages/UpdateApplicationPage/UpdateApplicationPage.tsx +++ b/client/src/pages/UpdateApplicationPage/UpdateApplicationPage.tsx @@ -1,57 +1,54 @@ -import React, { useState, useEffect } from "react"; -import { useNavigate, useParams } from "react-router-dom"; -import axios from "axios"; -import { useAppSelector, useAppDispatch } from "../../app/hooks"; -import { updateApplication } from "../../features/applications/applicationSlice"; -import { IApplicationFormData, IStatus } from "../../../types/applications"; +import React, { useState, useEffect } from 'react'; +import { useNavigate, useParams } from 'react-router-dom'; +import axios from 'axios'; +import { useAppSelector, useAppDispatch } from '../../app/hooks'; +import { updateApplication } from '../../features/applications/applicationSlice'; +import { IApplicationFormData, IStatus } from '../../../types/applications'; const UpdateApplicationPage = (): JSX.Element => { const { id } = useParams<{ id: string }>(); - console.log("id:", id); + console.log('id:', id); const user = useAppSelector((state) => state.user.userData); - const { application, status, error } = useAppSelector( - (state) => state.application - ); + const { status } = useAppSelector((state) => state.application); const dispatch = useAppDispatch(); const navigate = useNavigate(); const [statuses, setStatuses] = useState([]); const [formData, setFormData] = useState({ - title: "", - company: "", - location: "", - description: "", - url: "", + title: '', + company: '', + location: '', + description: '', + url: '', status_id: 1, - user_id: user?._id || "", + user_id: user?._id || '', quick_apply: false, - date_applied: new Date().toISOString().split("T")[0], - general_notes: "", + date_applied: new Date().toISOString().split('T')[0], + general_notes: '', job_id: 0, }); useEffect(() => { async function fetchStatuses() { try { - const response = await axios.get("/api/applications/statuses"); + const response = await axios.get('/api/applications/statuses'); setStatuses(response.data); } catch (error) { - console.error("Error fetching statuses:", error); + console.error('Error fetching statuses:', error); } } async function fetchApplication() { try { - console.log("HITTT!!!!!"); const response = await axios.get(`/api/applications/${id}`); const applicationData = response.data; applicationData.date_applied = new Date(applicationData.date_applied) .toISOString() - .split("T")[0]; + .split('T')[0]; setFormData(applicationData); } catch (error) { - console.error("Error fetching application:", error); + console.error('Error fetching application:', error); } } @@ -62,16 +59,14 @@ const UpdateApplicationPage = (): JSX.Element => { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); dispatch(updateApplication({ id: Number(id), ...formData })); - navigate("/app/applications"); + navigate('/app/applications'); }; const handleChange = ( - e: React.ChangeEvent< - HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement - > + e: React.ChangeEvent, ) => { const { name, value, type } = e.target; - if (type === "checkbox") { + if (type === 'checkbox') { const checked = (e.target as HTMLInputElement).checked; setFormData((prevFormData) => ({ ...prevFormData, @@ -204,7 +199,7 @@ const UpdateApplicationPage = (): JSX.Element => { className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" type="submit" > - {status === "updating" ? "Updating..." : "Update Application"} + {status === 'updating' ? 'Updating...' : 'Update Application'} diff --git a/server/controllers/applicationsController.ts b/server/controllers/applicationsController.ts index a8f2d49..bdfdb6b 100644 --- a/server/controllers/applicationsController.ts +++ b/server/controllers/applicationsController.ts @@ -7,7 +7,7 @@ interface StatusCount { count: string; } -const getAllApplications = async (req: Request, res: Response, next: NextFunction) => { +const getAllApplications = async (req: Request, res: Response) => { try { const userId = req.query.user_id; @@ -37,7 +37,7 @@ const getAllApplications = async (req: Request, res: Response, next: NextFunctio } }; -const getStatuses = async (req: Request, res: Response, next: NextFunction) => { +const getStatuses = async (req: Request, res: Response) => { try { const { rows } = await pool.query('SELECT * FROM statuses'); res.json(rows); @@ -47,7 +47,7 @@ const getStatuses = async (req: Request, res: Response, next: NextFunction) => { } }; -const createApplication = async (req: Request, res: Response, next: NextFunction) => { +const createApplication = async (req: Request, res: Response) => { try { const { title, @@ -93,11 +93,7 @@ const createApplication = async (req: Request, res: Response, next: NextFunction } }; -const getApplicationById = async ( - req: CustomRequest<{ id: string }>, - res: Response, - next: NextFunction, -) => { +const getApplicationById = async (req: CustomRequest<{ id: string }>, res: Response) => { const { id } = req.params; try { const query = ` @@ -138,11 +134,7 @@ const getApplicationById = async ( } }; -const updateApplication = async ( - req: CustomRequest<{ id: string }>, - res: Response, - next: NextFunction, -) => { +const updateApplication = async (req: CustomRequest<{ id: string }>, res: Response) => { const { id } = req.params; if (!req.user) { @@ -181,11 +173,7 @@ const updateApplication = async ( } }; -const getAggregatedUserStats = async ( - req: CustomRequest<{ userId: string }>, - res: Response, - next: NextFunction, -) => { +const getAggregatedUserStats = async (req: CustomRequest<{ userId: string }>, res: Response) => { const { userId } = req.params; if (!req.user || req.user.id !== userId) return res.status(401).json({ message: 'You are not authorized to retrieve those records' }); @@ -216,7 +204,7 @@ const getAggregatedUserStats = async ( } }; -const updateNotificationPeriod = async (req: Request, res: Response, next: NextFunction) => { +const updateNotificationPeriod = async (req: Request, res: Response) => { try { const { id } = req.params; const { period } = req.body; @@ -234,7 +222,7 @@ const updateNotificationPeriod = async (req: Request, res: Response, next: NextF } }; -const pauseNotifications = async (req: Request, res: Response, next: NextFunction) => { +const pauseNotifications = async (req: Request, res: Response) => { try { const { id } = req.params; const { pause } = req.body;