Skip to content

Commit

Permalink
feat: Added checkbox in settings for the new setting (RocketChat#2532)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogesh-aggarwal committed Jan 6, 2024
1 parent ee6691a commit e939b45
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ui/components/SettingsView/GeneralTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Box, FieldGroup } from '@rocket.chat/fuselage';
import type { FC } from 'react';
import React from 'react';

import { AlwaysStartAtHomePage } from './features/AlwaysStartAtHomePage';
import { ClearPermittedScreenCaptureServers } from './features/ClearPermittedScreenCaptureServers';
import { FlashFrame } from './features/FlashFrame';
import { HardwareAcceleration } from './features/HardwareAcceleration';
Expand All @@ -16,6 +17,7 @@ import { TrayIcon } from './features/TrayIcon';
export const GeneralTab: FC = () => (
<Box is='form' margin={24} maxWidth={960} flexGrow={1} flexShrink={1}>
<FieldGroup>
<AlwaysStartAtHomePage />
<ReportErrors />
<FlashFrame />
<HardwareAcceleration />
Expand Down
52 changes: 52 additions & 0 deletions src/ui/components/SettingsView/features/AlwaysStartAtHomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
Field,
FieldHint,
FieldLabel,
FieldRow,
ToggleSwitch,
} from '@rocket.chat/fuselage';
import type { ChangeEvent, FC } from 'react';
import React, { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import type { Dispatch } from 'redux';

import type { RootAction } from '../../../../store/actions';
import type { RootState } from '../../../../store/rootReducer';
import { SETTINGS_SET_DO_ALWAYS_START_AT_HOME_PAGE_CHANGED } from '../../../actions';

type Props = {
className?: string;
};

export const AlwaysStartAtHomePage: FC<Props> = (props) => {
const isEnabled = useSelector(
({ doAlwaysStartAtHomePage }: RootState) => doAlwaysStartAtHomePage
);
const dispatch = useDispatch<Dispatch<RootAction>>();
const { t } = useTranslation();
const handleChange = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
const isChecked = event.currentTarget.checked;
dispatch({
type: SETTINGS_SET_DO_ALWAYS_START_AT_HOME_PAGE_CHANGED,
payload: isChecked,
});
},
[dispatch]
);

return (
<Field className={props.className}>
<FieldRow>
<ToggleSwitch onChange={handleChange} checked={isEnabled} />
<FieldLabel htmlFor='toggle-switch'>
{t('settings.options.startPage.title')}
</FieldLabel>
</FieldRow>
<FieldRow>
<FieldHint>{t('settings.options.startPage.description')}</FieldHint>
</FieldRow>
</Field>
);
};

0 comments on commit e939b45

Please sign in to comment.