From 5eaa82cfe1d59a55b00c645dc8101addb4858abf Mon Sep 17 00:00:00 2001 From: anaspacheco Date: Tue, 28 Nov 2023 11:59:40 -0500 Subject: [PATCH 1/3] connected frontend of feedback --- back-end/models/Feedback.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/back-end/models/Feedback.js b/back-end/models/Feedback.js index b85c78a..7cc4fd0 100644 --- a/back-end/models/Feedback.js +++ b/back-end/models/Feedback.js @@ -4,8 +4,8 @@ const Schema = mongoose.Schema const FeedbackSchema = new Schema({ user: { - type: String, - unique: true, + type: Number, + unique: false, required: true, }, timestamp: { @@ -19,7 +19,9 @@ const FeedbackSchema = new Schema({ feedback:{ type: String, required: true, - }, + }, +}, { + unique: false, }) const Feedback = mongoose.model("Feedback", FeedbackSchema) From 5956e87185bbfdfa8d4c3c899542a27f3ca5cde6 Mon Sep 17 00:00:00 2001 From: anaspacheco Date: Tue, 28 Nov 2023 12:04:41 -0500 Subject: [PATCH 2/3] integrated front-end --- front-end/package.json | 2 +- front-end/src/App.js | 4 +- .../settings/FeedbackSupportPage.js | 50 ++++++++++++++++--- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/front-end/package.json b/front-end/package.json index 6180a12..1f9c606 100644 --- a/front-end/package.json +++ b/front-end/package.json @@ -7,7 +7,7 @@ "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", - "axios": "^1.5.1", + "axios": "^1.6.2", "mongodb": "^6.3.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/front-end/src/App.js b/front-end/src/App.js index 7ae150d..e471379 100644 --- a/front-end/src/App.js +++ b/front-end/src/App.js @@ -15,8 +15,8 @@ import PrivacyPolicyPage from './components/settings/PrivacyPolicyPage'; import LoadingScreen from './components/LoadingScreen'; import TutorialComponent from './components/TutorialComponent'; + // Import hooks and utilities -import useDarkMode from './hooks/darkMode'; import { registerService } from './utils/serviceRegister'; import { getUserPos, loadGoogleMapsAPI } from './utils/mapUtility'; @@ -28,7 +28,6 @@ import './css/tutorialComponent.css'; export const TutorialContext = createContext(); function App() { - const [colorTheme, setTheme] = useDarkMode(); const [isLoading, setIsLoading] = useState(true); const isFirstTimeUser = localStorage.getItem('isFirst') !== 'false'; const [tutorialIndex, setTutorialIndex] = useState(0); @@ -38,6 +37,7 @@ function App() { let key = localStorage.key(i); let value = localStorage.getItem(key); localStorageItems[key] = value; + //console.log(key, value) } useEffect(() => { diff --git a/front-end/src/components/settings/FeedbackSupportPage.js b/front-end/src/components/settings/FeedbackSupportPage.js index 28ee7ef..3ff7e4c 100644 --- a/front-end/src/components/settings/FeedbackSupportPage.js +++ b/front-end/src/components/settings/FeedbackSupportPage.js @@ -1,13 +1,45 @@ -import { useState } from 'react'; -import { Link } from 'react-router-dom'; -import '../../css/settingsPage.css'; +import { useState } from "react"; +import { Link } from "react-router-dom"; +import { + localStorageLoad, +} from "../../utils/localStorageSaveLoad.js"; +import "../../css/settingsPage.css"; +import axios from "axios"; const FeedbackSupportPage = () => { - const [category, setCategory] = useState(''); - const [feedback, setFeedback] = useState(''); + const [response, setResponse] = useState({}); + const [category, setCategory] = useState(""); + const [feedback, setFeedback] = useState(""); + const [errorMessage, setErrorMessage] = useState(""); - const handleSubmit = () => { - // later link with backend + const userId = localStorageLoad("deviceId"); + + const handleSubmit = async (e) => { + e.preventDefault(); + if (category === "" || feedback === "") { + setErrorMessage("Please fill out all fields"); + return; + } + try { + const requestData = { + user: userId, + timestamp: Date.now(), + category: category, + feedback: feedback, + }; + const response = await axios.post( + `${process.env.REACT_APP_BACKEND}/feedback/newfeedback`, + requestData + ); + console.log(`Server response: ${JSON.stringify(response.data, null, 0)}`); + setResponse(response.data); + } catch (err) { + console.log(err); + setErrorMessage(err.message); + } finally { + setCategory(""); + setFeedback(""); + } }; return ( @@ -31,7 +63,9 @@ const FeedbackSupportPage = () => { > - + From 626e1437660c33bff23d4bed7eb15b31f4901c84 Mon Sep 17 00:00:00 2001 From: anaspacheco Date: Tue, 28 Nov 2023 12:26:29 -0500 Subject: [PATCH 3/3] fixed tests --- back-end/test/feedback.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back-end/test/feedback.test.js b/back-end/test/feedback.test.js index 2935d04..25f91e4 100644 --- a/back-end/test/feedback.test.js +++ b/back-end/test/feedback.test.js @@ -9,7 +9,7 @@ const server = require("../app"); describe("Feedback Routes", () => { const formData = { - user: "blxyaaa", + user: 12345, timestamp: new Date(), category: "test_category", feedback: "Test feedback content",