@zeniai/client-epic-state 5.3.18-betaAK1 → 5.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/entity/tenant/epic/fetchAllTenantsEpic.d.ts +4 -2
- package/lib/entity/tenant/epic/fetchAllTenantsEpic.js +42 -45
- package/lib/entity/tenant/tenantPayload.d.ts +1 -17
- package/lib/entity/tenant/tenantReducer.d.ts +2 -2
- package/lib/entity/tenant/tenantReducer.js +18 -29
- package/lib/entity/tenant/tenantSelector.d.ts +6 -14
- package/lib/entity/tenant/tenantSelector.js +97 -98
- package/lib/entity/tenant/tenantState.d.ts +0 -10
- package/lib/epic.d.ts +1 -2
- package/lib/epic.js +0 -2
- package/lib/esm/entity/tenant/epic/fetchAllTenantsEpic.js +46 -49
- package/lib/esm/entity/tenant/tenantReducer.js +17 -28
- package/lib/esm/entity/tenant/tenantSelector.js +96 -94
- package/lib/esm/epic.js +0 -2
- package/lib/esm/index.js +6 -6
- package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +3 -65
- package/lib/esm/view/aiCfoView/aiCfoViewSelector.js +0 -25
- package/lib/esm/view/dashboard/dashboardEpic.js +4 -0
- package/lib/esm/view/dashboard/dashboardSelector.js +3 -2
- package/lib/esm/view/financeStatement/financeStatementEpic.js +5 -1
- package/lib/esm/view/people/peoplePageEpic.js +4 -0
- package/lib/index.d.ts +7 -7
- package/lib/index.js +46 -54
- package/lib/view/aiCfoView/aiCfoViewPayload.d.ts +0 -20
- package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +2 -2
- package/lib/view/aiCfoView/aiCfoViewReducer.js +4 -66
- package/lib/view/aiCfoView/aiCfoViewSelector.d.ts +1 -8
- package/lib/view/aiCfoView/aiCfoViewSelector.js +0 -27
- package/lib/view/aiCfoView/aiCfoViewState.d.ts +0 -9
- package/lib/view/dashboard/dashboardEpic.js +4 -0
- package/lib/view/dashboard/dashboardSelector.d.ts +2 -0
- package/lib/view/dashboard/dashboardSelector.js +2 -1
- package/lib/view/financeStatement/financeStatementEpic.js +5 -1
- package/lib/view/people/peoplePageEpic.js +4 -0
- package/package.json +1 -1
- package/lib/esm/view/aiCfoView/epics/transcribeAudioEpic.js +0 -60
- package/lib/view/aiCfoView/epics/transcribeAudioEpic.d.ts +0 -19
- package/lib/view/aiCfoView/epics/transcribeAudioEpic.js +0 -64
|
@@ -3,10 +3,12 @@ import { Observable } from 'rxjs';
|
|
|
3
3
|
import { ID } from '../../../commonStateTypes/common';
|
|
4
4
|
import { MonthYearPeriod } from '../../../commonStateTypes/timePeriod';
|
|
5
5
|
import { RootState } from '../../../rootStateTypes';
|
|
6
|
+
import { initializeSelectedPeriodForTenants } from '../../../view/expenseAutomationView/expenseAutomationViewReducer';
|
|
6
7
|
import { ZeniAPI } from '../../../zeniAPI';
|
|
8
|
+
import { updateCompanies } from '../../company/companyReducer';
|
|
7
9
|
import { TenantsData } from '../tenantPayload';
|
|
8
|
-
import {
|
|
9
|
-
export type ActionType = ReturnType<typeof fetchAllTenants> | ReturnType<typeof
|
|
10
|
+
import { fetchAllTenants, updateTenantsFailure, updateTenantsSuccess } from '../tenantReducer';
|
|
11
|
+
export type ActionType = ReturnType<typeof fetchAllTenants> | ReturnType<typeof updateCompanies> | ReturnType<typeof updateTenantsSuccess> | ReturnType<typeof initializeSelectedPeriodForTenants> | ReturnType<typeof updateTenantsFailure>;
|
|
10
12
|
export declare const fetchAllTenantsEpic: (actions$: ActionsObservable<ActionType>, state: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
|
11
13
|
export declare const defaultMonthYearPeriod: MonthYearPeriod;
|
|
12
14
|
export declare const getDefaultSelectedPeriodsForTenants: (tenantsData: TenantsData) => Record<ID, MonthYearPeriod>;
|
|
@@ -6,63 +6,60 @@ const operators_1 = require("rxjs/operators");
|
|
|
6
6
|
const timePeriod_1 = require("../../../commonStateTypes/timePeriod");
|
|
7
7
|
const responsePayload_1 = require("../../../responsePayload");
|
|
8
8
|
const sessionEndpointsLoader_1 = require("../../../sessionEndpointsLoader");
|
|
9
|
+
const expenseAutomationViewReducer_1 = require("../../../view/expenseAutomationView/expenseAutomationViewReducer");
|
|
9
10
|
const zeniDayJS_1 = require("../../../zeniDayJS");
|
|
11
|
+
const companyReducer_1 = require("../../company/companyReducer");
|
|
10
12
|
const tenantReducer_1 = require("../tenantReducer");
|
|
11
|
-
// Only what the tenant switcher and tenant lookups read (~0.3 KB a tenant
|
|
12
|
-
// instead of ~18 KB with full records and companies). A tenant's full record
|
|
13
|
-
// comes from `fetchActiveTenant` when it is opened.
|
|
14
|
-
const TENANT_SUMMARIES_QUERY = {
|
|
15
|
-
is_full: false,
|
|
16
|
-
is_include_companies_in_response: false,
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* The tenant the app lands on: the selected one, or the most recently opened
|
|
20
|
-
* when none is selected (sign-in, the root route).
|
|
21
|
-
*/
|
|
22
|
-
function getLandingTenantId(tenants, currentTenantId) {
|
|
23
|
-
if (currentTenantId != null &&
|
|
24
|
-
tenants.some((tenant) => tenant.tenant_id === currentTenantId)) {
|
|
25
|
-
return currentTenantId;
|
|
26
|
-
}
|
|
27
|
-
const lastCheckIn = (tenant) => tenant.user_last_check_in_time_into_tenant != null
|
|
28
|
-
? (0, zeniDayJS_1.date)(tenant.user_last_check_in_time_into_tenant).valueOf()
|
|
29
|
-
: 0;
|
|
30
|
-
return tenants.reduce((mostRecent, tenant) => mostRecent == null || lastCheckIn(tenant) > lastCheckIn(mostRecent)
|
|
31
|
-
? tenant
|
|
32
|
-
: mostRecent, undefined)?.tenant_id;
|
|
33
|
-
}
|
|
34
13
|
const fetchAllTenantsEpic = (actions$, state, zeniAPI) => {
|
|
14
|
+
const queryParam = {
|
|
15
|
+
is_include_companies_in_response: true,
|
|
16
|
+
};
|
|
35
17
|
return actions$.pipe((0, operators_1.filter)(tenantReducer_1.fetchAllTenants.match), (0, operators_1.switchMap)((action) => {
|
|
36
|
-
const { userId,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
18
|
+
const fetchTenants$ = (0, rxjs_1.defer)(() => zeniAPI.getJSON(`${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/users/${action.payload.userId}/tenants?query=${encodeURIComponent(JSON.stringify(queryParam))}`, Object.assign({ 'zeni-user-id': action.payload.userId }, { 'zeni-tenant-id': '' }, action.payload.zeniSessionId != null
|
|
19
|
+
? { 'zeni-session-id': action.payload.zeniSessionId }
|
|
20
|
+
: {}))).pipe((0, operators_1.mergeMap)((response) => {
|
|
21
|
+
const currentTenantId = state.value.tenantState.currentTenantId;
|
|
22
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
23
|
+
const defaultSelectedPeriodsForTenants = (0, exports.getDefaultSelectedPeriodsForTenants)(response.data);
|
|
24
|
+
let actions = [
|
|
25
|
+
(0, tenantReducer_1.updateTenantsSuccess)(response.data),
|
|
26
|
+
(0, expenseAutomationViewReducer_1.initializeSelectedPeriodForTenants)({
|
|
27
|
+
selectedPeriodByTenantId: defaultSelectedPeriodsForTenants,
|
|
28
|
+
}),
|
|
29
|
+
];
|
|
30
|
+
if (response.data.companies != null) {
|
|
31
|
+
let companiesPayload = response.data.companies;
|
|
32
|
+
if (currentTenantId != null) {
|
|
33
|
+
// filter out this tenant ID related company detail
|
|
34
|
+
// Find companyID for this tenant
|
|
35
|
+
const currentTenantPayload = response.data.tenants.find((tenant) => tenant.tenant_id === currentTenantId);
|
|
36
|
+
if (currentTenantPayload != null) {
|
|
37
|
+
companiesPayload = response.data.companies.filter((company) => company.company_id !== currentTenantPayload.company_id);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.warn('Selected tenant record not found in response', currentTenantId);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
actions = [
|
|
44
|
+
(0, companyReducer_1.updateCompanies)({
|
|
45
|
+
payload: companiesPayload,
|
|
46
|
+
schema: {},
|
|
47
|
+
}),
|
|
48
|
+
...actions,
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
return (0, rxjs_1.from)(actions);
|
|
40
52
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return (0, rxjs_1.of)((0, tenantReducer_1.updateTenantsFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected error', 'Empty list of tenants')));
|
|
44
|
-
}
|
|
45
|
-
const tenantsLoaded = (0, tenantReducer_1.updateTenantSummariesSuccess)(tenants);
|
|
46
|
-
const { tenantState } = state.value;
|
|
47
|
-
const landingTenantId = getLandingTenantId(tenants, tenantState.currentTenantId);
|
|
48
|
-
const isLandingTenantLoadedOrLoading = landingTenantId == null ||
|
|
49
|
-
tenantState.tenantsById[landingTenantId] != null ||
|
|
50
|
-
tenantState.activeTenantFetchState.fetchState === 'In-Progress';
|
|
51
|
-
if (isLandingTenantLoadedOrLoading) {
|
|
52
|
-
return (0, rxjs_1.of)(tenantsLoaded);
|
|
53
|
+
else {
|
|
54
|
+
return (0, rxjs_1.of)((0, tenantReducer_1.updateTenantsFailure)(response.status));
|
|
53
55
|
}
|
|
54
|
-
// Screens that wait for this fetch (sign-in, the root route) read the
|
|
55
|
-
// landing tenant's roles and product settings, which the list does
|
|
56
|
-
// not carry, so it completes only once that tenant's record is in.
|
|
57
|
-
return (0, rxjs_1.merge)(actions$.pipe((0, operators_1.filter)((landingAction) => tenantReducer_1.updateTenantSuccess.match(landingAction) ||
|
|
58
|
-
tenantReducer_1.updateTenantFailure.match(landingAction)), (0, operators_1.take)(1), (0, operators_1.map)(() => tenantsLoaded)), (0, rxjs_1.of)((0, tenantReducer_1.fetchActiveTenant)(userId, landingTenantId, zeniSessionId)));
|
|
59
56
|
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, tenantReducer_1.updateTenantsFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected error', 'Fetch All Tenants REST API call errored out' +
|
|
60
57
|
JSON.stringify(error))))));
|
|
61
58
|
const sessionEndpointsLoader = (0, sessionEndpointsLoader_1.getSessionEndpointsLoader)();
|
|
62
59
|
if (sessionEndpointsLoader == null) {
|
|
63
60
|
return fetchTenants$;
|
|
64
61
|
}
|
|
65
|
-
return (0, rxjs_1.defer)(() => (0, rxjs_1.from)(sessionEndpointsLoader(userId, zeniSessionId))).pipe((0, operators_1.switchMap)(() => fetchTenants$), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, tenantReducer_1.updateTenantsFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected error', 'Loading session endpoints errored out: ' +
|
|
62
|
+
return (0, rxjs_1.defer)(() => (0, rxjs_1.from)(sessionEndpointsLoader(action.payload.userId, action.payload.zeniSessionId))).pipe((0, operators_1.switchMap)(() => fetchTenants$), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, tenantReducer_1.updateTenantsFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected error', 'Loading session endpoints errored out: ' +
|
|
66
63
|
JSON.stringify(error))))));
|
|
67
64
|
}));
|
|
68
65
|
};
|
|
@@ -7,22 +7,6 @@ import { SubscriptionSummaryPayload } from '../subscription/subscriptionSummary/
|
|
|
7
7
|
import { MasterTOSInfoPayload } from '../userRole/userRolePayload';
|
|
8
8
|
import { CapitalizableClassificationType, CapitalizableMatchPattern, CapitalizableThresholdSource } from './tenantState';
|
|
9
9
|
type TenantsResponse = ZeniAPIResponse<TenantsData>;
|
|
10
|
-
type TenantSummariesResponse = ZeniAPIResponse<TenantSummariesData>;
|
|
11
|
-
/**
|
|
12
|
-
* The tenants list requested with `is_full: false`: only what the tenant
|
|
13
|
-
* switcher and tenant lookups need. A tenant's full record comes from the
|
|
14
|
-
* active-tenant fetch.
|
|
15
|
-
*/
|
|
16
|
-
export interface TenantSummariesData {
|
|
17
|
-
tenants: TenantSummaryPayload[];
|
|
18
|
-
}
|
|
19
|
-
export interface TenantSummaryPayload {
|
|
20
|
-
company_id: ID;
|
|
21
|
-
company_name: string;
|
|
22
|
-
tenant_email_domain: string;
|
|
23
|
-
tenant_id: ID;
|
|
24
|
-
user_last_check_in_time_into_tenant: string | null;
|
|
25
|
-
}
|
|
26
10
|
export interface TenantsData {
|
|
27
11
|
tenants: TenantPayload[];
|
|
28
12
|
user: TenantUserPayload;
|
|
@@ -213,4 +197,4 @@ type SaveConnectionResponse = ZeniAPIResponse<ConnectionDataPayload>;
|
|
|
213
197
|
type SubscriptionSummaryForTenantResponse = ZeniAPIResponse<SubscriptionSummaryPayload>;
|
|
214
198
|
type OnboardingTenantResponse = ZeniAPIResponse<TenantPayload>;
|
|
215
199
|
/** Lets export interfaces and types */
|
|
216
|
-
export {
|
|
200
|
+
export { TenantsResponse, TenantPayload, LoggedInUserPayload, UserData, SignInResponse, SignOutResponse, RoleResourcePayload, RoleResourcesResponse, ConnectionsPayload, ConnectionWithMetaPayload, ConnectionsResponse, SaveConnectionResponse, SubscriptionSummaryForTenantResponse, OnboardingTenantResponse, MagicLinkSignInResponse, sendEmailMagicLinkToUserResponse, VerifyDeviceWithTwoFAResponse, };
|
|
@@ -3,7 +3,7 @@ import { ZeniAPIStatus } from '../../responsePayload';
|
|
|
3
3
|
import ZeniUrl from '../../zeniUrl';
|
|
4
4
|
import { SubscriptionSummaryPayload } from '../subscription/subscriptionSummary/subscriptionSummaryPayload';
|
|
5
5
|
import { UserRolePayload } from '../userRole/userRolePayload';
|
|
6
|
-
import { CapitalizableAccountsPayload, ConnectionDataPayload, ConnectionWithMetaPayload, ConnectionsPayload, LoggedInUserPayload, RoleResourcePayload, TenantPayload,
|
|
6
|
+
import { CapitalizableAccountsPayload, ConnectionDataPayload, ConnectionWithMetaPayload, ConnectionsPayload, LoggedInUserPayload, RoleResourcePayload, TenantPayload, TenantUserPayload, TenantsData } from './tenantPayload';
|
|
7
7
|
import { CapitalizableAccounts, Connection, RoleResource, TenantState } from './tenantState';
|
|
8
8
|
import { AuthProvider } from './tenantTypes';
|
|
9
9
|
export interface DoSignInPayload {
|
|
@@ -40,7 +40,7 @@ export declare const updateTenants: import("@reduxjs/toolkit").ActionCreatorWith
|
|
|
40
40
|
}, "tenant/updateTenants", never, never>, fetchAllTenants: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[userId: string, zeniSessionId?: string | undefined], {
|
|
41
41
|
userId: string;
|
|
42
42
|
zeniSessionId: string | undefined;
|
|
43
|
-
}, "tenant/fetchAllTenants", never, never>,
|
|
43
|
+
}, "tenant/fetchAllTenants", never, never>, updateTenantsSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<TenantsData, "tenant/updateTenantsSuccess">, updateTenantsFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "tenant/updateTenantsFailure">, fetchActiveTenant: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[userId: string, tenantId: string, zeniSessionId?: string | undefined], {
|
|
44
44
|
userId: string;
|
|
45
45
|
tenantId: string;
|
|
46
46
|
zeniSessionId: string | undefined;
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
var _a;
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.updateSubscriptionSummaryForTenantSuccess = exports.fetchSubscriptionSummaryForTenant = exports.deleteConnectionFailure = exports.deleteConnectionSuccess = exports.deleteConnection = exports.initEmailConnectOAuthFailure = exports.initEmailConnectOAuthSuccess = exports.initEmailConnectOAuth = exports.saveConnectorCredentialsFailure = exports.saveConnectorCredentialsSuccess = exports.saveConnectorCredentials = exports.saveOAuthConnectionFailure = exports.saveOAuthConnectionSuccess = exports.saveOAuthConnection = exports.saveAPIKeyConnectionFailure = exports.saveAPIKeyConnectionSuccess = exports.saveAPIKeyConnection = exports.fetchExternalConnectionsSuccess = exports.fetchExternalConnectionsFailure = exports.saveExternalConnectionFailure = exports.saveExternalConnectionSuccess = exports.saveExternalConnection = exports.fetchExternalConnections = exports.updateLoggedInUser = exports.sessionHeartbeatFailure = exports.sessionHeartbeatSuccess = exports.sendSessionHeartbeat = exports.signOutSuccess = exports.doSignOut = exports.updateSignInState = exports.sendEmailMagicLinkToUserFailure = exports.sendEmailMagicLinkToUserSuccess = exports.sendEmailMagicLinkToUser = exports.magicLinkSignInFailure = exports.magicLinkSignInSuccess = exports.doMagicLinkSignIn = exports.doSignIn = exports.updateExcludedResourcesFailure = exports.updateExcludedResourcesSuccess = exports.fetchExcludedResources = exports.updateCurrentTenant = exports.updateTenantFailure = exports.updateTenantSuccess = exports.fetchActiveTenant = exports.updateTenantsFailure = exports.
|
|
7
|
+
exports.updateSubscriptionSummaryForTenantSuccess = exports.fetchSubscriptionSummaryForTenant = exports.deleteConnectionFailure = exports.deleteConnectionSuccess = exports.deleteConnection = exports.initEmailConnectOAuthFailure = exports.initEmailConnectOAuthSuccess = exports.initEmailConnectOAuth = exports.saveConnectorCredentialsFailure = exports.saveConnectorCredentialsSuccess = exports.saveConnectorCredentials = exports.saveOAuthConnectionFailure = exports.saveOAuthConnectionSuccess = exports.saveOAuthConnection = exports.saveAPIKeyConnectionFailure = exports.saveAPIKeyConnectionSuccess = exports.saveAPIKeyConnection = exports.fetchExternalConnectionsSuccess = exports.fetchExternalConnectionsFailure = exports.saveExternalConnectionFailure = exports.saveExternalConnectionSuccess = exports.saveExternalConnection = exports.fetchExternalConnections = exports.updateLoggedInUser = exports.sessionHeartbeatFailure = exports.sessionHeartbeatSuccess = exports.sendSessionHeartbeat = exports.signOutSuccess = exports.doSignOut = exports.updateSignInState = exports.sendEmailMagicLinkToUserFailure = exports.sendEmailMagicLinkToUserSuccess = exports.sendEmailMagicLinkToUser = exports.magicLinkSignInFailure = exports.magicLinkSignInSuccess = exports.doMagicLinkSignIn = exports.doSignIn = exports.updateExcludedResourcesFailure = exports.updateExcludedResourcesSuccess = exports.fetchExcludedResources = exports.updateCurrentTenant = exports.updateTenantFailure = exports.updateTenantSuccess = exports.fetchActiveTenant = exports.updateTenantsFailure = exports.updateTenantsSuccess = exports.fetchAllTenants = exports.updateTenants = exports.initialState = exports.toExternalIntegrationType = void 0;
|
|
8
8
|
exports.toConnection = exports.toRoleResource = exports.resendVerifyDeviceOTPFailure = exports.resendVerifyDeviceOTPSuccess = exports.resendVerifyDeviceOTP = exports.updateTreasuryPromoIntroClosedByOutsideClickForLoggedInUser = exports.updateTreasuryPromoRemindMeLaterClickedForLoggedInUser = exports.updateTreasuryVideoViewedForLoggedInUser = exports.verifyDeviceWithTwoFAFailure = exports.verifyDeviceWithTwoFASuccess = exports.verifyDeviceWithTwoFA = exports.updateTenantMasterTOSInfo = exports.updateTenantCapitalizationAccountOverride = exports.updateTenantCapitalizationOnboardingDismissed = exports.updateTenantProductSettings = exports.updateTenantAutoReviewIncomeWithoutCustomer = exports.updateTenantAccountingProjectsEnabled = exports.updateTenantAccountingClassesEnabled = exports.trigger2FA = exports.resetSignInState = exports.updateReferViewedForLoggedInUser = exports.updateTenantReimbursementInfo = exports.removeOnboardingTenant = exports.updateOnboardingTenants = exports.updateSubscriptionSummaryForTenantFailure = void 0;
|
|
9
9
|
exports.mapCapitalizableAccountsPayload = mapCapitalizableAccountsPayload;
|
|
10
10
|
exports.mapConnectionsPayloadToState = mapConnectionsPayloadToState;
|
|
@@ -28,7 +28,6 @@ exports.initialState = {
|
|
|
28
28
|
error: undefined,
|
|
29
29
|
accountLocked: false,
|
|
30
30
|
tenantsById: {},
|
|
31
|
-
tenantSummariesById: {},
|
|
32
31
|
onboardingTenantsById: {},
|
|
33
32
|
tenantIds: [],
|
|
34
33
|
signInState: 'Not-Started',
|
|
@@ -119,24 +118,26 @@ const tenant = (0, toolkit_1.createSlice)({
|
|
|
119
118
|
});
|
|
120
119
|
},
|
|
121
120
|
},
|
|
122
|
-
|
|
121
|
+
updateTenantsSuccess(draft, action) {
|
|
122
|
+
const { tenants, user } = action.payload;
|
|
123
123
|
draft.fetchState = 'Completed';
|
|
124
124
|
draft.error = undefined;
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
accessibleTenantsById[tenant.tenantId] = tenant;
|
|
125
|
+
const [tenantsbyId, tenantIds, firstUser] = mapTenantsPayloadToState(tenants, user);
|
|
126
|
+
tenantIds.forEach((tenantId) => {
|
|
127
|
+
const existingTenant = draft.tenantsById[tenantId];
|
|
128
|
+
tenantsbyId[tenantId] = applyTreasuryPromoUserFieldsFromPayload(existingTenant, tenantsbyId[tenantId], user);
|
|
129
|
+
if (existingTenant != null) {
|
|
130
|
+
tenantsbyId[tenantId].capitalizableAccountOverrides =
|
|
131
|
+
tenantsbyId[tenantId].capitalizableAccountOverrides ??
|
|
132
|
+
existingTenant.capitalizableAccountOverrides;
|
|
133
|
+
tenantsbyId[tenantId].capitalizationOnboardingDismissedAccounts =
|
|
134
|
+
tenantsbyId[tenantId].capitalizationOnboardingDismissedAccounts ??
|
|
135
|
+
existingTenant.capitalizationOnboardingDismissedAccounts;
|
|
137
136
|
}
|
|
138
137
|
});
|
|
139
|
-
draft.tenantsById =
|
|
138
|
+
draft.tenantsById = tenantsbyId;
|
|
139
|
+
draft.tenantIds = tenantIds;
|
|
140
|
+
draft.loggedInUser = (0, assignWith_1.default)(draft.loggedInUser ?? {}, firstUser, (objValue, srcValue) => srcValue ?? objValue);
|
|
140
141
|
},
|
|
141
142
|
updateTenantsFailure(draft, action) {
|
|
142
143
|
draft.fetchState = 'Error';
|
|
@@ -144,7 +145,6 @@ const tenant = (0, toolkit_1.createSlice)({
|
|
|
144
145
|
draft.error = action.payload;
|
|
145
146
|
draft.tenantIds = [];
|
|
146
147
|
draft.tenantsById = {};
|
|
147
|
-
draft.tenantSummariesById = {};
|
|
148
148
|
},
|
|
149
149
|
updateTenantSuccess(draft, action) {
|
|
150
150
|
const { tenants, user } = action.payload;
|
|
@@ -253,7 +253,6 @@ const tenant = (0, toolkit_1.createSlice)({
|
|
|
253
253
|
draft.signInState = 'Error';
|
|
254
254
|
draft.tenantIds = [];
|
|
255
255
|
draft.tenantsById = {};
|
|
256
|
-
draft.tenantSummariesById = {};
|
|
257
256
|
},
|
|
258
257
|
updateTenantReimbursementInfo(draft, action) {
|
|
259
258
|
const { tenant_id, reimbursement_info } = action.payload;
|
|
@@ -946,7 +945,7 @@ const tenant = (0, toolkit_1.createSlice)({
|
|
|
946
945
|
});
|
|
947
946
|
},
|
|
948
947
|
});
|
|
949
|
-
_a = tenant.actions, exports.updateTenants = _a.updateTenants, exports.fetchAllTenants = _a.fetchAllTenants, exports.
|
|
948
|
+
_a = tenant.actions, exports.updateTenants = _a.updateTenants, exports.fetchAllTenants = _a.fetchAllTenants, exports.updateTenantsSuccess = _a.updateTenantsSuccess, exports.updateTenantsFailure = _a.updateTenantsFailure, exports.fetchActiveTenant = _a.fetchActiveTenant, exports.updateTenantSuccess = _a.updateTenantSuccess, exports.updateTenantFailure = _a.updateTenantFailure, exports.updateCurrentTenant = _a.updateCurrentTenant, exports.fetchExcludedResources = _a.fetchExcludedResources, exports.updateExcludedResourcesSuccess = _a.updateExcludedResourcesSuccess, exports.updateExcludedResourcesFailure = _a.updateExcludedResourcesFailure, exports.doSignIn = _a.doSignIn, exports.doMagicLinkSignIn = _a.doMagicLinkSignIn, exports.magicLinkSignInSuccess = _a.magicLinkSignInSuccess, exports.magicLinkSignInFailure = _a.magicLinkSignInFailure, exports.sendEmailMagicLinkToUser = _a.sendEmailMagicLinkToUser, exports.sendEmailMagicLinkToUserSuccess = _a.sendEmailMagicLinkToUserSuccess, exports.sendEmailMagicLinkToUserFailure = _a.sendEmailMagicLinkToUserFailure, exports.updateSignInState = _a.updateSignInState, exports.doSignOut = _a.doSignOut, exports.signOutSuccess = _a.signOutSuccess, exports.sendSessionHeartbeat = _a.sendSessionHeartbeat, exports.sessionHeartbeatSuccess = _a.sessionHeartbeatSuccess, exports.sessionHeartbeatFailure = _a.sessionHeartbeatFailure, exports.updateLoggedInUser = _a.updateLoggedInUser, exports.fetchExternalConnections = _a.fetchExternalConnections, exports.saveExternalConnection = _a.saveExternalConnection, exports.saveExternalConnectionSuccess = _a.saveExternalConnectionSuccess, exports.saveExternalConnectionFailure = _a.saveExternalConnectionFailure, exports.fetchExternalConnectionsFailure = _a.fetchExternalConnectionsFailure, exports.fetchExternalConnectionsSuccess = _a.fetchExternalConnectionsSuccess, exports.saveAPIKeyConnection = _a.saveAPIKeyConnection, exports.saveAPIKeyConnectionSuccess = _a.saveAPIKeyConnectionSuccess, exports.saveAPIKeyConnectionFailure = _a.saveAPIKeyConnectionFailure, exports.saveOAuthConnection = _a.saveOAuthConnection, exports.saveOAuthConnectionSuccess = _a.saveOAuthConnectionSuccess, exports.saveOAuthConnectionFailure = _a.saveOAuthConnectionFailure, exports.saveConnectorCredentials = _a.saveConnectorCredentials, exports.saveConnectorCredentialsSuccess = _a.saveConnectorCredentialsSuccess, exports.saveConnectorCredentialsFailure = _a.saveConnectorCredentialsFailure, exports.initEmailConnectOAuth = _a.initEmailConnectOAuth, exports.initEmailConnectOAuthSuccess = _a.initEmailConnectOAuthSuccess, exports.initEmailConnectOAuthFailure = _a.initEmailConnectOAuthFailure, exports.deleteConnection = _a.deleteConnection, exports.deleteConnectionSuccess = _a.deleteConnectionSuccess, exports.deleteConnectionFailure = _a.deleteConnectionFailure, exports.fetchSubscriptionSummaryForTenant = _a.fetchSubscriptionSummaryForTenant, exports.updateSubscriptionSummaryForTenantSuccess = _a.updateSubscriptionSummaryForTenantSuccess, exports.updateSubscriptionSummaryForTenantFailure = _a.updateSubscriptionSummaryForTenantFailure, exports.updateOnboardingTenants = _a.updateOnboardingTenants, exports.removeOnboardingTenant = _a.removeOnboardingTenant, exports.updateTenantReimbursementInfo = _a.updateTenantReimbursementInfo, exports.updateReferViewedForLoggedInUser = _a.updateReferViewedForLoggedInUser, exports.resetSignInState = _a.resetSignInState, exports.trigger2FA = _a.trigger2FA, exports.updateTenantAccountingClassesEnabled = _a.updateTenantAccountingClassesEnabled, exports.updateTenantAccountingProjectsEnabled = _a.updateTenantAccountingProjectsEnabled, exports.updateTenantAutoReviewIncomeWithoutCustomer = _a.updateTenantAutoReviewIncomeWithoutCustomer, exports.updateTenantProductSettings = _a.updateTenantProductSettings, exports.updateTenantCapitalizationOnboardingDismissed = _a.updateTenantCapitalizationOnboardingDismissed, exports.updateTenantCapitalizationAccountOverride = _a.updateTenantCapitalizationAccountOverride, exports.updateTenantMasterTOSInfo = _a.updateTenantMasterTOSInfo, exports.verifyDeviceWithTwoFA = _a.verifyDeviceWithTwoFA, exports.verifyDeviceWithTwoFASuccess = _a.verifyDeviceWithTwoFASuccess, exports.verifyDeviceWithTwoFAFailure = _a.verifyDeviceWithTwoFAFailure, exports.updateTreasuryVideoViewedForLoggedInUser = _a.updateTreasuryVideoViewedForLoggedInUser, exports.updateTreasuryPromoRemindMeLaterClickedForLoggedInUser = _a.updateTreasuryPromoRemindMeLaterClickedForLoggedInUser, exports.updateTreasuryPromoIntroClosedByOutsideClickForLoggedInUser = _a.updateTreasuryPromoIntroClosedByOutsideClickForLoggedInUser, exports.resendVerifyDeviceOTP = _a.resendVerifyDeviceOTP, exports.resendVerifyDeviceOTPSuccess = _a.resendVerifyDeviceOTPSuccess, exports.resendVerifyDeviceOTPFailure = _a.resendVerifyDeviceOTPFailure;
|
|
950
949
|
exports.default = tenant.reducer;
|
|
951
950
|
/**
|
|
952
951
|
* Applies treasury promo user fields from the tenants API user block when present.
|
|
@@ -988,16 +987,6 @@ function mapTenantsPayloadToState(tenantsPayload, userTenantPayload) {
|
|
|
988
987
|
const firstUser = mapTenantPayloadToUser(tenantsPayload[0]);
|
|
989
988
|
return [tenantsById, tenantIds, firstUser];
|
|
990
989
|
}
|
|
991
|
-
function mapTenantSummaryPayloadToTenantSummary(payload) {
|
|
992
|
-
return {
|
|
993
|
-
companyId: payload.company_id,
|
|
994
|
-
companyName: payload.company_name,
|
|
995
|
-
tenantEmailDomain: payload.tenant_email_domain,
|
|
996
|
-
tenantId: payload.tenant_id,
|
|
997
|
-
// A tenant never opened sorts last, as in `mapTenantPayloadToTenant`.
|
|
998
|
-
userLastCheckInTime: (0, zeniDayJS_1.date)(payload.user_last_check_in_time_into_tenant ?? '1970-01-01'),
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
990
|
function mapTenantPayloadToTenant(payload, userTenantPayload) {
|
|
1002
991
|
const tenant = {
|
|
1003
992
|
accountingClassIDs: payload.accounting_class_ids,
|
|
@@ -22,14 +22,11 @@ export interface TenantBaseView extends TenantCoreDetailsView {
|
|
|
22
22
|
}
|
|
23
23
|
export declare function getTenant(tenantState: TenantState, companyState: CompanyState, tenantId: ID): TenantView | undefined;
|
|
24
24
|
export declare function getTenantIdByCompanyId(tenantState: TenantState, companyId: ID): ID | undefined;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* to complete: the tenants list alone carries neither.
|
|
31
|
-
*/
|
|
32
|
-
export declare const isCurrentTenantLoaded: (state: RootState) => boolean;
|
|
25
|
+
declare function getTenantsByCheckInDate(tenantState: TenantState, companyState: CompanyState): {
|
|
26
|
+
order: "descending_last_check_in";
|
|
27
|
+
tenantsInOrder: TenantView[];
|
|
28
|
+
};
|
|
29
|
+
export type TenantsOrdered = ReturnType<typeof getTenantsByCheckInDate>;
|
|
33
30
|
export declare const getTenantBaseViewForTenantId: (state: RootState, tenantId: ID) => TenantBaseView | undefined;
|
|
34
31
|
export type TenantsBaseOrdered = {
|
|
35
32
|
order: 'descending_last_check_in';
|
|
@@ -77,12 +74,7 @@ declare const getCurrentTenantHelper: (tenantState: TenantState, companyState: C
|
|
|
77
74
|
};
|
|
78
75
|
export type CurrentTenant = ReturnType<typeof getCurrentTenantHelper>;
|
|
79
76
|
export declare const getCurrentTenant: (state: RootState) => CurrentTenant;
|
|
80
|
-
|
|
81
|
-
* The selected tenant's id as soon as it is chosen. Unlike `getCurrentTenant`,
|
|
82
|
-
* it is set before the tenant fetch lands (boot reads it from the cached
|
|
83
|
-
* tenant list).
|
|
84
|
-
*/
|
|
85
|
-
export declare const getCurrentTenantId: (state: RootState) => ID | undefined;
|
|
77
|
+
export declare const getTenantsByCheckInDateSelector: (state: RootState) => TenantsOrdered;
|
|
86
78
|
export declare function getOnboardingTenantByTenantId(tenantState: TenantState, tenantId: ID): Tenant | undefined;
|
|
87
79
|
export declare const getTenantBaseById: (state: RootState) => TenantBaseView[];
|
|
88
80
|
export declare const getTenantsBaseByCheckInDateSelector: (state: RootState) => TenantsBaseOrdered;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DEFAULT_RECEIPTS_EMAIL = exports.isTenantTreasuryEnabled = exports.isOtherProductsEnabledForTenant = exports.isTenantBookkeepingEnabled = exports.getIsAutoReviewIncomeWithoutCustomerEnabled = exports.getIsAccountingProjectsEnabled = exports.getIsAccountingClassesEnabled = exports.isTenantAccountingServicesEnabled = exports.isTenantCardsOnly = exports.isTenantBankingOnly = exports.toTenantCoreDetailsView = exports.getCurrentTenantExternalConnections = exports.isTenantUsingZeniCOA = exports.isZeniDomainTenant = exports.getTenantBaseViewForTenantView = exports.getTenantsCoreDetailsByCheckInDateSelector = exports.getTenantsBaseByCheckInDateSelector = exports.getTenantBaseById = exports.
|
|
6
|
+
exports.DEFAULT_RECEIPTS_EMAIL = exports.isTenantTreasuryEnabled = exports.isOtherProductsEnabledForTenant = exports.isTenantBookkeepingEnabled = exports.getIsAutoReviewIncomeWithoutCustomerEnabled = exports.getIsAccountingProjectsEnabled = exports.getIsAccountingClassesEnabled = exports.isTenantAccountingServicesEnabled = exports.isTenantCardsOnly = exports.isTenantBankingOnly = exports.toTenantCoreDetailsView = exports.getCurrentTenantExternalConnections = exports.isTenantUsingZeniCOA = exports.isZeniDomainTenant = exports.getTenantBaseViewForTenantView = exports.getTenantsCoreDetailsByCheckInDateSelector = exports.getTenantsBaseByCheckInDateSelector = exports.getTenantBaseById = exports.getTenantsByCheckInDateSelector = exports.getCurrentTenant = exports.getTenantBaseViewForTenantId = void 0;
|
|
7
7
|
exports.getTenant = getTenant;
|
|
8
8
|
exports.getTenantIdByCompanyId = getTenantIdByCompanyId;
|
|
9
9
|
exports.getOnboardingTenantByTenantId = getOnboardingTenantByTenantId;
|
|
@@ -26,77 +26,50 @@ function getTenant(tenantState, companyState, tenantId) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
function getTenantIdByCompanyId(tenantState, companyId) {
|
|
29
|
-
return
|
|
30
|
-
Object.values(tenantState.tenantSummariesById).find((tenantSummary) => tenantSummary.companyId === companyId))?.tenantId;
|
|
29
|
+
return Object.values(tenantState.tenantsById).find((tenant) => tenant.companyId === companyId)?.tenantId;
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (tenant != null) {
|
|
42
|
-
return {
|
|
43
|
-
companyId: tenant.companyId,
|
|
44
|
-
companyName: tenant.companyName,
|
|
45
|
-
tenantEmailDomain: tenant.tenantEmailDomain,
|
|
46
|
-
tenantId: tenant.tenantId,
|
|
47
|
-
userLastCheckInTime: tenant.userLastCheckInTime,
|
|
48
|
-
userRole: tenant.userRole,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return tenantSummary != null
|
|
52
|
-
? { ...tenantSummary, userRole: [] }
|
|
53
|
-
: undefined;
|
|
54
|
-
})
|
|
55
|
-
.filter((entry) => entry != null);
|
|
56
|
-
return (0, orderBy_1.default)(entries, (entry) => entry.userLastCheckInTime.valueOf(), 'desc');
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* The selected tenant's full record. With no tenant selected, or one the user
|
|
60
|
-
* can no longer open, it is the most recently opened loaded tenant. A selected
|
|
61
|
-
* tenant that is in the list but not loaded yet reads as no tenant until its
|
|
62
|
-
* fetch lands, so nothing renders another tenant's record in its place.
|
|
63
|
-
*/
|
|
64
|
-
function getCurrentTenantView(tenantState, companyState) {
|
|
65
|
-
const { currentTenantId } = tenantState;
|
|
66
|
-
if (currentTenantId != null) {
|
|
67
|
-
const tenant = getTenant(tenantState, companyState, currentTenantId);
|
|
68
|
-
if (tenant != null ||
|
|
69
|
-
tenantState.tenantSummariesById[currentTenantId] != null) {
|
|
70
|
-
return tenant;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const mostRecentLoadedTenant = getTenantListEntriesByCheckInDate(tenantState).find((entry) => tenantState.tenantsById[entry.tenantId] != null);
|
|
74
|
-
return mostRecentLoadedTenant != null
|
|
75
|
-
? getTenant(tenantState, companyState, mostRecentLoadedTenant.tenantId)
|
|
76
|
-
: undefined;
|
|
31
|
+
function getTenantsByCheckInDate(tenantState, companyState) {
|
|
32
|
+
const tenants = tenantState.tenantIds
|
|
33
|
+
.map((tenantId) => getTenant(tenantState, companyState, tenantId))
|
|
34
|
+
.filter((value) => value != null);
|
|
35
|
+
const tenantsOrdered = (0, orderBy_1.default)(tenants, (value) => value.userLastCheckInTime.valueOf(), 'desc');
|
|
36
|
+
return {
|
|
37
|
+
order: 'descending_last_check_in',
|
|
38
|
+
tenantsInOrder: tenantsOrdered,
|
|
39
|
+
};
|
|
77
40
|
}
|
|
78
|
-
/** Whether the tenant's full record is loaded, not just its list entry. */
|
|
79
|
-
const isTenantLoaded = (state, tenantId) => state.tenantState.tenantsById[tenantId] != null;
|
|
80
|
-
exports.isTenantLoaded = isTenantLoaded;
|
|
81
|
-
/**
|
|
82
|
-
* Whether the selected tenant's full record is loaded. Screens that act on
|
|
83
|
-
* roles or product settings wait for this rather than for either tenant fetch
|
|
84
|
-
* to complete: the tenants list alone carries neither.
|
|
85
|
-
*/
|
|
86
|
-
const isCurrentTenantLoaded = (state) => {
|
|
87
|
-
const { currentTenantId } = state.tenantState;
|
|
88
|
-
return currentTenantId != null && (0, exports.isTenantLoaded)(state, currentTenantId);
|
|
89
|
-
};
|
|
90
|
-
exports.isCurrentTenantLoaded = isCurrentTenantLoaded;
|
|
91
41
|
exports.getTenantBaseViewForTenantId = (0, toolkit_1.createSelector)((state) => state.tenantState, (state) => state.companyState, (_state, tenantId) => tenantId, (tenantState, companyState, tenantId) => {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
42
|
+
const tenant = tenantState.tenantsById[tenantId];
|
|
43
|
+
if (tenant != null) {
|
|
44
|
+
const companyId = tenant.companyId;
|
|
45
|
+
const companyName = companyState.companiesById[companyId]?.companyInfo.name;
|
|
46
|
+
const tenantName = tenant.companyName ?? companyName;
|
|
47
|
+
const tenantEmailDomain = tenant.tenantEmailDomain;
|
|
48
|
+
const userRole = tenant.userRole;
|
|
49
|
+
const companyLocaleInfo = companyState.companiesById[companyId]?.companyLocaleInfo;
|
|
50
|
+
return {
|
|
51
|
+
tenantId,
|
|
52
|
+
tenantName,
|
|
53
|
+
tenantEmailDomain,
|
|
54
|
+
companyId,
|
|
55
|
+
companyName,
|
|
56
|
+
userRole,
|
|
57
|
+
companyLocaleInfo,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
96
61
|
});
|
|
97
62
|
const getCurrentTenantHelper = (tenantState, companyState) => {
|
|
98
|
-
const { currentTenantId, excludedResourcesByTenant, subscriptionSummaryByTenant, } = tenantState;
|
|
99
|
-
|
|
63
|
+
const { tenantIds, currentTenantId, excludedResourcesByTenant, subscriptionSummaryByTenant, } = tenantState;
|
|
64
|
+
let tenant = undefined;
|
|
65
|
+
if (currentTenantId != null) {
|
|
66
|
+
tenant = getTenant(tenantState, companyState, currentTenantId);
|
|
67
|
+
}
|
|
68
|
+
if (tenant == null && tenantIds.length > 0) {
|
|
69
|
+
const tenants = getTenantsByCheckInDate(tenantState, companyState);
|
|
70
|
+
tenant =
|
|
71
|
+
tenants.tenantsInOrder.length > 0 ? tenants.tenantsInOrder[0] : undefined;
|
|
72
|
+
}
|
|
100
73
|
let excludedResources = undefined;
|
|
101
74
|
if (tenant != null) {
|
|
102
75
|
excludedResources = excludedResourcesByTenant[tenant.tenantId];
|
|
@@ -157,13 +130,9 @@ const getCurrentTenantHelper = (tenantState, companyState) => {
|
|
|
157
130
|
exports.getCurrentTenant = (0, toolkit_1.createSelector)((state) => state.tenantState, (state) => state.companyState, (tenantState, companyState) => {
|
|
158
131
|
return getCurrentTenantHelper(tenantState, companyState);
|
|
159
132
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
* tenant list).
|
|
164
|
-
*/
|
|
165
|
-
const getCurrentTenantId = (state) => state.tenantState.currentTenantId;
|
|
166
|
-
exports.getCurrentTenantId = getCurrentTenantId;
|
|
133
|
+
exports.getTenantsByCheckInDateSelector = (0, toolkit_1.createSelector)((state) => state.tenantState, (state) => state.companyState, (tenantState, companyState) => {
|
|
134
|
+
return getTenantsByCheckInDate(tenantState, companyState);
|
|
135
|
+
});
|
|
167
136
|
function getOnboardingTenantByTenantId(tenantState, tenantId) {
|
|
168
137
|
const tenant = tenantState.onboardingTenantsById[tenantId];
|
|
169
138
|
if (tenant != null) {
|
|
@@ -174,7 +143,10 @@ function getOnboardingTenantByTenantId(tenantState, tenantId) {
|
|
|
174
143
|
}
|
|
175
144
|
}
|
|
176
145
|
exports.getTenantBaseById = (0, toolkit_1.createSelector)((state) => state.tenantState, (state) => state.companyState, (tenantState, companyState) => {
|
|
177
|
-
return
|
|
146
|
+
return tenantState.tenantIds.map((tenantId) => {
|
|
147
|
+
const tenant = tenantState.tenantsById[tenantId];
|
|
148
|
+
return getTenantBaseViewForTenant(tenant, companyState);
|
|
149
|
+
});
|
|
178
150
|
});
|
|
179
151
|
exports.getTenantsBaseByCheckInDateSelector = (0, toolkit_1.createSelector)((state) => state.tenantState, (state) => state.companyState, (tenantState, companyState) => {
|
|
180
152
|
return getTenantsBaseByCheckInDate(tenantState, companyState);
|
|
@@ -206,8 +178,16 @@ const isTenantUsingZeniCOA = (currentTenant) => {
|
|
|
206
178
|
};
|
|
207
179
|
exports.isTenantUsingZeniCOA = isTenantUsingZeniCOA;
|
|
208
180
|
const getCurrentTenantExternalConnections = (tenantState, companyState) => {
|
|
209
|
-
const { externalConnectionsByTenant, currentTenantId } = tenantState;
|
|
210
|
-
|
|
181
|
+
const { externalConnectionsByTenant, tenantIds, currentTenantId } = tenantState;
|
|
182
|
+
let tenant = undefined;
|
|
183
|
+
if (currentTenantId != null) {
|
|
184
|
+
tenant = getTenant(tenantState, companyState, currentTenantId);
|
|
185
|
+
}
|
|
186
|
+
if (tenant == null && tenantIds.length > 0) {
|
|
187
|
+
const tenants = getTenantsByCheckInDate(tenantState, companyState);
|
|
188
|
+
tenant =
|
|
189
|
+
tenants.tenantsInOrder.length > 0 ? tenants.tenantsInOrder[0] : undefined;
|
|
190
|
+
}
|
|
211
191
|
let externalConnections = undefined;
|
|
212
192
|
if (tenant != null) {
|
|
213
193
|
externalConnections = externalConnectionsByTenant[tenant.tenantId];
|
|
@@ -222,39 +202,58 @@ exports.getCurrentTenantExternalConnections = getCurrentTenantExternalConnection
|
|
|
222
202
|
* Helpers
|
|
223
203
|
*/
|
|
224
204
|
function getTenantsBaseByCheckInDate(tenantState, companyState) {
|
|
205
|
+
const tenants = tenantState.tenantIds
|
|
206
|
+
.map((tenantId) => getTenant(tenantState, companyState, tenantId))
|
|
207
|
+
.filter((value) => value != null);
|
|
208
|
+
const tenantsOrdered = (0, orderBy_1.default)(tenants, (value) => value.userLastCheckInTime.valueOf(), 'desc');
|
|
209
|
+
const tenantsBaseOrdered = tenantsOrdered.map((tenant) => getTenantBaseViewForTenant(tenant, companyState));
|
|
225
210
|
return {
|
|
226
211
|
order: 'descending_last_check_in',
|
|
227
|
-
tenantsBaseInOrder:
|
|
212
|
+
tenantsBaseInOrder: tenantsBaseOrdered,
|
|
228
213
|
};
|
|
229
214
|
}
|
|
230
|
-
const
|
|
231
|
-
const
|
|
215
|
+
const getTenantBaseViewForTenant = (tenant, companyState) => {
|
|
216
|
+
const tenantId = tenant.tenantId;
|
|
217
|
+
const companyId = tenant.companyId;
|
|
218
|
+
const companyName = companyState.companiesById[companyId]?.companyInfo.name;
|
|
219
|
+
const tenantName = tenant.companyName ?? companyName ?? tenant.tenantEmailDomain ?? '';
|
|
220
|
+
const tenantEmailDomain = tenant.tenantEmailDomain;
|
|
221
|
+
const userRole = tenant.userRole;
|
|
222
|
+
const companyLocaleInfo = companyState.companiesById[companyId]?.companyLocaleInfo;
|
|
232
223
|
return {
|
|
233
|
-
tenantId
|
|
234
|
-
tenantName
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
// Companies are loaded only for opened tenants; the list carries the name.
|
|
241
|
-
companyName: company?.companyInfo.name ?? entry.companyName,
|
|
242
|
-
userRole: entry.userRole,
|
|
243
|
-
companyLocaleInfo: company?.companyLocaleInfo,
|
|
224
|
+
tenantId,
|
|
225
|
+
tenantName,
|
|
226
|
+
tenantEmailDomain,
|
|
227
|
+
companyId,
|
|
228
|
+
companyName,
|
|
229
|
+
userRole,
|
|
230
|
+
companyLocaleInfo,
|
|
244
231
|
};
|
|
245
232
|
};
|
|
246
233
|
function getTenantCoreDetailsByCheckInDate(tenantState, companyState) {
|
|
234
|
+
const tenants = tenantState.tenantIds
|
|
235
|
+
.map((tenantId) => getTenant(tenantState, companyState, tenantId))
|
|
236
|
+
.filter((value) => value != null);
|
|
237
|
+
const tenantsOrdered = (0, orderBy_1.default)(tenants, (value) => value.userLastCheckInTime.valueOf(), 'desc');
|
|
238
|
+
const tenantsCoreDetailsOrdered = tenantsOrdered.map((tenant) => getTenantCoreDetailsViewForTenant(tenant, companyState));
|
|
247
239
|
return {
|
|
248
240
|
order: 'descending_last_check_in',
|
|
249
|
-
tenantsCoreDetailsInOrder:
|
|
250
|
-
tenantId: entry.tenantId,
|
|
251
|
-
tenantName: entry.companyName ??
|
|
252
|
-
companyState.companiesById[entry.companyId]?.companyInfo.name,
|
|
253
|
-
tenantEmailDomain: entry.tenantEmailDomain,
|
|
254
|
-
companyId: entry.companyId,
|
|
255
|
-
})),
|
|
241
|
+
tenantsCoreDetailsInOrder: tenantsCoreDetailsOrdered,
|
|
256
242
|
};
|
|
257
243
|
}
|
|
244
|
+
const getTenantCoreDetailsViewForTenant = (tenant, companyState) => {
|
|
245
|
+
const tenantId = tenant.tenantId;
|
|
246
|
+
const companyId = tenant.companyId;
|
|
247
|
+
const companyName = companyState.companiesById[companyId]?.companyInfo.name;
|
|
248
|
+
const tenantName = tenant.companyName ?? companyName;
|
|
249
|
+
const tenantEmailDomain = tenant.tenantEmailDomain;
|
|
250
|
+
return {
|
|
251
|
+
tenantId,
|
|
252
|
+
tenantName,
|
|
253
|
+
tenantEmailDomain,
|
|
254
|
+
companyId,
|
|
255
|
+
};
|
|
256
|
+
};
|
|
258
257
|
const toTenantCoreDetailsView = (tenantsBaseView) => {
|
|
259
258
|
return tenantsBaseView.map(({ tenantId, tenantName, tenantEmailDomain, companyId }) => {
|
|
260
259
|
return {
|
|
@@ -46,10 +46,7 @@ export interface TenantState extends FetchedState {
|
|
|
46
46
|
summary?: SubscriptionSummary;
|
|
47
47
|
} | undefined>;
|
|
48
48
|
tenantIds: ID[];
|
|
49
|
-
/** Full records, loaded per tenant by the active-tenant fetch. */
|
|
50
49
|
tenantsById: Record<ID, Tenant>;
|
|
51
|
-
/** Every tenant the user can open, from the tenants list. */
|
|
52
|
-
tenantSummariesById: Record<ID, TenantSummary>;
|
|
53
50
|
verifyDeviceFetchState: FetchStateAndError;
|
|
54
51
|
accountLockTime?: ZeniDate;
|
|
55
52
|
accountUnlockTime?: ZeniDate;
|
|
@@ -61,13 +58,6 @@ export interface TenantState extends FetchedState {
|
|
|
61
58
|
sessionExpiresAt?: string;
|
|
62
59
|
twoFAPhoneNumber?: string;
|
|
63
60
|
}
|
|
64
|
-
export interface TenantSummary {
|
|
65
|
-
companyId: ID;
|
|
66
|
-
companyName: string;
|
|
67
|
-
tenantEmailDomain: string;
|
|
68
|
-
tenantId: ID;
|
|
69
|
-
userLastCheckInTime: ZeniDate;
|
|
70
|
-
}
|
|
71
61
|
export interface TenantProductSettings {
|
|
72
62
|
isBankingEnabled: boolean;
|
|
73
63
|
isBookkeepingEnabled: boolean;
|