Skip to content

Commit

Permalink
A way for admin to delete map during review
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Oct 21, 2024
1 parent 5363868 commit 3718613
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
19 changes: 13 additions & 6 deletions app/admin/review/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import {
} from "@/components/ui/card";
import { api } from "@/convex/_generated/api";

const Page = () => {
export default function AdminReviewPage() {
const isAdmin = useQuery(api.users.isAdmin);
const maps = useQuery(api.maps.getMaps, { isReviewed: false });
const adminApprovalMutation = useMutation(api.maps.approveMap);
const adminRejectMapMutation = useMutation(api.maps.rejectMap);

if (isAdmin == true) {
return (
<div className="container mx-auto min-h-screen gap-8 py-12 pb-24">
<h1 className="mb-6 text-center text-3xl font-bold">Review Maps</h1>
<div className="flex flex-col items-center justify-around gap-4">
<div className="grid grid-cols-[max-content_max-content] justify-center gap-4">
{maps?.map((map) => (
<Card key={map._id}>
<CardHeader>
Expand All @@ -32,7 +33,7 @@ const Page = () => {
<Map map={map.grid} />
</CardContent>

<CardFooter className="flex justify-center">
<CardFooter className="flex justify-center gap-2">
<Button
variant="outline"
onClick={async () => {
Expand All @@ -41,6 +42,14 @@ const Page = () => {
>
Approve
</Button>
<Button
variant="destructive"
onClick={async () => {
await adminRejectMapMutation({ mapId: map._id });
}}
>
Reject
</Button>
</CardFooter>
</Card>
))}
Expand All @@ -50,6 +59,4 @@ const Page = () => {
}

return <div>Not an admin</div>;
};

export default Page;
}
6 changes: 2 additions & 4 deletions app/prompts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "@/components/ui/table";
import { api } from "@/convex/_generated/api";

const Page = () => {
export default function PromptsPage() {
const prompts = useQuery(api.prompts.getAllPrompts);
const enablePrompt = useMutation(api.prompts.enablePrompt);
const deletePrompt = useMutation(api.prompts.deletePrompt);
Expand Down Expand Up @@ -91,6 +91,4 @@ const Page = () => {
</div>
</div>
);
};

export default Page;
}
9 changes: 9 additions & 0 deletions convex/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ export const approveMap = adminMutationBuilder({
},
});

export const rejectMap = adminMutationBuilder({
args: {
mapId: v.id("maps"),
},
handler: async (ctx, args) => {
await ctx.db.delete(args.mapId);
},
});

export const getMapByLevel = query({
args: { level: v.number() },
handler: async (ctx, args) => {
Expand Down

0 comments on commit 3718613

Please sign in to comment.