UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

51 lines 2.06 kB
import type { Dispatch, SetStateAction } from 'react'; import type { UseDateTimeHandlersReturn } from './useDateTimeHandlers'; import type { StepErrors } from '../../../../SendActivityModal/types'; /** Minimal shape required so date/time handlers can update the form */ interface DateTimeFields { startDate?: string; startTime?: string; finalDate?: string; finalTime?: string; } /** * Params for {@link useEditModalForm}. */ export interface UseEditModalFormParams<T extends DateTimeFields> { /** Whether the modal is open */ isOpen: boolean; /** Extra precondition for loading (e.g. has id + api client). Defaults to true. */ enabled?: boolean; /** Fetches the entity and maps it to the form shape. Should be stable (useCallback). */ load: () => Promise<T>; /** Called when the load fails (e.g. toast + close). Should be stable (useCallback). */ onLoadError: () => void; } /** * Return value of {@link useEditModalForm}. */ export interface UseEditModalFormReturn<T extends DateTimeFields> { formData: T; setFormData: Dispatch<SetStateAction<T>>; errors: StepErrors; setErrors: Dispatch<SetStateAction<StepErrors>>; loading: boolean; saving: boolean; setSaving: Dispatch<SetStateAction<boolean>>; updateFormData: (data: Partial<T>) => void; dateHandlers: UseDateTimeHandlersReturn; } /** * Shared plumbing for "quick edit" modals (title/dates): form state, validation * errors, loading/saving flags, a merge helper that clears errors, date/time * handlers, and a generic load-on-open effect with cancellation. * * The modal-specific fetch + mapping lives in `load`; the error feedback * (toast/close) lives in `onLoadError`. * * @param params - {@link UseEditModalFormParams} * @returns form state and helpers ({@link UseEditModalFormReturn}) */ export declare function useEditModalForm<T extends DateTimeFields>({ isOpen, enabled, load, onLoadError, }: UseEditModalFormParams<T>): UseEditModalFormReturn<T>; export {}; //# sourceMappingURL=useEditModalForm.d.ts.map