[FIX] LoginSignup blink services (#1809)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
d1844ba16e
commit
cfab64283d
|
@ -40,12 +40,6 @@ export function addSettings(settings) {
|
||||||
payload: settings
|
payload: settings
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export function setAllSettings(settings) {
|
|
||||||
return {
|
|
||||||
type: types.SET_ALL_SETTINGS,
|
|
||||||
payload: settings
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function login() {
|
export function login() {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
export const SET_CURRENT_SERVER = 'SET_CURRENT_SERVER';
|
export const SET_CURRENT_SERVER = 'SET_CURRENT_SERVER';
|
||||||
export const SET_ALL_SETTINGS = 'SET_ALL_SETTINGS';
|
|
||||||
export const SET_CUSTOM_EMOJIS = 'SET_CUSTOM_EMOJIS';
|
export const SET_CUSTOM_EMOJIS = 'SET_CUSTOM_EMOJIS';
|
||||||
export const ADD_SETTINGS = 'ADD_SETTINGS';
|
export const ADD_SETTINGS = 'ADD_SETTINGS';
|
||||||
|
|
|
@ -52,21 +52,17 @@ const serverInfoUpdate = async(serverInfo, iconSetting) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getSetting({ server, setting }) {
|
export async function getLoginSettings({ server }) {
|
||||||
return new Promise(async(resolve, reject) => {
|
|
||||||
try {
|
try {
|
||||||
const result = await fetch(`${ server }/api/v1/settings.public?query={"_id":{"$in":["${ setting }"]}}`).then(response => response.json());
|
const settingsParams = JSON.stringify(['Accounts_ShowFormLogin', 'Accounts_RegistrationForm']);
|
||||||
|
const result = await fetch(`${ server }/api/v1/settings.public?query={"_id":{"$in":${ settingsParams }}}`).then(response => response.json());
|
||||||
|
|
||||||
if (result.success && result.settings.length) {
|
if (result.success && result.settings.length) {
|
||||||
const [{ value }] = result.settings;
|
reduxStore.dispatch(actions.addSettings(this.parseSettings(this._prepareSettings(result.settings))));
|
||||||
return resolve(value);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e);
|
log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return reject();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setSettings() {
|
export async function setSettings() {
|
||||||
|
@ -81,7 +77,7 @@ export async function setSettings() {
|
||||||
valueAsArray: item.valueAsArray,
|
valueAsArray: item.valueAsArray,
|
||||||
_updatedAt: item._updatedAt
|
_updatedAt: item._updatedAt
|
||||||
}));
|
}));
|
||||||
reduxStore.dispatch(actions.setAllSettings(RocketChat.parseSettings(parsed.slice(0, parsed.length))));
|
reduxStore.dispatch(actions.addSettings(RocketChat.parseSettings(parsed.slice(0, parsed.length))));
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function() {
|
export default async function() {
|
||||||
|
|
|
@ -24,7 +24,7 @@ import subscribeRooms from './methods/subscriptions/rooms';
|
||||||
|
|
||||||
import protectedFunction from './methods/helpers/protectedFunction';
|
import protectedFunction from './methods/helpers/protectedFunction';
|
||||||
import readMessages from './methods/readMessages';
|
import readMessages from './methods/readMessages';
|
||||||
import getSettings, { getSetting, setSettings } from './methods/getSettings';
|
import getSettings, { getLoginSettings, setSettings } from './methods/getSettings';
|
||||||
|
|
||||||
import getRooms from './methods/getRooms';
|
import getRooms from './methods/getRooms';
|
||||||
import getPermissions from './methods/getPermissions';
|
import getPermissions from './methods/getPermissions';
|
||||||
|
@ -619,7 +619,7 @@ const RocketChat = {
|
||||||
cancelUpload,
|
cancelUpload,
|
||||||
isUploadActive,
|
isUploadActive,
|
||||||
getSettings,
|
getSettings,
|
||||||
getSetting,
|
getLoginSettings,
|
||||||
setSettings,
|
setSettings,
|
||||||
getPermissions,
|
getPermissions,
|
||||||
getCustomEmojis,
|
getCustomEmojis,
|
||||||
|
|
|
@ -2,11 +2,6 @@ import * as types from '../constants/types';
|
||||||
import initialState from './initialState';
|
import initialState from './initialState';
|
||||||
|
|
||||||
export default function settings(state = initialState.settings, action) {
|
export default function settings(state = initialState.settings, action) {
|
||||||
if (action.type === types.SET_ALL_SETTINGS) {
|
|
||||||
return {
|
|
||||||
...action.payload
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (action.type === types.ADD_SETTINGS) {
|
if (action.type === types.ADD_SETTINGS) {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {
|
import {
|
||||||
put, take, takeLatest, fork, cancel, race
|
put, take, takeLatest, fork, cancel, race, select
|
||||||
} from 'redux-saga/effects';
|
} from 'redux-saga/effects';
|
||||||
import { Alert } from 'react-native';
|
import { Alert } from 'react-native';
|
||||||
import RNUserDefaults from 'rn-user-defaults';
|
import RNUserDefaults from 'rn-user-defaults';
|
||||||
|
@ -133,9 +133,12 @@ const handleServerRequest = function* handleServerRequest({ server, certificate
|
||||||
const serverInfo = yield getServerInfo({ server });
|
const serverInfo = yield getServerInfo({ server });
|
||||||
|
|
||||||
if (serverInfo) {
|
if (serverInfo) {
|
||||||
const showFormLogin = yield RocketChat.getSetting({ server, setting: 'Accounts_ShowFormLogin' });
|
|
||||||
const loginServicesLength = yield RocketChat.getLoginServices(server);
|
const loginServicesLength = yield RocketChat.getLoginServices(server);
|
||||||
if (loginServicesLength === 0 && showFormLogin) {
|
yield RocketChat.getLoginSettings({ server });
|
||||||
|
|
||||||
|
const showFormLogin = yield select(state => state.settings.Accounts_ShowFormLogin);
|
||||||
|
|
||||||
|
if (!loginServicesLength && showFormLogin) {
|
||||||
Navigation.navigate('LoginView');
|
Navigation.navigate('LoginView');
|
||||||
} else {
|
} else {
|
||||||
Navigation.navigate('LoginSignupView');
|
Navigation.navigate('LoginSignupView');
|
||||||
|
|
Loading…
Reference in New Issue