Skip to content

Commit

Permalink
flagging functionality working
Browse files Browse the repository at this point in the history
  • Loading branch information
WSalinas315 committed Dec 5, 2022
1 parent 7dcf74e commit 9f9e5d9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 10 additions & 2 deletions server/routes/feedback.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const pool = require('../modules/pool.js');

// GET for admin functionality
router.get('/', (req, res) => {
let queryText = `SELECT * FROM "feedback";`;
let queryText = `SELECT * FROM "feedback" ORDER BY "id";`;
pool.query(queryText).then(result => {
res.send(result.rows);
}).catch(error => {
Expand Down Expand Up @@ -39,6 +39,14 @@ router.delete('/:id', (req, res) => {
});

// PUT for admin flagging

router.put('/:id', (req, res) => {
let changeID = req.params.id;
let queryText = `UPDATE "feedback" SET "flagged" = NOT "flagged" WHERE "id"=$1;`;
pool.query(queryText, [changeID]).then(result => {
res.sendStatus(200);
}).catch(error => {
console.log('Error with updating feedback flagging in database:', error);
});
});

module.exports = router;
18 changes: 16 additions & 2 deletions src/components/Admin/Admin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react";
import TableHeader from "../TableHeader/TableHeader";
import StarsIcon from "@mui/icons-material/Stars";
import DeleteIcon from '@mui/icons-material/Delete';
import Button from "@mui/material";
import { Flag, FlagOutlined } from "@mui/icons-material";
import axios from 'axios';
import './Admin.css';

Expand Down Expand Up @@ -33,6 +33,15 @@ export default function Admin() {
});
}

const toggleFlag = (id) =>{
console.log('id is:', id);
axios.put('/feedback/'+id).then(response =>{
fetchFeedback();
}).catch(error => {
console.log('Error with Axios Delete in Admin.jsx:', error );
});
}

return (
<div className="admin-content">
<div className="stars">
Expand All @@ -48,7 +57,12 @@ export default function Admin() {
<td>{feedbackItem.understanding}</td>
<td>{feedbackItem.support}</td>
<td>{feedbackItem.comments}</td>
<td>Flag Button</td>
<td>
{feedbackItem.flagged ?
<Flag onClick={() => toggleFlag(feedbackItem.id)}/>
:
<FlagOutlined onClick={() => toggleFlag(feedbackItem.id)}/>}
</td>
<td><DeleteIcon onClick={() => deleteRow(feedbackItem.id)}/></td>
</tr>
))}
Expand Down

0 comments on commit 9f9e5d9

Please sign in to comment.