From b19749a44e808e9dfd1ad24ec2ae626165842f3f Mon Sep 17 00:00:00 2001 From: David Arranz Date: Sun, 11 Aug 2024 13:10:26 +0200 Subject: [PATCH] Preguntar cambiar los cambios en Ajustes --- client/src/app/settings/edit.tsx | 42 ++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/client/src/app/settings/edit.tsx b/client/src/app/settings/edit.tsx index 5bc7b77..4d05895 100644 --- a/client/src/app/settings/edit.tsx +++ b/client/src/app/settings/edit.tsx @@ -19,9 +19,9 @@ import { useMemo, useState } from "react"; import { SubmitHandler, useForm } from "react-hook-form"; import { Trans } from "react-i18next"; +import { useUnsavedChangesNotifier } from "@/lib/hooks"; import { cn } from "@/lib/utils"; import { IUpdateProfile_Request_DTO } from "@shared/contexts"; -import { Link } from "react-router-dom"; import { toast } from "react-toastify"; import { useSettings } from "./hooks"; @@ -50,6 +50,7 @@ export const SettingsEditor = () => { mode: "onBlur", values: data?.dealer, defaultValues, + //defaultValues: _defaultValues, /*resolver: joiResolver( Joi.object({ email: Joi.string() @@ -63,11 +64,14 @@ export const SettingsEditor = () => { ),*/ }); - const { formState, reset } = form; - const { isSubmitting } = formState; + const { formState, reset, getValues } = form; + const { isSubmitting, isDirty } = formState; + + useUnsavedChangesNotifier({ + isDirty, + }); const onSubmit: SubmitHandler = async (data) => { - console.log(data); mutate(data, { onError: (error) => { console.debug(error); @@ -76,9 +80,8 @@ export const SettingsEditor = () => { }, //onSettled: () => {}, onSuccess: () => { - reset({}, { keepValues: true, keepIsValid: true }); + reset(getValues()); toast("Ajustes guardados"); - //clear(); }, }); }; @@ -117,27 +120,30 @@ export const SettingsEditor = () => { )}