MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / InputDateTime

Function InputDateTime

apps/start/src/components/ui/input-date-time.tsx:8–88  ·  view source on GitHub ↗
({
  value,
  onChange,
  placeholder = 'Select date and time',
  label,
  ...props
}: {
  value: string | undefined;
  onChange: (value: string) => void;
  label: string;
} & InputHTMLAttributes<HTMLInputElement>)

Source from the content-addressed store, hash-verified

6import { Input } from './input';
7
8export function InputDateTime({
9 value,
10 onChange,
11 placeholder = 'Select date and time',
12 label,
13 ...props
14}: {
15 value: string | undefined;
16 onChange: (value: string) => void;
17 label: string;
18} & InputHTMLAttributes<HTMLInputElement>) {
19 const [internalValue, setInternalValue] = useState(value ?? '');
20
21 useEffect(() => {
22 if (value !== internalValue) {
23 setInternalValue(value ?? '');
24 }
25 }, [value]);
26
27 // Convert string to Date for modal
28 const getDateFromValue = (dateString: string): Date => {
29 if (!dateString) return new Date();
30
31 try {
32 const date = parseISO(dateString);
33 return isValid(date) ? date : new Date();
34 } catch {
35 return new Date();
36 }
37 };
38
39 // Format date for display
40 const getDisplayValue = (dateString: string): string => {
41 if (!dateString) return '';
42
43 try {
44 const date = parseISO(dateString);
45 return isValid(date) ? format(date, 'MM/dd/yyyy HH:mm') : dateString;
46 } catch {
47 return dateString;
48 }
49 };
50
51 const handleDateTimeSelect = () => {
52 pushModal('DateTimePicker', {
53 initialDate: getDateFromValue(value || ''),
54 title: 'Select Date & Time',
55 onChange: (selectedDate: Date) => {
56 const isoString = selectedDate.toISOString();
57 setInternalValue(isoString);
58 onChange(isoString);
59 },
60 });
61 };
62
63 return (
64 <WithLabel label={label}>
65 <div

Callers

nothing calls this directly

Calls 2

handleDateTimeSelectFunction · 0.85
getDisplayValueFunction · 0.85

Tested by

no test coverage detected