From a98bd2074381e6843b6dd6fc8527b52e1c065987 Mon Sep 17 00:00:00 2001
From: Aleksander <170264518+t-aleksander@users.noreply.github.com>
Date: Wed, 18 Sep 2024 13:32:06 +0200
Subject: [PATCH] rework
---
.../ProfileDetailsForm/ProfileDetailsForm.tsx | 67 +++++++++++--------
.../ProfileDetailsWarningModals.tsx | 58 ----------------
.../hooks/useProfileDetailsWarningModal.tsx | 43 ------------
3 files changed, 39 insertions(+), 129 deletions(-)
delete mode 100644 web/src/pages/users/UserProfile/ProfileDetails/ProfileDetailsForm/ProfileDetailsWarningModals.tsx
delete mode 100644 web/src/pages/users/UserProfile/ProfileDetails/ProfileDetailsForm/hooks/useProfileDetailsWarningModal.tsx
diff --git a/web/src/pages/users/UserProfile/ProfileDetails/ProfileDetailsForm/ProfileDetailsForm.tsx b/web/src/pages/users/UserProfile/ProfileDetails/ProfileDetailsForm/ProfileDetailsForm.tsx
index b2850a79ef..41c1d7ab4e 100644
--- a/web/src/pages/users/UserProfile/ProfileDetails/ProfileDetailsForm/ProfileDetailsForm.tsx
+++ b/web/src/pages/users/UserProfile/ProfileDetails/ProfileDetailsForm/ProfileDetailsForm.tsx
@@ -11,6 +11,9 @@ import { z } from 'zod';
import { useI18nContext } from '../../../../../i18n/i18n-react';
import { FormInput } from '../../../../../shared/defguard-ui/components/Form/FormInput/FormInput';
import { FormSelect } from '../../../../../shared/defguard-ui/components/Form/FormSelect/FormSelect';
+import { Button } from '../../../../../shared/defguard-ui/components/Layout/Button/Button';
+import { ButtonStyleVariant } from '../../../../../shared/defguard-ui/components/Layout/Button/types';
+import { ModalWithTitle } from '../../../../../shared/defguard-ui/components/Layout/modals/ModalWithTitle/ModalWithTitle';
import { useAppStore } from '../../../../../shared/hooks/store/useAppStore';
import { useAuthStore } from '../../../../../shared/hooks/store/useAuthStore';
import { useUserProfileStore } from '../../../../../shared/hooks/store/useUserProfileStore';
@@ -27,9 +30,7 @@ import { OAuth2AuthorizedApps } from '../../../../../shared/types';
import { omitNull } from '../../../../../shared/utils/omitNull';
import { titleCase } from '../../../../../shared/utils/titleCase';
import { trimObjectStrings } from '../../../../../shared/utils/trimObjectStrings';
-import { useProfileDetailsWarningModal } from './hooks/useProfileDetailsWarningModal';
import { ProfileDetailsFormAppsField } from './ProfileDetailsFormAppsField';
-import { ProfileDetailsWarningModals } from './ProfileDetailsWarningModals';
interface Inputs {
username: string;
@@ -63,14 +64,14 @@ export const ProfileDetailsForm = () => {
const queryClient = useQueryClient();
const isAdmin = useAuthStore((state) => state.isAdmin);
const isMe = useUserProfileStore((state) => state.isMe);
- const [fetchGroups, setFetchGroups] = useState(false);
+ const [fetchGroups] = useState(false);
const {
user: { editUser },
groups: { getGroups },
} = useApi();
const { username: paramsUsername } = useParams();
const navigate = useNavigate();
- const warningModals = useProfileDetailsWarningModal((state) => state);
+ const [usernameChangeWarning, setUsernameChangeWarning] = useState(false);
const zodSchema = useMemo(
() =>
@@ -209,31 +210,48 @@ export const ProfileDetailsForm = () => {
useEffect(() => {
if (submitButton && submitButton.current) {
const sub = submitSubject.subscribe(() => {
+ if (getValues().username !== userProfile?.user.username) {
+ setUsernameChangeWarning(true);
+ return;
+ }
submitButton.current?.click();
});
return () => sub.unsubscribe();
}
- }, [submitSubject]);
-
- useEffect(() => {
- setTimeout(() => setFetchGroups(true), 500);
- warningModals.reset();
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
+ }, [submitSubject, getValues, userProfile?.user.username]);
return (
<>
-