Skip to content

Commit

Permalink
Aarons changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendon Kupsch authored and Brendon Kupsch committed Dec 8, 2024
1 parent 8cb0df8 commit eb34aec
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 74 deletions.
61 changes: 53 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ passport.use(new SamlStrategy(
wantAssertionsSigned: false,
wantAuthnResponseSigned: false
},
(profile, done) => {
// Extract user information from the profile
const user = {
email: profile.emailAddress,
};
return done(null, user);
}
function (req, profile, done) {
// for signon
findByEmail(profile.emailAddress, function (err, user) {
if (err) {
return done(err);
}
if (!user) {
return done(new Error('User not found'));
}
return done(null, user);
console.log('User found');
console.log(user);
});
},
));

passport.serializeUser((user, done) => {
Expand All @@ -78,6 +85,31 @@ passport.deserializeUser((user, done) => {
done(null, user);
});

// Correct route handler with both req and res
app.get('/committees', async (req, res) => {
try {
const result = await client.query('SELECT Cname FROM Committees');
console.log('Fetched committees:', result.rows); // Add this line to log the fetched data
res.json(result.rows);
} catch (err) {
console.error('Error fetching committees:', err);
res.status(500).json({ message: 'Server error' });
}
}
);

// Route to fetch school names
app.get('/schools', async (req, res) => {
try {
const result = await client.query('SELECT Sname FROM Schools');
res.json(result.rows);
} catch (err) {
console.error('Error fetching schools:', err);
res.status(500).json({ message: 'Server error' });
}
}
);

// SSO callback route
app.post(
'/login/callback',
Expand All @@ -99,6 +131,19 @@ app.get('/sso/login',
}
);

// Correct route handler with both req and res
app.get('/committees', async (req, res) => {
try {
const result = await client.query('SELECT Cname FROM Committees');
console.log('Fetched committees:', result.rows); // Add this line to log the fetched data
res.json(result.rows);
} catch (err) {
console.error('Error fetching committees:', err);
res.status(500).json({ message: 'Server error' });
}
}
);

// Route to handle admin login
app.post('/admin-login', async (req, res) => {
const { username, password } = req.body; // Capture username and password from request
Expand Down Expand Up @@ -175,4 +220,4 @@ httpServer.listen(httpPort, () => {
});
httpsServer.listen(httpsPort, () => {
console.log(`HTTPS Server running on port ${httpsPort}`);
});
});
Binary file added src/.UserProfile.tsx.swp
Binary file not shown.
197 changes: 131 additions & 66 deletions src/UserProfile.tsx
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;

0 comments on commit eb34aec

Please sign in to comment.