forked from RocketChat/Rocket.Chat.Electron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added checkbox in settings for the new setting (RocketChat#2532)
- Loading branch information
1 parent
ee6691a
commit e939b45
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/ui/components/SettingsView/features/AlwaysStartAtHomePage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |