Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ISettingColor, SettingEditor, SettingValue } from '@rocket.chat/core-typings';
import type { SettingEditor, SettingValue } from '@rocket.chat/core-typings';
import { isSettingColor, isSetting } from '@rocket.chat/core-typings';
import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks';
import { useSettingsDispatch, useSettingStructure } from '@rocket.chat/ui-contexts';
Expand Down Expand Up @@ -57,14 +57,17 @@ function SettingField({ className = undefined, settingId, sectionChanged }: Sett
const [value, setValue] = useState(setting.value);
const [editor, setEditor] = useState(isSettingColor(setting) ? setting.editor : undefined);

const editorValue = useMemo(() => {
return isSettingColor(setting) ? setting.editor : undefined;
}, [setting]);

useEffect(() => {
setValue(setting.value);
}, [setting.value]);

useEffect(() => {
setEditor(isSettingColor(setting) ? setting.editor : undefined);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [(setting as ISettingColor).editor]);
setEditor(editorValue);
}, [editorValue]);

const onChangeValue = useCallback(
(value: SettingValue) => {
Expand All @@ -84,13 +87,12 @@ function SettingField({ className = undefined, settingId, sectionChanged }: Sett

const onResetButtonClick = useCallback(() => {
setValue(setting.value);
setEditor(isSettingColor(setting) ? setting.editor : undefined);
setEditor(editorValue);
update({
value: persistedSetting.packageValue,
...(isSettingColor(persistedSetting) && { editor: persistedSetting.packageEditor }),
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setting.value, (setting as ISettingColor).editor, update, persistedSetting]);
}, [setting.value, editorValue, update, persistedSetting]);

const { _id, readonly, type, packageValue, i18nLabel, i18nDescription, alert } = setting;

Expand Down
16 changes: 9 additions & 7 deletions apps/meteor/client/views/admin/settings/Setting/Setting.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ISettingColor, SettingEditor, SettingValue } from '@rocket.chat/core-typings';
import type { SettingEditor, SettingValue } from '@rocket.chat/core-typings';
import { isSettingColor, isSetting } from '@rocket.chat/core-typings';
import { Box, Button, Tag } from '@rocket.chat/fuselage';
import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks';
Expand Down Expand Up @@ -64,14 +64,17 @@ function Setting({ className = undefined, settingId, sectionChanged }: SettingPr
const [value, setValue] = useState(setting.value);
const [editor, setEditor] = useState(isSettingColor(setting) ? setting.editor : undefined);

const editorValue = useMemo(() => {
return isSettingColor(setting) ? setting.editor : undefined;
}, [setting]);

useEffect(() => {
setValue(setting.value);
}, [setting.value]);

useEffect(() => {
setEditor(isSettingColor(setting) ? setting.editor : undefined);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [(setting as ISettingColor).editor]);
setEditor(editorValue);
}, [editorValue]);

const onChangeValue = useCallback(
(value: SettingValue) => {
Expand All @@ -91,13 +94,12 @@ function Setting({ className = undefined, settingId, sectionChanged }: SettingPr

const onResetButtonClick = useCallback(() => {
setValue(setting.value);
setEditor(isSettingColor(setting) ? setting.editor : undefined);
setEditor(editorValue);
update({
value: persistedSetting.packageValue,
...(isSettingColor(persistedSetting) && { editor: persistedSetting.packageEditor }),
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setting.value, (setting as ISettingColor).editor, update, persistedSetting]);
}, [setting.value, editorValue, update, persistedSetting]);

const { _id, readonly, type, packageValue, i18nLabel, i18nDescription, alert } = setting;

Expand Down
Loading