import { FC, useMemo, useState } from 'react'; import { Select } from '@gitroom/react/form/select'; import { useT } from '@gitroom/react/translation/get.transation.service.client'; import { useClickOutside } from '@mantine/hooks'; import { isUSCitizen } from '@gitroom/frontend/components/launches/helpers/isuscitizen.utils'; import clsx from 'clsx'; import { RepeatIcon, DropdownArrowIcon } from '@gitroom/frontend/components/ui/icons'; const list = [ { value: 1, label: 'Day', }, { value: 2, label: 'Two Days', }, { value: 3, label: 'Three Days', }, { value: 4, label: 'Four Days', }, { value: 5, label: 'Five Days', }, { value: 6, label: 'Six Days', }, { value: 7, label: 'Week', }, { value: 14, label: 'Two Weeks', }, { value: 30, label: 'Month', }, { value: null, label: 'Cancel', }, ]; export const RepeatComponent: FC<{ repeat: number | null; onChange: (newVal: number) => void; }> = (props) => { const { repeat } = props; const t = useT(); const [isOpen, setIsOpen] = useState(false); const ref = useClickOutside(() => { if (!isOpen) { return; } setIsOpen(false); }); const everyLabel = useMemo(() => { if (!repeat) { return ''; } return list.find((p) => p.value === repeat)?.label; }, [repeat]); return (
setIsOpen(!isOpen)} className="px-[16px] justify-center flex gap-[8px] items-center h-full select-none flex-1" >
{repeat ? `Repeat Post Every ${everyLabel}` : t('repeat_post_every', 'Repeat Post Every...')}
{isOpen && (
{list.map((p) => (
{ props.onChange(Number(p.value)); setIsOpen(false); }} key={p.label} className="h-[40px] py-[8px] px-[20px] -mx-[12px] hover:bg-newBgColor" > {p.label}
))}
)}
); };