-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brendon Kupsch
authored and
Brendon Kupsch
committed
Dec 8, 2024
1 parent
8cb0df8
commit eb34aec
Showing
3 changed files
with
184 additions
and
74 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
Binary file not shown.
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 |
---|---|---|
@@ -1,95 +1,160 @@ | ||
import React, { useState } from 'react'; | ||
import React, { useState, useEffect } from 'react'; | ||
import './UserProfile.css'; | ||
import Navbar from './components/navbar/Navbar'; | ||
import saveIcon from './assets/save-icon.png'; | ||
import CreatableSelect from 'react-select/creatable'; | ||
import Select from 'react-select'; | ||
|
||
const UserProfile: React.FC = () => { | ||
const [isEditing, setIsEditing] = useState(false); | ||
const [preferredName, setPreferredName] = useState(''); | ||
const [school, setSchool] = useState(''); | ||
const [committees, setCommittees] = useState<string[]>([]); | ||
const [serviceStatement, setServiceStatement] = useState(''); | ||
const [committeeOptions, setCommitteeOptions] = useState<{ value: string, label: string }[]>([]); | ||
const [schoolOptions, setSchoolOptions] = useState<{ value: string, label: string }[]>([]); | ||
|
||
const committeeOptions = [ | ||
{ value: 'COM1', label: 'COM1' }, | ||
{ value: 'COM2', label: 'COM2' }, | ||
{ value: 'COM3', label: 'COM3' }, | ||
]; | ||
useEffect(() => { | ||
const fetchCommitteeNames = async () => { | ||
try { | ||
const response = await fetch('/committees', { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
if (!response.ok) { | ||
throw new Error(`Error fetching committee names: ${response.statusText}`); | ||
} | ||
const data = await response.json(); | ||
const options = data.map((committee: { cname: string }) => ({ | ||
value: committee.cname, | ||
label: committee.cname, | ||
})); | ||
setCommitteeOptions(options); | ||
} catch (error) { | ||
console.error('Error fetching committee names:', error); | ||
} | ||
}; | ||
|
||
const schoolOptions = [ | ||
{ value: 'School of Business', label: 'School of Business' }, | ||
{ value: 'School of Science', label: 'School of Science' }, | ||
{ value: 'School of Liberal Arts', label: 'School of Liberal Arts' }, | ||
]; | ||
const fetchSchoolNames = async () => { | ||
try { | ||
const response = await fetch('/schools', { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
if (!response.ok) { | ||
throw new Error(`Error fetching school names: ${response.statusText}`); | ||
} | ||
const data = await response.json(); | ||
const options = data.map((school: { sname: string }) => ({ | ||
value: school.sname, | ||
label: school.sname, | ||
})); | ||
setSchoolOptions(options); | ||
} catch (error) { | ||
console.error('Error fetching school names:', error); | ||
} | ||
}; | ||
|
||
fetchCommitteeNames(); | ||
fetchSchoolNames(); | ||
}, []); | ||
|
||
const handleCommitteeChange = (selectedOptions: any) => { | ||
setCommittees(selectedOptions ? selectedOptions.map((option: any) => option.value) : []); | ||
}; | ||
|
||
const handleSave = () => { | ||
setIsEditing(false); | ||
// Trigger save to the database here | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className='container'> | ||
<Navbar /> | ||
<h1>Your Election Profile</h1> | ||
<h1 className='title'>Your Election Profile</h1> | ||
<div className="profile-form-container"> | ||
<form className="profile-form"> | ||
{/* Preferred Name Input */} | ||
<div className="form-group"> | ||
<label>Enter your preferred name (how it will appear on the ballot)</label> | ||
<input | ||
type="text" | ||
value={preferredName} | ||
onChange={(e) => setPreferredName(e.target.value)} | ||
placeholder="Your Preferred Name Here" | ||
/> | ||
</div> | ||
|
||
{/* Dropdown for School */} | ||
<div className="form-group"> | ||
<label>Select your School from the dropdown menu</label> | ||
<Select | ||
options={schoolOptions} | ||
value={schoolOptions.find(option => option.value === school)} | ||
onChange={(selectedOption) => setSchool(selectedOption?.value || '')} | ||
placeholder="Select School" | ||
/> | ||
</div> | ||
|
||
{/* Multi-select Committees */} | ||
<div className="form-group"> | ||
<label>Select the committees you have been a part of (can select multiple)</label> | ||
<CreatableSelect | ||
className='select-input' | ||
isMulti | ||
options={committeeOptions} | ||
onChange={handleCommitteeChange} | ||
placeholder="Select or input committees" | ||
/> | ||
</div> | ||
|
||
{/* Service Statement */} | ||
<div className="form-group"> | ||
<label>Create a Service Statement (Why someone should vote for you)</label> | ||
<textarea | ||
value={serviceStatement} | ||
onChange={(e) => setServiceStatement(e.target.value)} | ||
placeholder="Enter your statement here" | ||
maxLength={300} | ||
/> | ||
<small>{serviceStatement.length}/300</small> | ||
</div> | ||
|
||
{/* Save Button */} | ||
<div className="form-group"> | ||
<button type="submit" className="save-button"> | ||
<p>Save Profile</p> | ||
{/*<img src={saveIcon} alt="Save" />*/} | ||
{isEditing ? ( | ||
<form className="profile-form"> | ||
<div className="form-group"> | ||
<label>Enter your first name: </label> | ||
<input | ||
type="text" | ||
value={firstName} | ||
onChange={(e) => setFirstName(e.target.value)} | ||
placeholder="Your First Name Here" | ||
/> | ||
<label>Enter your last name: </label> | ||
<input | ||
type="text" | ||
value={lastName} | ||
onChange={(e) => setLastName(e.target.value)} | ||
placeholder="Your Last Name Here" | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<label>Enter your preferred name (how it will appear on the ballot)</label> | ||
<input | ||
type="text" | ||
value={preferredName} | ||
onChange={(e) => setPreferredName(e.target.value)} | ||
placeholder="Your Preferred Name Here" | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<label>Select your School from the dropdown menu</label> | ||
<Select | ||
options={schoolOptions} | ||
value={schoolOptions.find(option => option.value === school)} | ||
onChange={(selectedOption) => setSchool(selectedOption?.value || '')} | ||
placeholder="Select School" | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<label>Select the committees you have been a part of (can select multiple)</label> | ||
<CreatableSelect | ||
className='select-input' | ||
isMulti | ||
options={committeeOptions} | ||
onChange={handleCommitteeChange} | ||
placeholder="Select or input committees" | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<label>Create a Service Statement (Why someone should vote for you)</label> | ||
<textarea | ||
value={serviceStatement} | ||
onChange={(e) => setServiceStatement(e.target.value)} | ||
placeholder="Enter your statement here" | ||
maxLength={300} | ||
/> | ||
<small>{serviceStatement.length}/300</small> | ||
</div> | ||
<div className="form-group"> | ||
<button type="button" className="save-button" onClick={handleSave}> | ||
<p>Save Profile</p> | ||
{/* <img src={saveIcon} alt="Save" /> */} | ||
</button> | ||
</div> | ||
</form> | ||
) : ( | ||
<div className="profile-view"> | ||
<p><strong>Preferred Name:</strong> {preferredName || 'Not provided'}</p> | ||
<p><strong>School:</strong> {school || 'Not selected'}</p> | ||
<p><strong>Committees:</strong> {committees.length > 0 ? committees.join(', ') : 'None selected'}</p> | ||
<p><strong>Service Statement:</strong> {serviceStatement || 'Not provided'}</p> | ||
<button type="button" className="edit-button" onClick={() => setIsEditing(true)}> | ||
Edit Profile | ||
</button> | ||
</div> | ||
</form> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default UserProfile; | ||
|