Skip to content

Commit 2493c78

Browse files
committed
add delete question operation
1 parent d3431be commit 2493c78

File tree

12 files changed

+402
-117
lines changed

12 files changed

+402
-117
lines changed

peerprep-fe/src/app/(main)/components/Main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22
import { useFilteredProblems } from '@/hooks/useFilteredProblems';
33
import FilterBar from './filter/FilterBar';
4-
import ProblemTable from './problems/ProblemTable';
4+
import ProblemTable from '../../../components/problems/ProblemTable';
55

66
export default function MainComponent() {
77
const { problems, filters, updateFilter, removeFilter, isLoading } =

peerprep-fe/src/app/(main)/components/problems/ProblemRow.tsx

Lines changed: 0 additions & 79 deletions
This file was deleted.

peerprep-fe/src/app/admin/page.tsx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
1+
'use client';
12
import React from 'react';
3+
import { useFilteredProblems } from '@/hooks/useFilteredProblems';
4+
import FilterBar from '../(main)/components/filter/FilterBar';
5+
import ProblemTable from '../../components/problems/ProblemTable';
6+
import { axiosQuestionClient } from '@/network/axiosClient';
7+
8+
function AdminPage() {
9+
const {
10+
problems,
11+
filters,
12+
updateFilter,
13+
removeFilter,
14+
isLoading,
15+
refetchFilter,
16+
} = useFilteredProblems();
17+
18+
const handleDelete = async (id: number) => {
19+
const res = await axiosQuestionClient.delete(`/questions/${id}`);
20+
if (res.status !== 200) {
21+
// Add error handling for a failed delete
22+
throw new Error('Failed to delete problem');
23+
}
24+
refetchFilter();
25+
return res;
26+
};
227

3-
function page() {
428
return (
5-
<div className="flex min-h-screen items-center justify-center bg-gray-900">
6-
page
29+
<div className="min-h-screen bg-gray-900 p-6 pt-24 text-gray-100">
30+
<div className="mx-auto max-w-7xl">
31+
<FilterBar
32+
filters={filters}
33+
updateFilter={updateFilter}
34+
removeFilter={removeFilter}
35+
/>
36+
<ProblemTable
37+
problems={problems}
38+
isLoading={isLoading}
39+
showActions={true}
40+
handleDelete={handleDelete}
41+
/>
42+
</div>
743
</div>
844
);
945
}
1046

11-
export default page;
47+
export default AdminPage;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
import {
3+
Dialog,
4+
DialogContent,
5+
DialogDescription,
6+
DialogHeader,
7+
DialogTitle,
8+
} from '../ui/dialog';
9+
import { Button } from '../ui/button';
10+
11+
type Props = {
12+
isOpen: boolean;
13+
onClose: () => void;
14+
title?: string;
15+
subtitle?: string;
16+
description: string;
17+
callback?: () => void;
18+
callbackTitle?: string;
19+
};
20+
21+
const ActionDialog = ({
22+
isOpen,
23+
onClose,
24+
title,
25+
subtitle,
26+
description,
27+
callback,
28+
callbackTitle,
29+
}: Props) => {
30+
return (
31+
<Dialog open={isOpen} onOpenChange={onClose}>
32+
<DialogContent className="bg-black">
33+
<DialogHeader>
34+
<DialogTitle>{title}</DialogTitle>
35+
<DialogDescription>{subtitle}</DialogDescription>
36+
</DialogHeader>
37+
<div className="mt-4">
38+
<h3 className="mb-2 text-lg font-semibold">Description:</h3>
39+
<p>{description}</p>
40+
</div>
41+
<div className="mt-6 flex justify-end">
42+
<Button variant="secondary" onClick={callback}>
43+
{callbackTitle}
44+
</Button>
45+
</div>
46+
</DialogContent>
47+
</Dialog>
48+
);
49+
};
50+
51+
export default ActionDialog;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import {
3+
Dialog,
4+
DialogContent,
5+
DialogDescription,
6+
DialogHeader,
7+
DialogTitle,
8+
} from '../ui/dialog';
9+
10+
type Props = {
11+
isOpen: boolean;
12+
onClose: () => void;
13+
title?: string;
14+
description: string;
15+
};
16+
17+
const InformationDialog = ({ isOpen, onClose, title, description }: Props) => {
18+
return (
19+
<Dialog open={isOpen} onOpenChange={onClose}>
20+
<DialogContent className="bg-black">
21+
<DialogHeader>
22+
<DialogTitle>{title}</DialogTitle>
23+
<DialogDescription />
24+
</DialogHeader>
25+
<div className="mt-4">
26+
<p>{description}</p>
27+
</div>
28+
</DialogContent>
29+
</Dialog>
30+
);
31+
};
32+
33+
export default InformationDialog;
Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,53 @@
1+
import React from 'react';
12
import {
23
Dialog,
34
DialogContent,
5+
DialogDescription,
46
DialogHeader,
57
DialogTitle,
6-
DialogDescription,
7-
} from '@/components/ui/dialog';
8-
import { Button } from '@/components/ui/button';
8+
} from '../ui/dialog';
9+
import { Button } from '../ui/button';
10+
import { getDifficultyString } from '@/lib/utils';
911
import { ProblemDialogData } from '@/types/types';
1012

11-
export default function ProblemDialog({
12-
isOpen,
13-
onClose,
14-
problem,
15-
}: {
13+
type Props = {
1614
isOpen: boolean;
1715
onClose: () => void;
1816
problem: ProblemDialogData | null;
19-
}) {
20-
if (!problem) return null;
17+
requestCallback: () => void;
18+
requestTitle: string;
19+
};
2120

22-
const difficultyText =
23-
problem.difficulty === 1
24-
? 'Easy'
25-
: problem.difficulty === 2
26-
? 'Medium'
27-
: 'Hard';
21+
function ProblemInputDialog({
22+
isOpen,
23+
onClose,
24+
problem,
25+
requestCallback,
26+
requestTitle,
27+
}: Props) {
28+
if (!problem) return null;
2829

2930
return (
3031
<Dialog open={isOpen} onOpenChange={onClose}>
3132
<DialogContent className="bg-black">
3233
<DialogHeader>
3334
<DialogTitle>{problem.title}</DialogTitle>
34-
<DialogDescription>Difficulty: {difficultyText}</DialogDescription>
35+
<DialogDescription>
36+
Difficulty: {getDifficultyString(problem.difficulty)}
37+
</DialogDescription>
3538
</DialogHeader>
3639
<div className="mt-4">
3740
<h3 className="mb-2 text-lg font-semibold">Description:</h3>
3841
<p>{problem.description}</p>
3942
</div>
4043
<div className="mt-6 flex justify-end">
41-
{/* TODO: link to match route/page */}
42-
<Button variant="secondary">Match</Button>
44+
<Button variant="secondary" onClick={requestCallback}>
45+
{requestTitle}
46+
</Button>
4347
</div>
4448
</DialogContent>
4549
</Dialog>
4650
);
4751
}
52+
53+
export default ProblemInputDialog;

0 commit comments

Comments
 (0)