Skip to content
refs
History
66 lines · 3.1 KBRaw
1import { Banner, Button, InputArea, Popover, Radio } from "@refs/design-system";
2import { CheckCircleIcon, XIcon } from "@refs/design-system/icons";
3import { useState } from "react";
4import { useFetcher } from "react-router";
5
6const VERDICTS = [
7 { value: "comment", label: "Comment", description: "Give feedback without a verdict." },
8 { value: "approve", label: "Approve", description: "Give feedback and approve the merge of this revision." },
9 { value: "request-changes", label: "Request changes", description: "Give feedback that must be addressed before the merge." },
10] as const;
11
12/** The Review button of a pull request. It opens a form for a summary and a verdict on the revision `revision`. */
13export function FinishReview({ action, revision }: { action: string; revision: string }) {
14 const [open, setOpen] = useState(false);
15 const fetcher = useFetcher<{ error?: string | null }>();
16 const busy = fetcher.state !== "idle";
17 return (
18 <Popover open={open} onOpenChange={setOpen}>
19 <Popover.Trigger
20 render={
21 <Button size="sm" variant="primary" icon={<CheckCircleIcon />}>
22 Review
23 </Button>
24 }
25 />
26 <Popover.Content align="end" className="w-[34rem] max-w-[calc(100vw-2rem)] p-0">
27 <fetcher.Form method="post" action={action} className="flex flex-col">
28 <input type="hidden" name="intent" value="review" />
29 <input type="hidden" name="revision" value={revision} />
30 <div className="flex items-center justify-between gap-3 px-4 pt-3 pb-2">
31 <Popover.Title className="text-base">Finish your review</Popover.Title>
32 <Button type="button" variant="ghost" shape="square" size="sm" aria-label="Close" onClick={() => setOpen(false)}>
33 <XIcon size={16} />
34 </Button>
35 </div>
36 <div className="flex flex-col gap-4 px-4 pb-4">
37 <InputArea
38 name="body"
39 rows={5}
40 autoFocus
41 aria-label="Summary"
42 placeholder="Summarize the revision and your verdict. Markdown works."
43 onKeyDown={(event) => {
44 if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) event.currentTarget.form?.requestSubmit();
45 }}
46 />
47 <Radio.Group name="verdict" defaultValue="comment" appearance="card" legend="Verdict">
48 {VERDICTS.map((verdict) => (
49 <Radio.Item key={verdict.value} value={verdict.value} label={verdict.label} description={verdict.description} />
50 ))}
51 </Radio.Group>
52 {fetcher.data?.error && <Banner variant="error" description={fetcher.data.error} />}
53 </div>
54 <div className="flex justify-end gap-2 px-4 py-3 shadow-[inset_0_1px_0_var(--hairline)]">
55 <Button type="button" variant="secondary" onClick={() => setOpen(false)}>
56 Cancel
57 </Button>
58 <Button type="submit" variant="primary" loading={busy}>
59 Submit review
60 </Button>
61 </div>
62 </fetcher.Form>
63 </Popover.Content>
64 </Popover>
65 );
66}