import { Accordion, Box, Button, FieldGroup } from '@rocket.chat/fuselage'; import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; import React, { useMemo } from 'react'; import { useEditableSettings, useEditableSettingsDispatch } from '../../../contexts/EditableSettingsContext'; import { useTranslation } from '../../../contexts/TranslationContext'; import SectionSkeleton from './SectionSkeleton'; import Setting from './Setting'; function Section({ children = undefined, groupId, hasReset = true, help = undefined, sectionName, tabName, solo }) { const editableSettings = useEditableSettings( useMemo( () => ({ group: groupId, section: sectionName, tab: tabName, }), [groupId, sectionName, tabName], ), ); const changed = useMemo(() => editableSettings.some(({ changed }) => changed), [editableSettings]); const canReset = useMemo( () => editableSettings.some(({ value, packageValue }) => JSON.stringify(value) !== JSON.stringify(packageValue)), [editableSettings], ); const dispatch = useEditableSettingsDispatch(); const reset = useMutableCallback(() => { dispatch( editableSettings .filter(({ disabled }) => !disabled) .map(({ _id, value, packageValue, editor, packageEditor }) => ({ _id, value: packageValue, editor: packageEditor, changed: JSON.stringify(value) !== JSON.stringify(packageValue) || JSON.stringify(editor) !== JSON.stringify(packageEditor), })), ); }); const t = useTranslation(); const handleResetSectionClick = () => { reset(); }; return ( {help && ( {help} )} {editableSettings.map((setting) => ( ))} {children} {hasReset && canReset && (