diff --git a/app/selectors/login.js b/app/selectors/login.js deleted file mode 100644 index 03e3a2ecb..000000000 --- a/app/selectors/login.js +++ /dev/null @@ -1,19 +0,0 @@ -import { createSelector } from 'reselect'; -import isEmpty from 'lodash/isEmpty'; - -const getUser = state => { - if (!isEmpty(state.share?.user)) { - return state.share.user; - } - return state.login?.user; -}; -const getLoginServices = state => state.login.services || {}; -const getShowFormLoginSetting = state => state.settings.Accounts_ShowFormLogin || false; -const getIframeEnabledSetting = state => state.settings.Accounts_iframe_enabled || false; - -export const getUserSelector = createSelector([getUser], user => user); - -export const getShowLoginButton = createSelector( - [getLoginServices, getShowFormLoginSetting, getIframeEnabledSetting], - (loginServices, showFormLogin, iframeEnabled) => showFormLogin || Object.values(loginServices).length || iframeEnabled -); diff --git a/app/selectors/login.ts b/app/selectors/login.ts new file mode 100644 index 000000000..d9524b6e4 --- /dev/null +++ b/app/selectors/login.ts @@ -0,0 +1,32 @@ +import { createSelector } from 'reselect'; +import isEmpty from 'lodash/isEmpty'; + +import { IApplicationState } from '../definitions'; + +interface IServices { + facebook: { clientId: string }; + github: { clientId: string }; + gitlab: { clientId: string }; + google: { clientId: string }; + linkedin: { clientId: string }; + 'meteor-developer': { clientId: string }; + wordpress: { clientId: string; serverURL: string }; +} + +const getUser = (state: IApplicationState) => { + if (!isEmpty(state.share?.user)) { + return state.share.user; + } + return state.login?.user; +}; +const getLoginServices = (state: IApplicationState) => (state.login.services as IServices) || {}; +const getShowFormLoginSetting = (state: IApplicationState) => (state.settings.Accounts_ShowFormLogin as boolean) || false; +const getIframeEnabledSetting = (state: IApplicationState) => (state.settings.Accounts_iframe_enabled as boolean) || false; + +export const getUserSelector = createSelector([getUser], user => user); + +export const getShowLoginButton = createSelector( + [getLoginServices, getShowFormLoginSetting, getIframeEnabledSetting], + (loginServices, showFormLogin, iframeEnabled) => + (showFormLogin || Object.values(loginServices).length || iframeEnabled) as boolean +); diff --git a/app/views/UserPreferencesView/index.tsx b/app/views/UserPreferencesView/index.tsx index 5cb9a2aa5..4a2b1b042 100644 --- a/app/views/UserPreferencesView/index.tsx +++ b/app/views/UserPreferencesView/index.tsx @@ -13,13 +13,14 @@ import { SWITCH_TRACK_COLOR } from '../../constants/colors'; import { getUserSelector } from '../../selectors/login'; import RocketChat from '../../lib/rocketchat'; import { ProfileStackParamList } from '../../stacks/types'; +import { IApplicationState } from '../../definitions'; interface IUserPreferencesViewProps { navigation: StackNavigationProp; } const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Element => { - const { enableMessageParserEarlyAdoption, id } = useSelector(state => getUserSelector(state)); + const { enableMessageParserEarlyAdoption, id } = useSelector((state: IApplicationState) => getUserSelector(state)); const dispatch = useDispatch(); useEffect(() => {