diff --git a/back-end/App.js b/back-end/App.js index c58a397..49c04a0 100644 --- a/back-end/App.js +++ b/back-end/App.js @@ -57,10 +57,8 @@ const sessionOptions = { app.use(session(sessionOptions)); app.use(function (req, res, next) { - console.log(req.session.user); - req.session.user = req.session.user || "a"; - req.session.matches = req.session.matches || []; - //console.log(req.session) + req.session.otheruser = req.session.otheruser || ""; + console.log("otheruser:", req.session.otheruser); next(); }); @@ -139,10 +137,6 @@ app.post('/login', async (req, res) => { } }); - - - - app.get('/register', (req, res) => { }) @@ -176,16 +170,12 @@ app.post('/register', async (req, res) => { } }); - - - //expecting json object with handle sumbit attruputes -- in Survey.js //should push to surveyData arr app.post('/survey', (req, res) => { const surveyData = req.body; //console.log('Backend has received new survey data:', surveyData);//We should see a message on the backend console with the data that was sent - profiledict = { name: surveyData.name, year: surveyData.year, bio: "" } answersdict = { gender: surveyData.genderAns, year: surveyData.year, pets: surveyData.petsAns, @@ -214,28 +204,110 @@ app.post('/survey', (req, res) => { }); }); -app.get('/matches', async (req, res) => { - //console.log('matches:', req.session.user) - req.session.user = req.session.user || "randomname"; +app.get('/matches', authenticateToken, async (req, res) => { try { User.find() .then(foundUser => { - //jsonArray.push(foundUser); - res.json(foundUser) + if (!foundUser) return res.status(404).json({ message: "User not found" }); + + const foundOtherUser = []; + const matches = []; + var thisUser = new User({}); + + for (const user of foundUser) { + if (user._id && req.user.id) { + if (String(user._id) === req.user.id) { + //console.log(user.username); + thisUser = user; + } + else { + foundOtherUser.push(user); + } + } + } + keys = compat.createMatches(thisUser, foundOtherUser); + //console.log(keys); + + for (const key of keys) { + for (const user of foundUser) { + if (user.username === key) { + matches.push(user); + } + } + } + + res.json(matches); }) .catch(err => { console.log(err); res.status(500).send('server error'); }); + } catch (err) { + console.log(err); + } +}); - //res.json(jsonArray)//Now, send the array to the front end +app.post('/matches', authenticateToken, async (req, res) => { + const username = req.body.username; + req.session.otheruser = username; + //console.log('the clicked user is', username) + try { + const user = await User.findById(req.user.id); + if (!user) { + console.error('User not found'); + return res.status(404).json({ message: 'User not found.' }); + } + res.json({ message: 'Profile updated successfully.' }); + } catch (err) { + console.error("Error during profile update:", err); + res.status(500).json({ message: 'Internal server error', error: err.message }); + } +}); + +app.get('/otheruser', authenticateToken, (req, res) => { + try { + User.find() + .then(foundUser => { + if (!foundUser) return res.status(404).json({ message: "User not found" }); + + for (const user of foundUser) { + if(user.username === req.session.otheruser) { + res.json(user); + } + } + }) + .catch(err => { + console.log(err); + res.status(500).send('server error'); + }); + } catch (err) { + console.log(err); + } +}); +app.get('/useranswers', authenticateToken, (req, res) => { + console.log('in user answers', req.session.otheruser) + try { + User.find() + .then(foundUser => { + if (!foundUser) return res.status(404).json({ message: "User not found" }); + for (const user of foundUser) { + if(user.username === req.session.otheruser) { + res.json(user); + } + } + }) + .catch(err => { + console.log(err); + res.status(500).send('server error'); + }); } catch (err) { console.log(err); } }); + //returns a bunch of json objects as an array app.get('/chatlist', authenticateToken, async (req, res) => { try { @@ -401,8 +473,60 @@ app.get('/profile', authenticateToken, (req, res) => { }); }); +app.get('/retake', authenticateToken, async(req, res) => { + User.findById(req.user.id, 'profile.name answers.gender answers.year answers.pets ' + + 'answers.guests answers.smoke answers.drink ' + + 'answers.rent_max answers.rent_min ' + + 'answers.bedtime answers.quietness answers.cleanliness ' + + 'preferences.gender preferences.year preferences.pets ' + + 'preferences.guests preferences.smoke preferences.drink ' + + 'preferences.bedtime preferences.quietness preferences.cleanliness') + .then(user => { + if (!user) return res.status(404).json({ message: "User not found" }); + res.json(user); + }) + .catch(err => { + console.error(err); + res.status(500).json({ message: "Internal server error" }); + }); +}); -app.get('/mypreferences', (req, res) => { +app.post('/retake', authenticateToken, async(req, res) => { + console.log("Received update request for user:", req.user.id); + console.log("Request data:", req.body); + + try { + const user = await User.findById(req.user.id); + if (!user) { + console.error('User not found'); + return res.status(404).json({ message: 'User not found.' }); + } + + const surveyData = req.body; + + profiledict = { name: surveyData.name, year: surveyData.year, bio: "" } + answersdict = { + gender: surveyData.genderAns, year: surveyData.year, pets: surveyData.petsAns, + guests: surveyData.guestsAns, smoke: surveyData.smokeAns, drink: surveyData.drinkAns, + rent_max: surveyData.maxRent, rent_min: surveyData.minRent, + bedtime: surveyData.bedAns, quietness: surveyData.quietAns, cleanliness: surveyData.cleanAns + } + preferencesdict = { + gender: surveyData.genderPref, year: surveyData.yearPref, pets: surveyData.petsPref, + guests: surveyData.guestsPref, smoke: surveyData.smokePref, drink: surveyData.drinkPref, + bedtime: surveyData.bedPref, quietness: surveyData.quietPref, cleanliness: surveyData.cleanPref + } + user.profile = profiledict; + user.answers = answersdict; + user.preferences = preferencesdict; + + await user.save(); + console.log('User updated: ', user); + res.json({message: 'Survey updated successfully'}); + } catch (err) { + console.error("Error during survey retake update:", err); + res.status(500).json({ message: 'Internal server error', error: err.message }); + } }); app.post('/editprofile', authenticateToken, async (req, res) => { diff --git a/back-end/Compatibility.js b/back-end/Compatibility.js index ba7c1ad..9267264 100644 --- a/back-end/Compatibility.js +++ b/back-end/Compatibility.js @@ -290,7 +290,7 @@ function createMatches(arg1, [...args]) { for (const arg of args) { if (match(arg1, arg) !== -1) { - matchList[arg.login.username] = match(arg1, arg); + matchList[arg.username] = match(arg1, arg); } } diff --git a/front-end/package-lock.json b/front-end/package-lock.json index 3c2d998..ec73b86 100644 --- a/front-end/package-lock.json +++ b/front-end/package-lock.json @@ -17005,16 +17005,16 @@ } }, "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=14.17" + "node": ">=4.2.0" } }, "node_modules/unbox-primitive": { diff --git a/front-end/src/App.js b/front-end/src/App.js index 8a8ae8a..69a05c3 100644 --- a/front-end/src/App.js +++ b/front-end/src/App.js @@ -8,8 +8,9 @@ import Matches from './Matches'; import Survey from './Survey'; import Profile from './Profile' import EditProfile from './EditProfile'; -import MyPreferences from './MyPreferences' +import Retake from './Retake' import OtherProfile from './OtherProfile'; +import UserAnswers from './UserAnswers'; import ProtectedRoute from './ProtectedRoute'; import axios from 'axios' @@ -27,8 +28,9 @@ function App() { } /> } /> } /> - } /> + } /> } /> + } /> {/* Redirect all other paths to "/login" */} } /> diff --git a/front-end/src/Matches.js b/front-end/src/Matches.js index f648134..379c058 100644 --- a/front-end/src/Matches.js +++ b/front-end/src/Matches.js @@ -13,21 +13,25 @@ const Matches = props => { const [error, setError] = useState('') const [feedback, setFeedback] = useState('') const [matches, setMatches] = useState([]); + const [errorMessage, setErrorMessage] = useState(""); - const fetchMatches = () => { - axios - .get('http://localhost:3001/matches')//, { withCredentials: true}) - .then(response => { - const matchesData = response.data; //response is an array of JSON objects - setMatches(matchesData); - }) - .catch(err => { - const errMsg = JSON.stringify(err, null, 2); - setError(errMsg); - }) - .finally(() => { - setLoaded(true); + const fetchMatches = async() => { + try { + const response = await axios.get('http://localhost:3001/matches', { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}` + } }); + console.log('Fetching profile data', response.data); + if (response.data) { + setMatches(response.data); + } else { + throw new Error('Matches data is missing'); + } + } catch (error) { + console.error('Error fetching matches data:', error); + setError('Error fetching matches data: ' + error.message); + } }; useEffect(() => { @@ -46,6 +50,29 @@ const Matches = props => { } }, []) // putting a blank array as second argument will cause this function to run only once when component first loads + const handleClick = async (match) => { + console.log("Sending data of user: ", match.username); + + try { + const response = await axios.post('http://localhost:3001/matches', match, { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}` // Include the JWT token in the request + } + }); + console.log("Update response:", response.data); + if (response.status === 200) { + console.log("Match info sent successfully"); + navigate('/otheruser', { state: { updated: true } }); // Pass state to trigger re-fetch + } + } catch (error) { + console.error("Update error:", error); + const message = error.response?.data?.message || "An error occurred while updating the profile."; + setErrorMessage(message); + } +}; + +//() => navigate('/otheruser') + return ( <>
@@ -53,8 +80,7 @@ const Matches = props => { {error &&

{error}

} {/* To fix allignment I made error only show up if it is defined*/} {matches.map((match, index) => (
- - -
- - ); -} - -export default MyPreferences; diff --git a/front-end/src/OtherProfile.css b/front-end/src/OtherProfile.css index 621b2bc..f14e491 100644 --- a/front-end/src/OtherProfile.css +++ b/front-end/src/OtherProfile.css @@ -1,11 +1,10 @@ -.OtherBack { +.Heading{ display: flex; - justify-content: left; + justify-content: space-evenly; padding-top: 10px; - padding-left: 10px; } -.OtherProfile { +.Profile{ display: flex; flex-direction: column; align-items: center; @@ -13,13 +12,13 @@ font-family: 'Montserrat'; } -.OtherFooter { - display: flex; - justify-content: space-evenly; -} - -.OtherAbtTxt { +.AboutText{ padding-bottom: 20px; padding-left: 20px; padding-right: 20px; +} + +.Footer{ + display: flex; + justify-content: space-evenly; } \ No newline at end of file diff --git a/front-end/src/OtherProfile.js b/front-end/src/OtherProfile.js index 4893ec7..e133800 100644 --- a/front-end/src/OtherProfile.js +++ b/front-end/src/OtherProfile.js @@ -1,34 +1,73 @@ -import "./OtherProfile.css" -import Button from "./Button" -import profilePicture from "./ProfilePic.png" +import React, { useState, useEffect } from 'react'; +import axios from 'axios'; +import { useNavigate } from 'react-router-dom'; +import Header from './Header'; +import Button from './Button'; +import profilePicture from './ProfilePic.png'; +import "./Profile.css"; +import { socket } from './sockets/ReactSocket'; function OtherProfile() { + const [profileData, setProfileData] = useState({}); + const [username, setUsername] = useState(''); // Separate state for username + const [error, setError] = useState(''); + const navigate = useNavigate(); + + const fetchProfileData = async () => { + try { + const response = await axios.get('http://localhost:3001/otheruser', { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}` + } + }); + console.log('Fetching profile data', response.data); + if (response.data && response.data.profile) { + setProfileData(response.data.profile); // Set the profile-specific data + setUsername(response.data.username); // Set username separately + } else { + throw new Error('Profile data is missing'); + } + } catch (error) { + console.error('Error fetching profile data:', error); + setError('Error fetching profile data: ' + error.message); + } + }; + + useEffect(() => { + fetchProfileData(); + }, []); + + const handleLogout = () => { + console.log("Logging out..."); + localStorage.removeItem('token'); + socket.disconnect(); //disconnect the socket that was in use + navigate('/login', { replace: true }); + }; + + if (!profileData || Object.keys(profileData).length === 0) { + return

Loading...

; + } + + + if (error) { + return

{error}

+ } + return ( <> -
- -
-
- -

Other User

-
-
-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. - Etiam consequat ante vel vehicula vulputate. Aliquam maximus turpis ut - porttitor imperdiet. Cras elementum orci id neque tincidunt finibus. - Proin accumsan suscipit elit, at varius eros scelerisque id. - Suspendisse maximus ultricies orci, ac convallis mauris accumsan non. - Nullam vel lectus eget urna pulvinar sodales vitae nec neque. - Maecenas ut erat eget turpis ultricies suscipit. -

-
-
- - -
+
+
+ Profile +

{username || 'Username not set'}

+

{profileData.year || 'Year not set'}

+

{profileData.bio || 'No bio available.'}

+
+
+
); } -export default OtherProfile \ No newline at end of file +export default OtherProfile; \ No newline at end of file diff --git a/front-end/src/Profile.js b/front-end/src/Profile.js index cc9c8d6..9a9680a 100644 --- a/front-end/src/Profile.js +++ b/front-end/src/Profile.js @@ -64,6 +64,7 @@ function Profile() {
diff --git a/front-end/src/Retake.css b/front-end/src/Retake.css new file mode 100644 index 0000000..d0a8e22 --- /dev/null +++ b/front-end/src/Retake.css @@ -0,0 +1,57 @@ + +.Survey { + display: flex; + flex-direction: column; + background-color: #e8e8e8; + } + + .survey-question { + padding: 1rem; + background-color: white; + margin-bottom: 1rem; + border-radius: 4px; + } + + .section { + padding: 0rem 0rem 0rem 1rem; + background-color: #BEBEBE; + margin-bottom: 1rem; + } + + label { + display: block; + margin-bottom: 0.5rem; + } + + select, + input[type="number"] { + width: 100%; + padding: 0.75rem; + border: 1px solid #D1D1D1; + border-radius: 4px; + margin-bottom: 0.5rem; + } + + button { + background-color: #57068C; + color: white; + padding: 0.75rem 1.5rem; + border: none; + border-radius: 4px; + cursor: pointer; + } + + button:hover { + background-color: #6D28D9; + } + + + .Header { + display: flex; + align-items: center; + justify-content: space-between; + padding: 1rem; + background-color: #57068C; + color: white; + } + \ No newline at end of file diff --git a/front-end/src/Retake.js b/front-end/src/Retake.js new file mode 100644 index 0000000..283b69c --- /dev/null +++ b/front-end/src/Retake.js @@ -0,0 +1,883 @@ +import React, { useState, useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; +import "./Retake.css"; +import Header from "./Header"; +import axios from 'axios'; +import { set } from 'mongoose'; + +function Retake() { + const navigate = useNavigate(); + const [error, setError] = useState(''); + const [errorMessage, setErrorMessage] = useState(""); + + const[name, setName] = useState(null); + const [year, setYear] = useState(null); + const [genderAns, setGenderAns] = useState(null); + const [petsAns, setPetsAns] = useState(null); + const [guestsAns, setGuestsAns] = useState(null); + const [smokeAns, setSmokeAns] = useState(null); + const [drinkAns, setDrinkAns] = useState(null); + const [maxRent, setMaxRent] = useState(null); + const [minRent, setMinRent] = useState(null); + const [bedAns, setBedAns] = useState(null); + const [quietAns, setQuietAns] = useState(null); + const [cleanAns, setCleanAns] = useState(null); + + const [genderPref, setGenderPref] = useState(null); + const [yearPref, setYearPref] = useState(null); + const [petsPref, setPetsPref] = useState(null); + const [guestsPref, setGuestsPref] = useState(null); + const [smokePref, setSmokePref] = useState(null); + const [drinkPref, setDrinkPref] = useState(null); + const [bedPref, setBedPref] = useState(null); + const [quietPref, setQuietPref] = useState(null); + const [cleanPref, setCleanPref] = useState(null); + + const fetchSurveyData = async () => { + try { + const response = await axios.get('http://localhost:3001/retake', { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}` + } + }); + console.log('Fetching profile data', response.data); + if (response.data) { + setName(response.data.profile.name) + setYear(response.data.answers.year) + setGenderAns(response.data.answers.gender) + setPetsAns(response.data.answers.pets) + setGuestsAns(response.data.answers.guests) + setSmokeAns(response.data.answers.smoke) + setDrinkAns(response.data.answers.drink) + setMaxRent(response.data.answers.rent_max) + setMinRent(response.data.answers.rent_min) + setBedAns(response.data.answers.bedtime) + setQuietAns(response.data.answers.quietness) + setCleanAns(response.data.answers.cleanliness) + + setGenderPref(response.data.preferences.gender) + setYearPref(response.data.preferences.year) + setPetsPref(response.data.preferences.pets) + setGuestsPref(response.data.preferences.guests) + setSmokePref(response.data.preferences.smoke) + setDrinkPref(response.data.preferences.drink) + setBedPref(response.data.preferences.bedtime) + setQuietPref(response.data.preferences.quietness) + setCleanPref(response.data.preferences.cleanliness) + } else { + throw new Error('Profile data is missing'); + } + } catch (error) { + console.error('Error fetching profile data:', error); + setError('Error fetching profile data: ' + error.message); + } + }; + + useEffect(() => { + fetchSurveyData(); + }, []); + + //Profile + const handleNameChange = (value) => { + setName(value); + }; + const handleYearChange = (value) => { + setYear(value); + }; + + //Answers + const handleGenderAnsChange = (value) => { + setGenderAns(value); + }; + const handlePetsAnsChange = (value) => { + setPetsAns(value); + }; + + const handleGuestsAnsChange = (value) => { + setGuestsAns(value); + } + const handleSmokeAnsChange = (value) => { + setSmokeAns(value); + } + const handleDrinkAnsChange = (value) => { + setDrinkAns(value); + } + + const handleMaxRentChange = (value) => { + setMaxRent(value); + }; + const handleMinRentChange = (value) => { + setMinRent(value); + }; + + const handleBedAnsChange = (value) => { + setBedAns(value) + } + const handleQuietAnsChange = (value) => { + setQuietAns(value) + } + const handleCleanAnsChange = (value) => { + setCleanAns(value) + } + + //Preferences + const handleGenderPrefChange = (value) => { + setGenderPref(value); + }; + const handleYearPrefChange = (value) => { + setYearPref(value); + }; + const handlePetsPrefChange = (value) => { + setPetsPref(value); + }; + + const handleGuestsPrefChange = (value) => { + setGuestsPref(value); + } + const handleSmokePrefChange = (value) => { + setSmokePref(value); + } + const handleDrinkPrefChange = (value) => { + setDrinkPref(value); + } + + const handleBedPrefChange = (value) => { + setBedPref(value) + } + const handleQuietPrefChange = (value) => { + setQuietPref(value) + } + const handleCleanPrefChange = (value) => { + setCleanPref(value) + } + + const handleSubmit = async () => { + // Check if any required questions are unanswered + if ( + !year || + !genderAns || + !petsAns || + !guestsAns || + !smokeAns || + !drinkAns || + !maxRent || + !minRent || + !bedAns || + !quietAns || + !cleanAns || + !genderPref || + !yearPref || + !petsPref || + !guestsPref || + !smokePref || + !drinkPref || + !bedPref || + !quietPref || + !cleanPref + ) { + // If any required questions are unanswered, display an alert + alert("Please answer all questions before submitting the survey."); + } else { + // If all questions are answered, proceed with submitting the survey + const surveyData = { + name, + year, + genderAns, + petsAns, + guestsAns, + smokeAns, + drinkAns, + maxRent, + minRent, + bedAns, + quietAns, + cleanAns, + genderPref, + yearPref, + petsPref, + guestsPref, + smokePref, + drinkPref, + bedPref, + quietPref, + cleanPref + }; + + try { + const response = await axios.post('http://localhost:3001/retake', surveyData, { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}` // Include the JWT token in the request + } + }); + console.log("Update response:", response.data); + if (response.status === 200) { + console.log("Survey updated successfully"); + navigate('/profile', { state: { updated: true } }); // Pass state to trigger re-fetch + } + } catch (error) { + console.error("Update error:", error); + const message = error.response?.data?.message || "An error occurred while updating the profile."; + setErrorMessage(message); + } + + } + }; + + + return ( +
+
+
+

Let's set up your profile!

+
+ +
+

What is your first and last name? (i.e. Barack Obama)

+ handleNameChange(e.target.value)} + /> +
+ +
+

What is your year?

+ + + + +
+ +
+

Tell us about yourself.

+
+ +
+

What is your gender?

+ + + +
+ +
+

Do you have pets?

+ + +
+ +
+

Specify your desired rent per person in dollars:

+
+

+
+ +
+
+ +
+

How often do you bring guests into your home?

+ + + +
+ +
+

How often do you smoke?

+ + + +
+ +
+

How often do you drink?

+ + + +
+ +
+

When is your usual bedtime?

+ + + + + + +
+ +
+

How would you rate your loudness from 1 to 5? (1 being quiet and 5 being loud)

+ + + + + +
+ +
+

How would you rate your cleanliness from 1 to 5? (1 being messy and 5 being clean)

+ + + + + +
+ +

+
+

Now tell us what you are looking for in a roommate.

+
+ +
+

Are you open to having a roommate with another gender?

+ + +
+ +
+

Are you open to having a roommate in another year of school?

+ + +
+ +
+

Are you okay with your roommate having pets?

+ + +
+ +
+

Are you okay with your roommate bringing guests?

+ + +
+ +
+

Are you okay with your roommate smoking?

+ + +
+ +
+

Are you okay with your roommate drinking?

+ + +
+ +
+

Would you prefer your roommate to have a similar bedtime as you?

+ + +
+ +
+

Would you prefer your roommate to have a similar level of loudness as you?

+ + +
+ +
+

Would you prefer your roommate to have a similar level of cleanliness as you?

+ + +
+ + +
+ ); +} + +export default Retake; \ No newline at end of file diff --git a/front-end/src/UserAnswers.css b/front-end/src/UserAnswers.css new file mode 100644 index 0000000..97d97e0 --- /dev/null +++ b/front-end/src/UserAnswers.css @@ -0,0 +1,45 @@ + +.Survey { + display: flex; + flex-direction: column; + background-color: #e8e8e8; + height: 150vh; + } + + .survey-question { + background-color: white; + margin-bottom: 1rem; + border-radius: 4px; + } + + .section { + padding: 0rem 0rem 0rem 1rem; + background-color: #BEBEBE; + margin-bottom: 1rem; + } + + label { + display: block; + } + + select, + input[type="number"] { + width: 100%; + padding: 0.75rem; + border: 1px solid #D1D1D1; + border-radius: 4px; + margin-bottom: 0.5rem; + } + + button { + background-color: #57068C; + color: white; + padding: 0.75rem 1.5rem; + border: none; + border-radius: 4px; + cursor: pointer; + } + + button:hover { + background-color: #6D28D9; + } \ No newline at end of file diff --git a/front-end/src/UserAnswers.js b/front-end/src/UserAnswers.js new file mode 100644 index 0000000..0745ac4 --- /dev/null +++ b/front-end/src/UserAnswers.js @@ -0,0 +1,100 @@ +import React, { useState, useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; +import "./UserAnswers.css"; +import Header from "./Header"; +import Button from './Button'; +import axios from 'axios'; +import { set } from 'mongoose'; + +function UserAnswers() { + const navigate = useNavigate(); + const [error, setError] = useState(''); + const [errorMessage, setErrorMessage] = useState(""); + + const[name, setName] = useState(null); + const [year, setYear] = useState(null); + const [genderAns, setGenderAns] = useState(null); + const [petsAns, setPetsAns] = useState(null); + const [guestsAns, setGuestsAns] = useState(null); + const [smokeAns, setSmokeAns] = useState(null); + const [drinkAns, setDrinkAns] = useState(null); + const [maxRent, setMaxRent] = useState(null); + const [minRent, setMinRent] = useState(null); + const [bedAns, setBedAns] = useState(null); + const [quietAns, setQuietAns] = useState(null); + const [cleanAns, setCleanAns] = useState(null); + + const fetchSurveyData = async () => { + try { + const response = await axios.get('http://localhost:3001/useranswers', { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}` + } + }); + console.log('Fetching profile data', response.data); + if (response.data) { + setName(response.data.profile.name) + setYear(response.data.answers.year) + setGenderAns(response.data.answers.gender) + setPetsAns(response.data.answers.pets) + setGuestsAns(response.data.answers.guests) + setSmokeAns(response.data.answers.smoke) + setDrinkAns(response.data.answers.drink) + setMaxRent(response.data.answers.rent_max) + setMinRent(response.data.answers.rent_min) + setBedAns(response.data.answers.bedtime) + setQuietAns(response.data.answers.quietness) + setCleanAns(response.data.answers.cleanliness) + } else { + throw new Error('Profile data is missing'); + } + } catch (error) { + console.error('Error fetching profile data:', error); + setError('Error fetching profile data: ' + error.message); + } + }; + + useEffect(() => { + fetchSurveyData(); + }, []); + + + return ( +
+
+
+

Status

+
+
+

Name: {name}

+

Year: {year}

+

Gender: {genderAns}

+

Do you have pets? {petsAns}

+
+

+
+

Rent Range

+
+
+

Max Rent: {maxRent}

+

Min Rent: {minRent}

+
+

+
+

Living Habits

+
+
+

How often do you bring over guests? {guestsAns}

+

How often do you smoke? {smokeAns}

+

How often do you drink? {drinkAns}

+

When is your usual bedtime(1: Before 10, 2: Between 10 pm and 12 am, 3: Between 12 am and 2 am, + 4: Between 2 am and 4 am, 5:After 4 am, 6: Irregular)? {bedAns}

+

How would you rate your loudness from 1 to 5(1 being quiet and 5 being loud)? {quietAns}

+

How would you rate your cleanliness from 1 to 5(1 being messy and 5 being clean)? {cleanAns}

+
+
+ ); +} + +export default UserAnswers; \ No newline at end of file