Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Delete Button to Admin Page #297

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ app.post('/api/remove-like', authenticate, likeHandler(true));

app.put('/api/update-review-status/:reviewDocId/:newStatus', async (req, res) => {
const { reviewDocId, newStatus } = req.params;
const statusList = ['PENDING', 'APPROVED', 'DECLINED'];
const statusList = ['PENDING', 'APPROVED', 'DECLINED', 'DELETED'];
try {
if (!statusList.includes(newStatus)) {
res.status(400).send('Invalid status type');
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/components/Admin/AdminReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import axios from 'axios';
type Props = {
readonly review: ReviewWithId;
readonly setToggle: React.Dispatch<React.SetStateAction<boolean>>;
readonly declinedSection: boolean;
};

export type RatingInfo = {
Expand Down Expand Up @@ -61,7 +62,7 @@ const useStyles = makeStyles(() => ({
},
}));

const AdminReviewComponent = ({ review, setToggle }: Props): ReactElement => {
const AdminReviewComponent = ({ review, setToggle, declinedSection }: Props): ReactElement => {
const { detailedRatings, overallRating, date, reviewText, photos } = review;
const formattedDate = format(new Date(date), 'MMM dd, yyyy').toUpperCase();
const { root, dateText, ratingInfo, photoStyle, photoRowStyle } = useStyles();
Expand Down Expand Up @@ -169,6 +170,17 @@ const AdminReviewComponent = ({ review, setToggle }: Props): ReactElement => {

<CardActions>
<Grid container spacing={2} alignItems="center" justifyContent="flex-end">
{declinedSection && (
<Grid item>
<Button
onClick={() => changeStatus('DELETED')}
variant="contained"
style={{ color: colors.black }}
>
<strong>Delete</strong>
</Button>
</Grid>
)}
<Grid item>
<Button
onClick={() => changeStatus('DECLINED')}
Expand Down
12 changes: 10 additions & 2 deletions frontend/src/pages/AdminPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ const AdminPage = (): ReactElement => {
<Grid container item spacing={3}>
{sortReviews(pendingData, 'date').map((review, index) => (
<Grid item xs={12} key={index}>
<AdminReviewComponent review={review} setToggle={setToggle} />
<AdminReviewComponent
review={review}
setToggle={setToggle}
declinedSection={false}
/>
</Grid>
))}
</Grid>
Expand All @@ -62,7 +66,11 @@ const AdminPage = (): ReactElement => {
<Grid container item spacing={3}>
{sortReviews(declinedData, 'date').map((review, index) => (
<Grid item xs={12} key={index}>
<AdminReviewComponent review={review} setToggle={setToggle} />
<AdminReviewComponent
review={review}
setToggle={setToggle}
declinedSection={true}
/>
</Grid>
))}
</Grid>
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4116,9 +4116,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001125, caniuse-lite@^1.0.30001286:
version "1.0.30001431"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001431.tgz"
integrity sha512-zBUoFU0ZcxpvSt9IU66dXVT/3ctO1cy4y9cscs1szkPlcWb6pasYM144GqrUygUbT+k7cmUCW61cvskjcv0enQ==
version "1.0.30001525"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001525.tgz"
integrity sha512-/3z+wB4icFt3r0USMwxujAqRvaD/B7rvGTsKhbhSQErVrJvkZCLhgNLJxU8MevahQVH6hCU9FsHdNUFbiwmE7Q==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down
Loading