Skip to content

Commit

Permalink
wip(frontend): submission delete in challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Jun 2, 2024
1 parent e6175ac commit 8da23c9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
56 changes: 54 additions & 2 deletions web/src/pages/admin/challenges/[id]/submissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import withChallengeEdit from "@/components/layouts/admin/withChallengeEdit";
import MDIcon from "@/components/ui/MDIcon";
import { Challenge } from "@/types/challenge";
import { Submission } from "@/types/submission";
import { showSuccessNotification } from "@/utils/notification";
import {
Divider,
Group,
Expand All @@ -18,6 +19,7 @@ import {
Tooltip,
LoadingOverlay,
} from "@mantine/core";
import { modals } from "@mantine/modals";
import dayjs from "dayjs";
import { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
Expand All @@ -34,6 +36,8 @@ function Page() {
const [rowsPerPage, _] = useState<number>(10);
const [page, setPage] = useState<number>(1);

const [refresh, setRefresh] = useState<number>(0);

const [loading, setLoading] = useState<boolean>(false);

const statusMap = new Map<number, { color: string; label: string }>([
Expand Down Expand Up @@ -104,11 +108,52 @@ function Page() {
});
}

function deleteSubmission(submission?: Submission) {
if (submission) {
submissionApi
.deleteSubmission({
id: submission?.id,
})
.then(() => {
showSuccessNotification({
message: "提交记录已移除",
});
setRefresh((prev) => prev + 1);
});
}
}

const openDeleteSubmissionModal = (submission?: Submission) =>
modals.openConfirmModal({
centered: true,
children: (
<>
<Flex gap={10} align={"center"}>
<MDIcon>verified</MDIcon>
<Text fw={600}>删除提交记录</Text>
</Flex>
<Divider my={10} />
<Text>你确定要删除提交记录 {submission?.flag} 吗?</Text>
</>
),
withCloseButton: false,
labels: {
confirm: "确定",
cancel: "取消",
},
confirmProps: {
color: "red",
},
onConfirm: () => {
deleteSubmission(submission);
},
});

useEffect(() => {
if (challenge) {
getSubmissions();
}
}, [challenge, page, rowsPerPage]);
}, [challenge, page, rowsPerPage, refresh]);

useEffect(() => {
getChallenge();
Expand Down Expand Up @@ -220,7 +265,14 @@ function Page() {
withArrow
label="删除提交记录"
>
<ActionIcon variant="transparent">
<ActionIcon
variant="transparent"
onClick={() =>
openDeleteSubmissionModal(
submission
)
}
>
<MDIcon color={"red"}>
delete
</MDIcon>
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/challenges/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export default function Page() {
</Flex>
<Stack w={"120%"}>
<Box mih={"calc(100vh - 260px)"} pos={"relative"}>
<LoadingOverlay visible={loading} />
<LoadingOverlay visible={loading} zIndex={2} />
<Group
gap={"lg"}
sx={{
Expand Down

0 comments on commit 8da23c9

Please sign in to comment.