Skip to content

Commit

Permalink
Merge pull request #87 from agiledev-students-fall2023/anasofia
Browse files Browse the repository at this point in the history
connected frontend and fixed tests
  • Loading branch information
unfiltered-syrup authored Nov 28, 2023
2 parents 84e4b47 + 626e143 commit 3fc2c52
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
8 changes: 5 additions & 3 deletions back-end/models/Feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const Schema = mongoose.Schema

const FeedbackSchema = new Schema({
user: {
type: String,
unique: true,
type: Number,
unique: false,
required: true,
},
timestamp: {
Expand All @@ -19,7 +19,9 @@ const FeedbackSchema = new Schema({
feedback:{
type: String,
required: true,
},
},
}, {
unique: false,
})

const Feedback = mongoose.model("Feedback", FeedbackSchema)
Expand Down
2 changes: 1 addition & 1 deletion back-end/test/feedback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion front-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions front-end/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand All @@ -38,6 +37,7 @@ function App() {
let key = localStorage.key(i);
let value = localStorage.getItem(key);
localStorageItems[key] = value;
//console.log(key, value)
}

useEffect(() => {
Expand Down
50 changes: 42 additions & 8 deletions front-end/src/components/settings/FeedbackSupportPage.js
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -31,7 +63,9 @@ const FeedbackSupportPage = () => {
>
<option value="">--Select--</option>
<option value="Bug Report">Bug Report</option>
<option value="User Experience Feedback">User Experience Feedback</option>
<option value="User Experience Feedback">
User Experience Feedback
</option>
<option value="Bus Schedule Error">Bus Schedule Error</option>
</select>
</div>
Expand Down

0 comments on commit 3fc2c52

Please sign in to comment.