Skip to content

Commit 6adff72

Browse files
authored
feat: delete button on current round's responses (#48)
1 parent 5104ce8 commit 6adff72

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

src/modules/common/response/Response.tsx

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { FC } from 'react';
22
import { useTranslation } from 'react-i18next';
33

4+
import DeleteIcon from '@mui/icons-material/Delete';
45
import Button from '@mui/material/Button';
56
import Card from '@mui/material/Card';
67
import CardActions from '@mui/material/CardActions';
78
import CardContent from '@mui/material/CardContent';
89
import Divider from '@mui/material/Divider';
10+
import IconButton from '@mui/material/IconButton';
911
import Typography from '@mui/material/Typography';
1012
import grey from '@mui/material/colors/grey';
1113

@@ -20,16 +22,20 @@ const Response: FC<{
2022
onSelect?: (id: string) => void;
2123
enableBuildAction?: boolean;
2224
evaluationType?: EvaluationType;
25+
onDelete?: (id: string) => void;
2326
}> = ({
2427
responseId,
2528
response,
2629
onSelect,
30+
onDelete,
2731
enableBuildAction = true,
2832
evaluationType = EvaluationType.None,
2933
}) => {
3034
const { t } = useTranslation();
3135

3236
const showSelectButton = typeof onSelect !== 'undefined';
37+
const showDeleteButton = typeof onDelete !== 'undefined';
38+
const showActions = showDeleteButton || showSelectButton;
3339

3440
const renderEvaluationComponent = (): JSX.Element => {
3541
if (evaluationType === EvaluationType.UsefulnessNoveltyRating) {
@@ -58,18 +64,28 @@ const Response: FC<{
5864
</Typography>
5965
</CardContent>
6066
{evaluationType !== EvaluationType.None && renderEvaluationComponent()}
61-
{showSelectButton && (
67+
{showActions && (
6268
<>
6369
<Divider />
6470
<CardActions>
65-
<Button
66-
disabled={!enableBuildAction}
67-
onClick={() => {
68-
if (typeof onSelect !== 'undefined') onSelect(responseId);
69-
}}
70-
>
71-
{t('BUILD_ON_THIS_IDEA')}
72-
</Button>
71+
{showSelectButton && (
72+
<Button
73+
disabled={!enableBuildAction}
74+
onClick={() => {
75+
if (typeof onSelect !== 'undefined') onSelect(responseId);
76+
}}
77+
>
78+
{t('BUILD_ON_THIS_IDEA')}
79+
</Button>
80+
)}
81+
{showDeleteButton && (
82+
<IconButton
83+
sx={{ marginLeft: 'auto' }}
84+
onClick={() => onDelete(responseId)}
85+
>
86+
<DeleteIcon />
87+
</IconButton>
88+
)}
7389
</CardActions>
7490
</>
7591
)}

src/modules/responseCollection/MyResponses.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import Typography from '@mui/material/Typography';
55

66
import { useLocalContext } from '@graasp/apps-query-client';
77

8+
import { mutations } from '@/config/queryClient';
9+
import useActivityState from '@/hooks/useActivityState';
810
import Response from '@/modules/common/response/Response';
911

1012
import { useActivityContext } from '../context/ActivityContext';
1113

1214
const MyResponses: FC = () => {
1315
const { memberId } = useLocalContext();
1416
const { myResponses } = useActivityContext();
17+
const { round } = useActivityState();
18+
const { mutate: deleteAppData } = mutations.useDeleteAppData();
19+
20+
const handleDelete = (id: string): void => deleteAppData({ id });
1521
if (memberId) {
1622
return (
1723
<>
@@ -26,6 +32,9 @@ const MyResponses: FC = () => {
2632
key={response.id}
2733
response={response.data}
2834
responseId={response.id}
35+
onDelete={
36+
response.data.round === round ? handleDelete : undefined
37+
}
2938
/>
3039
</Grid>
3140
))

0 commit comments

Comments
 (0)