Preguntar cambiar los cambios en Ajustes
This commit is contained in:
parent
86a29ad082
commit
b19749a44e
@ -19,9 +19,9 @@ import { useMemo, useState } from "react";
|
|||||||
import { SubmitHandler, useForm } from "react-hook-form";
|
import { SubmitHandler, useForm } from "react-hook-form";
|
||||||
import { Trans } from "react-i18next";
|
import { Trans } from "react-i18next";
|
||||||
|
|
||||||
|
import { useUnsavedChangesNotifier } from "@/lib/hooks";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { IUpdateProfile_Request_DTO } from "@shared/contexts";
|
import { IUpdateProfile_Request_DTO } from "@shared/contexts";
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import { useSettings } from "./hooks";
|
import { useSettings } from "./hooks";
|
||||||
|
|
||||||
@ -50,6 +50,7 @@ export const SettingsEditor = () => {
|
|||||||
mode: "onBlur",
|
mode: "onBlur",
|
||||||
values: data?.dealer,
|
values: data?.dealer,
|
||||||
defaultValues,
|
defaultValues,
|
||||||
|
//defaultValues: _defaultValues,
|
||||||
/*resolver: joiResolver(
|
/*resolver: joiResolver(
|
||||||
Joi.object({
|
Joi.object({
|
||||||
email: Joi.string()
|
email: Joi.string()
|
||||||
@ -63,11 +64,14 @@ export const SettingsEditor = () => {
|
|||||||
),*/
|
),*/
|
||||||
});
|
});
|
||||||
|
|
||||||
const { formState, reset } = form;
|
const { formState, reset, getValues } = form;
|
||||||
const { isSubmitting } = formState;
|
const { isSubmitting, isDirty } = formState;
|
||||||
|
|
||||||
|
useUnsavedChangesNotifier({
|
||||||
|
isDirty,
|
||||||
|
});
|
||||||
|
|
||||||
const onSubmit: SubmitHandler<SettingsDataForm> = async (data) => {
|
const onSubmit: SubmitHandler<SettingsDataForm> = async (data) => {
|
||||||
console.log(data);
|
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
console.debug(error);
|
console.debug(error);
|
||||||
@ -76,9 +80,8 @@ export const SettingsEditor = () => {
|
|||||||
},
|
},
|
||||||
//onSettled: () => {},
|
//onSettled: () => {},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
reset({}, { keepValues: true, keepIsValid: true });
|
reset(getValues());
|
||||||
toast("Ajustes guardados");
|
toast("Ajustes guardados");
|
||||||
//clear();
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -117,27 +120,30 @@ export const SettingsEditor = () => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<nav className='grid gap-4 text-sm text-muted-foreground'>
|
<nav className='grid gap-4 text-sm text-muted-foreground'>
|
||||||
<Link
|
<a
|
||||||
to='#'
|
|
||||||
onClick={() => setActiveSection("profile")}
|
onClick={() => setActiveSection("profile")}
|
||||||
className={activeSection === "profile" ? "font-semibold text-primary" : ""}
|
className={
|
||||||
|
activeSection === "profile" ? "font-semibold text-primary" : "cursor-pointer"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Trans i18nKey='settings.edit.tabs.profile' />
|
<Trans i18nKey='settings.edit.tabs.profile' />
|
||||||
</Link>
|
</a>
|
||||||
<Link
|
<a
|
||||||
to='#'
|
|
||||||
onClick={() => setActiveSection("quotes")}
|
onClick={() => setActiveSection("quotes")}
|
||||||
className={activeSection === "quotes" ? "font-semibold text-primary" : ""}
|
className={
|
||||||
|
activeSection === "quotes" ? "font-semibold text-primary" : "cursor-pointer "
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Trans i18nKey='settings.edit.tabs.quotes' />
|
<Trans i18nKey='settings.edit.tabs.quotes' />
|
||||||
</Link>
|
</a>
|
||||||
<Link
|
<a
|
||||||
to='#'
|
|
||||||
onClick={() => setActiveSection("legal")}
|
onClick={() => setActiveSection("legal")}
|
||||||
className={activeSection === "legal" ? "font-semibold text-primary" : ""}
|
className={
|
||||||
|
activeSection === "legal" ? "font-semibold text-primary" : "cursor-pointer "
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Trans i18nKey='settings.edit.tabs.legal' />
|
<Trans i18nKey='settings.edit.tabs.legal' />
|
||||||
</Link>
|
</a>
|
||||||
</nav>
|
</nav>
|
||||||
<div className={cn("grid gap-6", activeSection === "profile" ? "visible" : "hidden")}>
|
<div className={cn("grid gap-6", activeSection === "profile" ? "visible" : "hidden")}>
|
||||||
<Card>
|
<Card>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user