import { Dialog } from '@base-ui/react/dialog'; import { OntimeView } from 'ontime-types'; import { FormEvent, memo } from 'react'; import { IoClose } from 'react-icons/io5'; import { useSearchParams } from 'react-router'; import useViewSettings from '../../hooks-query/useViewSettings'; import { useIsSmallScreen } from '../../hooks/useIsSmallScreen'; import Button from '../buttons/Button'; import IconButton from '../buttons/IconButton'; import Info from '../info/Info'; import { ViewOption } from './viewParams.types'; import { getPreservedSearchParams, getURLSearchParamsFromObj } from './viewParams.utils'; import { useViewParamsEditorStore } from './viewParamsEditor.store'; import { ViewParamsPresets } from './ViewParamsPresets'; import ViewParamsSection from './ViewParamsSection'; import style from './ViewParamsEditor.module.scss'; interface EditFormDrawerProps { target: OntimeView; viewOptions: ViewOption[]; } export default memo(ViewParamsEditor); function ViewParamsEditor({ target, viewOptions }: EditFormDrawerProps) { const [searchParams, setSearchParams] = useSearchParams(); const { data: viewSettings } = useViewSettings(); const { isOpen, close } = useViewParamsEditorStore(); const isSmallScreen = useIsSmallScreen(); const getPreservedParams = () => getPreservedSearchParams(searchParams, viewOptions); const handleClose = () => { close(); }; const resetParams = () => { setSearchParams(getPreservedParams()); }; const onParamsFormSubmit = (formEvent: FormEvent) => { formEvent.preventDefault(); const newParamsObject = Object.fromEntries(new FormData(formEvent.currentTarget)); const newSearchParams = getURLSearchParamsFromObj(newParamsObject, viewOptions); const preservedParams = getPreservedParams(); preservedParams.forEach((value, key) => { newSearchParams.append(key, value); }); setSearchParams(newSearchParams); if (isSmallScreen) { close(); } }; return ( { if (!open) { handleClose(); } }} >
Customise
{viewSettings.overrideStyles && ( This view style is being modified by a custom CSS file. )}
{viewOptions.map((section) => ( ))}
); }