diff --git a/frontend/src/components/Locations/AddLocationModal.tsx b/frontend/src/components/Locations/AddLocationModal.tsx index 19105bab7..9ddd382be 100644 --- a/frontend/src/components/Locations/AddLocationModal.tsx +++ b/frontend/src/components/Locations/AddLocationModal.tsx @@ -1,27 +1,26 @@ import React, { useState, useEffect } from 'react'; -import { - Dialog, - DialogTitle, - DialogContent, +import { + Dialog, + DialogTitle, + DialogContent, DialogActions, TextField, Button, Select, MenuItem, FormControl, - InputLabel + InputLabel, } from '@mui/material'; import { PlacesSearch } from './PlacesSearch'; - // TODO : Move to the index.ts since it is a constant const CAMPUS_OPTIONS = [ 'North Campus', - 'West Campus', + 'West Campus', 'Central Campus', 'South Campus', 'Commons', - 'Other' + 'Other', ] as const; interface Location { @@ -42,7 +41,7 @@ interface AddLocationModalProps { export const AddLocationModal: React.FC = ({ open, onClose, - onAdd + onAdd, }) => { const [newLocation, setNewLocation] = useState({ name: '', @@ -50,12 +49,12 @@ export const AddLocationModal: React.FC = ({ info: '', tag: 'Other', lat: 0, - lng: 0 + lng: 0, }); const [errors, setErrors] = useState({ name: '', - info: '' + info: '', }); useEffect(() => { @@ -66,22 +65,22 @@ export const AddLocationModal: React.FC = ({ info: '', tag: 'Other', lat: 0, - lng: 0 + lng: 0, }); setErrors({ name: '', - info: '' + info: '', }); } }, [open]); const handleAddressSelect = (address: string, lat: number, lng: number) => { console.log('Address selected:', { address, lat, lng }); - setNewLocation(prev => ({ + setNewLocation((prev) => ({ ...prev, address, lat, - lng + lng, })); }; @@ -98,8 +97,8 @@ export const AddLocationModal: React.FC = ({ const handleNameChange = (e: React.ChangeEvent) => { const name = e.target.value; const error = validateName(name); - setErrors(prev => ({ ...prev, name: error })); - setNewLocation(prev => ({ ...prev, name })); + setErrors((prev) => ({ ...prev, name: error })); + setNewLocation((prev) => ({ ...prev, name })); }; const handleSubmit = () => { @@ -108,10 +107,16 @@ export const AddLocationModal: React.FC = ({ setErrors({ name: nameError, - info: infoError + info: infoError, }); - if (!nameError && !infoError && newLocation.address && newLocation.lat && newLocation.lng) { + if ( + !nameError && + !infoError && + newLocation.address && + newLocation.lat && + newLocation.lng + ) { console.log('Submitting location:', newLocation); onAdd(newLocation); onClose(); @@ -127,7 +132,14 @@ export const AddLocationModal: React.FC = ({ Add New Location -
+
= ({ error={!!errors.name} helperText={errors.name} /> - +
-
- + = ({ value={newLocation.info} onChange={(e) => { const info = e.target.value; - setErrors(prev => ({ ...prev, info: info ? '' : 'Description is required' })); - setNewLocation(prev => ({ ...prev, info })); + setErrors((prev) => ({ + ...prev, + info: info ? '' : 'Description is required', + })); + setNewLocation((prev) => ({ ...prev, info })); }} error={!!errors.info} helperText={errors.info} @@ -164,10 +185,12 @@ export const AddLocationModal: React.FC = ({