Skip to content
Snippets Groups Projects
Commit 0720805201a2 authored by Arnaud Vergnet's avatar Arnaud Vergnet :sun_with_face:
Browse files

feat(fontend): only enable save button when there are changes

parent 4f7c69693731
No related branches found
No related tags found
1 merge request!24feat(fontend): only enable save button when there are changes
Pipeline #228358 failed
......@@ -26,7 +26,12 @@
export function DataServiceForm({ dataService }: DataServiceFormProps) {
const [loading, setLoading] = useState(false);
const { handleSubmit, control } = useForm<DataService>({
const {
handleSubmit,
control,
formState: { isDirty },
reset,
} = useForm<DataService>({
defaultValues: dataService
? dataService
: {
......@@ -49,6 +54,7 @@
router.push(`/data-service/${eid}`);
} else {
await updateDataService(data);
reset(data);
setLoading(false);
}
} catch (e) {
......@@ -148,6 +154,7 @@
startIcon={<SaveIcon />}
loading={loading}
type="submit"
disabled={!isDirty}
>
{dataService ? "Sauvegarder" : "Ajouter"}
</LoadingButton>
......
......@@ -15,7 +15,12 @@
export function ProjectForm({ project }: ProjectFormProps) {
const [loading, setLoading] = useState(false);
const { handleSubmit, control } = useForm<Project>({
const {
handleSubmit,
control,
formState: { isDirty },
reset,
} = useForm<Project>({
defaultValues: project ?? { activated: false },
});
const handleAuthErrors = useHandleAuthErrors();
......@@ -33,6 +38,7 @@
router.push(`/project/${eid}`);
} else {
await updateProject(data);
reset(data);
setLoading(false);
}
} catch (e) {
......@@ -120,6 +126,7 @@
startIcon={<SaveIcon />}
type="submit"
loading={loading}
disabled={!isDirty}
>
{project ? "Sauvegarder" : "Ajouter"}
</LoadingButton>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment