diff --git a/dashboard/src/components/form-fields/date.tsx b/dashboard/src/components/form-fields/date.tsx index 7db3077..2afa0b8 100644 --- a/dashboard/src/components/form-fields/date.tsx +++ b/dashboard/src/components/form-fields/date.tsx @@ -1,10 +1,21 @@ -import { FC, useEffect, useState } from 'react'; -import { format } from 'date-fns'; -import { CalendarIcon } from '@radix-ui/react-icons'; -import { cn } from '@marzneshin/utils'; -import { useFormContext, FieldValues } from 'react-hook-form'; -import { useTranslation } from 'react-i18next'; -import { Popover, PopoverTrigger, FormControl, Button, Calendar, PopoverContent, FormLabel, FormItem, FormField, FormMessage } from '@marzneshin/components'; +import { type FC, useEffect, useState } from "react"; +import { format } from "date-fns"; +import { CalendarIcon } from "@radix-ui/react-icons"; +import { cn } from "@marzneshin/utils"; +import { useFormContext, type FieldValues } from "react-hook-form"; +import { useTranslation } from "react-i18next"; +import { + Popover, + PopoverTrigger, + FormControl, + Button, + Calendar, + PopoverContent, + FormLabel, + FormItem, + FormField, + FormMessage, +} from "@marzneshin/components"; interface DateFieldProps { name: keyof FieldValues; @@ -20,13 +31,19 @@ function parseISODate(isoDateString: string | undefined): Date | undefined { export const DateField: FC = ({ name, label }) => { const { t } = useTranslation(); const form = useFormContext(); - const [selectedDate, setSelectedDate] = useState(parseISODate(form.getValues(name))); + const [selectedDate, setSelectedDate] = useState( + parseISODate(form.getValues(name)), + ); useEffect(() => { const newValue = selectedDate?.toISOString().slice(0, -5); const prevValue = form.getValues(name); if (newValue !== prevValue) { - form.setValue(name, newValue, { shouldValidate: true, shouldTouch: true }); + form.setValue(name, newValue, { + shouldValidate: true, + shouldTouch: true, + shouldDirty: true, + }); } }, [form, name, selectedDate]); @@ -44,11 +61,11 @@ export const DateField: FC = ({ name, label }) => { variant={"outline"} className={cn( "w-full pl-3 text-left font-normal", - !field.value && "text-muted-foreground" + !field.value && "text-muted-foreground", )} > {field.value ? ( - format(field.value + 'Z', "PPP") + format(field.value + "Z", "PPP") ) : ( Pick a date )} @@ -64,9 +81,7 @@ export const DateField: FC = ({ name, label }) => { onSelect={(date) => { setSelectedDate(date); }} - disabled={(date) => - date < new Date() - } + disabled={(date) => date < new Date()} initialFocus /> diff --git a/dashboard/src/features/users/components/dialogs/mutation/index.tsx b/dashboard/src/features/users/components/dialogs/mutation/index.tsx index d1d0820..b49bbbc 100644 --- a/dashboard/src/features/users/components/dialogs/mutation/index.tsx +++ b/dashboard/src/features/users/components/dialogs/mutation/index.tsx @@ -16,11 +16,12 @@ import { useUsersCreationMutation, useUsersUpdateMutation, UserSchema, - UsernameField, type UserMutationType + UsernameField, + type UserMutationType, } from "@marzneshin/features/users"; import { ServicesField } from "@marzneshin/features/services"; import { NoteField } from "./fields"; -import { MutationDialogProps, useMutationDialog } from "@marzneshin/hooks"; +import { type MutationDialogProps, useMutationDialog } from "@marzneshin/hooks"; import { DataLimitFields, ExpirationMethodFields } from "./sections"; export const UsersMutationDialog: FC> = ({ @@ -28,12 +29,17 @@ export const UsersMutationDialog: FC> = ({ onClose, }) => { const { t } = useTranslation(); - const defaultValue = useMemo(() => ({ - service_ids: [], - username: "", - data_limit_reset_strategy: "no_reset", - note: "", - }), []) + const defaultValue = useMemo( + () => ({ + service_ids: [], + username: "", + data_limit_reset_strategy: "no_reset", + note: "", + expire_date: "", + expire_strategy: "fixed_date", + }), + [], + ); const { open, onOpenChange, form, handleSubmit } = useMutationDialog({ entity, @@ -60,7 +66,7 @@ export const UsersMutationDialog: FC> = ({
- +