Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: whene clise edit users profile modal sholud clear form state

shuaif7bf234da90b
diff --git a/ui/src/components/SchemaForm/index.tsx b/ui/src/components/SchemaForm/index.tsx
index ba4acadd..6b7cbbf0 100644
--- a/ui/src/components/SchemaForm/index.tsx
+++ b/ui/src/components/SchemaForm/index.tsx
@@ -29,7 +29,7 @@ import { useTranslation } from 'react-i18next';
import isEmpty from 'lodash/isEmpty';
import classnames from 'classnames';
-import { scrollToElementTop } from '@/utils';
+import { scrollElementIntoView } from '@/utils';
import type * as Type from '@/common/interface';
import type {
@@ -202,7 +202,7 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, FormProps> = (
if (onChange instanceof Function) {
onChange({ ...formData });
}
- scrollToElementTop(document.getElementById(errors[0]));
+ scrollElementIntoView(document.getElementById(errors[0]));
return false;
}
const syncErrors = await syncValidator();
@@ -218,7 +218,7 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, FormProps> = (
if (onChange instanceof Function) {
onChange({ ...formData });
}
- scrollToElementTop(document.getElementById(syncErrors[0].key));
+ scrollElementIntoView(document.getElementById(syncErrors[0].key));
return false;
}
return true;
diff --git a/ui/src/hooks/useChangeProfileModal/index.tsx b/ui/src/hooks/useChangeProfileModal/index.tsx
index 891c7894..e4496461 100644
--- a/ui/src/hooks/useChangeProfileModal/index.tsx
+++ b/ui/src/hooks/useChangeProfileModal/index.tsx
@@ -94,6 +94,7 @@ const useChangeProfileModal = (props: IProps = {}, userData) => {
}>(null);
const onClose = () => {
+ setFormData(initFormData(schema));
setVisibleState(false);
};
diff --git a/ui/src/utils/common.ts b/ui/src/utils/common.ts
index 27d303b3..97880bf7 100644
--- a/ui/src/utils/common.ts
+++ b/ui/src/utils/common.ts
@@ -60,6 +60,17 @@ function scrollToElementTop(element) {
});
}
+function scrollElementIntoView(element) {
+ if (!element) {
+ return;
+ }
+ element.scrollIntoView({
+ behavior: 'smooth',
+ block: 'center',
+ inline: 'center',
+ });
+}
+
const scrollToDocTop = () => {
setTimeout(() => {
window.scrollTo({
@@ -274,6 +285,7 @@ function changeTheme(mode: 'default' | 'light' | 'dark' | 'system') {
export {
thousandthDivision,
formatCount,
+ scrollElementIntoView,
scrollToElementTop,
scrollToDocTop,
bgFadeOut,