refacotr notification create page

This commit is contained in:
Alex Holliday committed 2026-08-06 11:54:46 -07:00
1 parent c1e9fd6079
commit bc2115f578
4 files changed
+268 -388

No files matched your search

@@ -0,0 +1,43 @@
import {
Controller,
useFormContext,
type FieldPath,
type FieldValues,
} from "react-hook-form";
import dayjs from "dayjs";
import { DatePicker } from "@/Components/inputs";
interface FormDatePickerFieldProps<T extends FieldValues> {
name: FieldPath<T>;
fieldLabel?: string;
format?: string;
onValueChange?: (value: string) => void; // e.g. () => trigger("startDate")
}
export const FormDatePickerField = <T extends FieldValues>({
name,
fieldLabel,
format = "YYYY-MM-DD",
onValueChange,
}: FormDatePickerFieldProps<T>) => {
const { control } = useFormContext<T>();
return (
<Controller
name={name}
control={control}
render={({ field, fieldState }) => (
<DatePicker
fieldLabel={fieldLabel}
value={field.value ? dayjs(field.value, format) : null}
onChange={(date) => {
const next = date ? date.format(format) : "";
field.onChange(next);
onValueChange?.(next);
}}
error={!!fieldState.error}
helperText={fieldState.error?.message}
/>
)}
/>
);
};