Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
110 lines
3.1 KiB
TypeScript
110 lines
3.1 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useId, useState, type FormEvent } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { toast } from "sonner";
|
|
|
|
import { reviewRibbonSubmission } from "@/app/(frontend)/awards/design/actions";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "@/components/ui/dialog";
|
|
import { Label } from "@/components/ui/label";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import type { RibbonSubmission } from "@/payload-types";
|
|
|
|
interface RejectRibbonDialogProps {
|
|
readonly submission: RibbonSubmission;
|
|
readonly open: boolean;
|
|
readonly onOpenChange: (open: boolean) => void;
|
|
}
|
|
|
|
export function RejectRibbonDialog({ submission, open, onOpenChange }: RejectRibbonDialogProps) {
|
|
const router = useRouter();
|
|
const noteId = useId();
|
|
const [reviewNote, setReviewNote] = useState("");
|
|
const [pending, setPending] = useState(false);
|
|
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
setReviewNote("");
|
|
setPending(false);
|
|
}, [open]);
|
|
|
|
async function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
setPending(true);
|
|
|
|
try {
|
|
const result = await reviewRibbonSubmission(submission.id, "rejected", {
|
|
reviewNote: reviewNote.trim() || undefined,
|
|
});
|
|
|
|
if (!result.success) {
|
|
toast.error(result.error ?? "Could not reject this ribbon.");
|
|
return;
|
|
}
|
|
|
|
toast.success("Ribbon rejected");
|
|
onOpenChange(false);
|
|
router.refresh();
|
|
} catch (error) {
|
|
toast.error(error instanceof Error ? error.message : "Could not reject this ribbon.");
|
|
} finally {
|
|
setPending(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Dialog
|
|
open={open}
|
|
onOpenChange={(nextOpen) => {
|
|
if (!pending) onOpenChange(nextOpen);
|
|
}}
|
|
>
|
|
<DialogContent className="sm:max-w-md">
|
|
<DialogHeader>
|
|
<DialogTitle>Reject ribbon</DialogTitle>
|
|
<DialogDescription>
|
|
Add optional feedback for the submitter before rejecting "{submission.name}".
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<form className="flex flex-col gap-4" onSubmit={handleSubmit}>
|
|
<div className="flex flex-col gap-1.5">
|
|
<Label htmlFor={noteId}>Review note</Label>
|
|
<Textarea
|
|
id={noteId}
|
|
value={reviewNote}
|
|
onChange={(event) => setReviewNote(event.target.value)}
|
|
rows={4}
|
|
disabled={pending}
|
|
/>
|
|
</div>
|
|
<DialogFooter>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
onClick={() => onOpenChange(false)}
|
|
disabled={pending}
|
|
>
|
|
Cancel
|
|
</Button>
|
|
<Button
|
|
type="submit"
|
|
variant="outline"
|
|
className="text-destructive hover:text-destructive"
|
|
disabled={pending}
|
|
>
|
|
{pending ? "Rejecting..." : "Reject ribbon"}
|
|
</Button>
|
|
</DialogFooter>
|
|
</form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|