Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
141 lines
4.3 KiB
TypeScript
141 lines
4.3 KiB
TypeScript
import {
|
|
ButtonGroup,
|
|
Button,
|
|
Box,
|
|
ToggleSwitch,
|
|
States,
|
|
StatesIcon,
|
|
StatesTitle,
|
|
Accordion,
|
|
AccordionItem,
|
|
Field,
|
|
FieldGroup,
|
|
FieldLabel,
|
|
FieldRow,
|
|
FieldHint,
|
|
Callout,
|
|
Margins,
|
|
} from '@rocket.chat/fuselage';
|
|
import { usePreferenceFeaturePreviewList, Page, PageHeader, PageScrollableContentWithShadow, PageFooter } from '@rocket.chat/ui-client';
|
|
import type { TranslationKey } from '@rocket.chat/ui-contexts';
|
|
import { useToastMessageDispatch, useTranslation, useEndpoint } from '@rocket.chat/ui-contexts';
|
|
import type { ChangeEvent } from 'react';
|
|
import { useEffect, Fragment } from 'react';
|
|
import { useForm } from 'react-hook-form';
|
|
|
|
import { useFeaturePreviewEnableQuery } from '../../../hooks/useFeaturePreviewEnableQuery';
|
|
|
|
const AccountFeaturePreviewPage = () => {
|
|
const t = useTranslation();
|
|
const dispatchToastMessage = useToastMessageDispatch();
|
|
const { features, unseenFeatures } = usePreferenceFeaturePreviewList();
|
|
|
|
const setUserPreferences = useEndpoint('POST', '/v1/users.setPreferences');
|
|
|
|
useEffect(() => {
|
|
if (unseenFeatures) {
|
|
const featuresPreview = features.map((feature) => ({
|
|
name: feature.name,
|
|
value: feature.value,
|
|
}));
|
|
|
|
void setUserPreferences({ data: { featuresPreview } });
|
|
}
|
|
}, [setUserPreferences, features, unseenFeatures]);
|
|
|
|
const {
|
|
watch,
|
|
formState: { isDirty },
|
|
setValue,
|
|
handleSubmit,
|
|
reset,
|
|
} = useForm({
|
|
defaultValues: { featuresPreview: features },
|
|
});
|
|
|
|
const { featuresPreview } = watch();
|
|
|
|
const handleSave = async () => {
|
|
const featuresToBeSaved = featuresPreview.map((feature) => ({ name: feature.name, value: feature.value }));
|
|
try {
|
|
await setUserPreferences({ data: { featuresPreview: featuresToBeSaved } });
|
|
dispatchToastMessage({ type: 'success', message: t('Preferences_saved') });
|
|
} catch (error) {
|
|
dispatchToastMessage({ type: 'error', message: error });
|
|
} finally {
|
|
reset({ featuresPreview });
|
|
}
|
|
};
|
|
|
|
const handleFeatures = (e: ChangeEvent<HTMLInputElement>) => {
|
|
const updated = featuresPreview.map((item) => (item.name === e.target.name ? { ...item, value: e.target.checked } : item));
|
|
setValue('featuresPreview', updated, { shouldDirty: true });
|
|
};
|
|
|
|
const grouppedFeaturesPreview = useFeaturePreviewEnableQuery(featuresPreview);
|
|
|
|
return (
|
|
<Page>
|
|
<PageHeader title={t('Feature_preview')} />
|
|
<PageScrollableContentWithShadow>
|
|
<Box maxWidth='x600' width='full' alignSelf='center'>
|
|
{featuresPreview.length === 0 && (
|
|
<States>
|
|
<StatesIcon name='magnifier' />
|
|
<StatesTitle>{t('No_feature_to_preview')}</StatesTitle>
|
|
</States>
|
|
)}
|
|
{featuresPreview.length > 0 && (
|
|
<>
|
|
<Box>
|
|
<Margins block={24}>
|
|
<Box fontScale='p1'>{t('Feature_preview_page_description')}</Box>
|
|
<Callout>{t('Feature_preview_page_callout')}</Callout>
|
|
</Margins>
|
|
</Box>
|
|
<Accordion>
|
|
{grouppedFeaturesPreview?.map(([group, features], index) => (
|
|
<AccordionItem defaultExpanded={index === 0} key={group} title={t(group as TranslationKey)}>
|
|
<FieldGroup>
|
|
{features.map((feature) => (
|
|
<Fragment key={feature.name}>
|
|
<Field>
|
|
<FieldRow>
|
|
<FieldLabel htmlFor={feature.name}>{t(feature.i18n)}</FieldLabel>
|
|
<ToggleSwitch
|
|
id={feature.name}
|
|
checked={feature.value}
|
|
name={feature.name}
|
|
onChange={handleFeatures}
|
|
disabled={feature.disabled}
|
|
/>
|
|
</FieldRow>
|
|
{feature.description && <FieldHint marginBlockStart={12}>{t(feature.description)}</FieldHint>}
|
|
</Field>
|
|
{feature.imageUrl && (
|
|
<Box is='img' width='100%' height='auto' marginBlockStart={16} src={feature.imageUrl} alt='' />
|
|
)}
|
|
</Fragment>
|
|
))}
|
|
</FieldGroup>
|
|
</AccordionItem>
|
|
))}
|
|
</Accordion>
|
|
</>
|
|
)}
|
|
</Box>
|
|
</PageScrollableContentWithShadow>
|
|
<PageFooter isDirty={isDirty}>
|
|
<ButtonGroup>
|
|
<Button onClick={() => reset({ featuresPreview: features })}>{t('Cancel')}</Button>
|
|
<Button primary disabled={!isDirty} onClick={handleSubmit(handleSave)}>
|
|
{t('Save_changes')}
|
|
</Button>
|
|
</ButtonGroup>
|
|
</PageFooter>
|
|
</Page>
|
|
);
|
|
};
|
|
|
|
export default AccountFeaturePreviewPage;
|