Spaces:
Sleeping
Sleeping
| import { useState, useCallback } from 'react'; | |
| import type { ScanPreset } from '@icc/shared'; | |
| export function useScanDateRange() { | |
| const [preset, setPreset] = useState<ScanPreset>('today'); | |
| const [startDate, setStartDate] = useState<string>(''); | |
| const [endDate, setEndDate] = useState<string>(''); | |
| const selectPreset = useCallback((p: ScanPreset) => { | |
| setPreset(p); | |
| if (p !== 'custom') { | |
| setStartDate(''); | |
| setEndDate(''); | |
| } | |
| }, []); | |
| const setCustomRange = useCallback((start: string, end: string) => { | |
| setPreset('custom'); | |
| setStartDate(start); | |
| setEndDate(end); | |
| }, []); | |
| const isValid = preset !== 'custom' || (startDate !== '' && endDate !== '' && startDate <= endDate); | |
| return { | |
| preset, | |
| startDate, | |
| endDate, | |
| setPreset: selectPreset, | |
| setStartDate, | |
| setEndDate, | |
| setCustomRange, | |
| isValid, | |
| }; | |
| } | |