From 953a5853f9e0d60ac9c55619c40112c4b0aca50c Mon Sep 17 00:00:00 2001 From: Ar Rakin Date: Wed, 4 Oct 2023 11:50:42 +0600 Subject: [PATCH] fix(mobile): unsaved changes snackbar --- src/components/Dashboard/SettingsForm.tsx | 83 +++++++++++++++++------ 1 file changed, 62 insertions(+), 21 deletions(-) diff --git a/src/components/Dashboard/SettingsForm.tsx b/src/components/Dashboard/SettingsForm.tsx index 0017c16..6d2562d 100644 --- a/src/components/Dashboard/SettingsForm.tsx +++ b/src/components/Dashboard/SettingsForm.tsx @@ -2,8 +2,9 @@ import { getConfig, putConfig } from "@/api/config"; import { useAuthContext } from "@/contexts/AuthContext"; +import useIsDesktop from "@/hooks/useIsDesktop"; import { SettingCardProps } from "@/types/SetttingCardProps"; -import { Alert, Snackbar } from "@mui/material"; +import { Alert, Button as MUIButton, Snackbar } from "@mui/material"; import { Button } from "@nextui-org/react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { FC, ReactNode, useEffect, useRef, useState } from "react"; @@ -87,6 +88,23 @@ const SettingsForm: FC = ({ onSubmit?.(data); mutation.mutate(data); }; + const isDesktop = useIsDesktop(); + + const formReset = () => { + console.log("Reset"); + + formRef.current?.reset(); + reset(); + + setState(s => ({ ...s, resetting: true })); + + setTimeout(() => { + setState(s => ({ + ...s, + resetting: false, + })); + }, 200); + }; return (
= ({
- {isDirty && ( -
- You have unsaved changes! -
- )} + {isDirty && + (isDesktop ? ( +
+ You have unsaved changes! +
+ ) : ( + + +
+
+ + + + You have unsaved changes! + +
+ +
+ + formRef.current?.requestSubmit() + } + type="button" + className="absolute right-[10px] top-[50%] -translate-y-[50%]" + > + SAVE + +
+
+
+
+ ))}