Chore: Migrate selector/login to TS (#3731)
* migrate selector/login to TS * Fix lint errors * set aliases for returns
This commit is contained in:
parent
f51ec9ef0c
commit
78da41d4f7
|
@ -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
|
|
||||||
);
|
|
|
@ -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
|
||||||
|
);
|
|
@ -13,13 +13,14 @@ import { SWITCH_TRACK_COLOR } from '../../constants/colors';
|
||||||
import { getUserSelector } from '../../selectors/login';
|
import { getUserSelector } from '../../selectors/login';
|
||||||
import RocketChat from '../../lib/rocketchat';
|
import RocketChat from '../../lib/rocketchat';
|
||||||
import { ProfileStackParamList } from '../../stacks/types';
|
import { ProfileStackParamList } from '../../stacks/types';
|
||||||
|
import { IApplicationState } from '../../definitions';
|
||||||
|
|
||||||
interface IUserPreferencesViewProps {
|
interface IUserPreferencesViewProps {
|
||||||
navigation: StackNavigationProp<ProfileStackParamList, 'UserPreferencesView'>;
|
navigation: StackNavigationProp<ProfileStackParamList, 'UserPreferencesView'>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Element => {
|
const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Element => {
|
||||||
const { enableMessageParserEarlyAdoption, id } = useSelector(state => getUserSelector(state));
|
const { enableMessageParserEarlyAdoption, id } = useSelector((state: IApplicationState) => getUserSelector(state));
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
Loading…
Reference in New Issue