aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/settings/WebhookEventSelector.tsx
blob: 6321b8a0b3751d7bb2f556feadf402279af0c262 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Button } from "@/components/ui/button";
import {
  Command,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
} from "@/components/ui/command";
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "@/components/ui/popover";
import { Check, ChevronsUpDown } from "lucide-react";

import {
  ZWebhookEvent,
  zWebhookEventSchema,
} from "@karakeep/shared/types/webhooks";

export function WebhookEventSelector({
  value,
  onChange,
}: {
  value: ZWebhookEvent[];
  onChange: (value: ZWebhookEvent[]) => void;
}) {
  return (
    <Popover>
      <PopoverTrigger asChild>
        <Button
          variant="outline"
          role="combobox"
          className="w-full justify-between"
        >
          {value.length > 0 ? value.join(", ") : "Select events"}
          <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
        </Button>
      </PopoverTrigger>
      <PopoverContent>
        <Command>
          <CommandInput placeholder="Search events..." />
          <CommandList>
            <CommandEmpty>No events found.</CommandEmpty>
            <CommandGroup>
              {zWebhookEventSchema.options.map((eventType) => (
                <CommandItem
                  key={eventType}
                  value={eventType}
                  onSelect={() => {
                    const newEvents = value.includes(eventType)
                      ? value.filter((e) => e !== eventType)
                      : [...value, eventType];
                    onChange(newEvents);
                  }}
                >
                  {eventType}
                  {value?.includes(eventType) && (
                    <Check className="ml-auto h-4 w-4" />
                  )}
                </CommandItem>
              ))}
            </CommandGroup>
          </CommandList>
        </Command>
      </PopoverContent>
    </Popover>
  );
}