You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
import { call, put, select } from 'redux-saga/effects';
|
|
|
|
import { runPathActionsService } from './router';
|
|
import {
|
|
fetchCardRequest,
|
|
fetchCurrentUserRequest,
|
|
fetchNotificationsRequest,
|
|
fetchProjectsRequest,
|
|
fetchUsersRequest,
|
|
} from '../requests';
|
|
import { pathsMatchSelector } from '../../../selectors';
|
|
import { appInitialized } from '../../../actions';
|
|
import i18n from '../../../i18n';
|
|
import Paths from '../../../constants/Paths';
|
|
|
|
export function* loadLocaleService(language) {
|
|
try {
|
|
yield call(i18n.loadAppLocale, language);
|
|
|
|
return true;
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function* initializeAppService() {
|
|
const {
|
|
payload: {
|
|
user: { isAdmin },
|
|
},
|
|
} = yield call(fetchCurrentUserRequest); // TODO: success check
|
|
|
|
if (isAdmin) {
|
|
yield call(fetchUsersRequest);
|
|
}
|
|
|
|
yield call(fetchProjectsRequest);
|
|
|
|
const pathsMatch = yield select(pathsMatchSelector);
|
|
|
|
if (pathsMatch && pathsMatch.path === Paths.CARDS) {
|
|
yield call(fetchCardRequest, pathsMatch.params.id);
|
|
}
|
|
|
|
yield call(fetchNotificationsRequest);
|
|
yield call(runPathActionsService, pathsMatch);
|
|
yield call(loadLocaleService, i18n.language);
|
|
|
|
yield put(appInitialized());
|
|
}
|