import React from "react"; // headless ui import { Popover } from "@headlessui/react"; // lucide icons import { CalendarCheck2, CalendarClock, X } from "lucide-react"; // react date picker import DatePicker from "react-datepicker"; // mobx import { observer } from "mobx-react-lite"; // components import { Tooltip } from "@plane/ui"; // hooks import useDynamicDropdownPosition from "hooks/use-dynamic-dropdown"; // helpers import { renderDateFormat } from "helpers/date-time.helper"; export interface IIssuePropertyDate { value: any; onChange: (date: any) => void; disabled?: boolean; type: "start_date" | "target_date"; } const DATE_OPTIONS = { start_date: { key: "start_date", placeholder: "Start date", icon: CalendarClock, }, target_date: { key: "target_date", placeholder: "Target date", icon: CalendarCheck2, }, }; export const IssuePropertyDate: React.FC = observer((props) => { const { value, onChange, disabled, type } = props; const dropdownBtn = React.useRef(null); const dropdownOptions = React.useRef(null); const [isOpen, setIsOpen] = React.useState(false); useDynamicDropdownPosition(isOpen, () => setIsOpen(false), dropdownBtn, dropdownOptions); const dateOptionDetails = DATE_OPTIONS[type]; return ( {({ open }) => { if (open) { if (!isOpen) setIsOpen(true); } else if (isOpen) setIsOpen(false); return ( <>
{value && ( <>
{value}
{ if (onChange) onChange(null); }} >
)}
{({ close }) => ( { if (onChange && val) { onChange(renderDateFormat(val)); close(); } }} dateFormat="dd-MM-yyyy" calendarClassName="h-full" inline /> )}
); }}
); });