"use client"; import { Icon } from "@iconify/react"; import { ReportReason } from "@prisma/client"; import { useSelect } from "downshift"; interface Props { reason: ReportReason | undefined; setReason: React.Dispatch>; } const reasonMap: Record = { INAPPROPRIATE: "Inappropriate content", SPAM: "Spam", COPYRIGHT: "Copyrighted content", BAD_QUALITY: "Bad quality", OTHER: "Other...", }; const reasonOptions = Object.entries(reasonMap).map(([value, label]) => ({ value: value as ReportReason, label, })); export default function ReasonSelector({ reason, setReason }: Props) { const { isOpen, getToggleButtonProps, getMenuProps, getItemProps, highlightedIndex, selectedItem } = useSelect({ items: reasonOptions, selectedItem: reason ? reasonOptions.find((option) => option.value === reason) : null, itemToString: (item) => (item ? item.label : ""), onSelectedItemChange: ({ selectedItem }) => { if (selectedItem) { setReason(selectedItem.value); } }, }); return (
{/* Toggle button to open the dropdown */} {/* Dropdown menu */}
    {isOpen && reasonOptions.map((item, index) => (
  • {item.label}
  • ))}
); }