Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / reducers / organization.ts
blob65bf2f30f9f889bc2e9f3af60dfa871923c110cd
1 import type { Reducer } from 'redux';
3 import { getUserAccessSuccess, userEvent } from '@proton/pass/store/actions';
4 import { getOrganizationSettings } from '@proton/pass/store/actions/creators/organization';
5 import { BitField, type MaybeNull, PlanType } from '@proton/pass/types';
6 import { type OrganizationSettings } from '@proton/pass/types/data/organization';
7 import { partialMerge } from '@proton/pass/utils/object/merge';
8 import type { Organization } from '@proton/shared/lib/interfaces';
10 export const INITIAL_ORGANIZATION_SETTINGS: OrganizationSettings = {
11     ExportMode: BitField.DISABLED,
12     ShareMode: BitField.DISABLED,
13     ForceLockSeconds: BitField.DISABLED,
16 export type OrganizationState = {
17     canUpdate: boolean;
18     organization: Organization;
19     settings: OrganizationSettings;
22 const organizationReducer: Reducer<MaybeNull<OrganizationState>> = (state = null, action) => {
23     /* Remove all organization state if the user plan changes */
24     if (getUserAccessSuccess.match(action)) return action.payload.plan.Type !== PlanType.business ? null : state;
26     if (state !== null) {
27         /* Actions applied to the organization state should only be processed
28          * if we actually have an organization state in the first place. */
29         if (userEvent.match(action) && action.payload.Organization) {
30             return partialMerge(state, { organization: action.payload.Organization });
31         }
33         if (getOrganizationSettings.success.match(action)) {
34             const { Settings, CanUpdate } = action.payload;
35             return partialMerge(state, { settings: Settings, canUpdate: CanUpdate });
36         }
37     }
39     return state;
42 export default organizationReducer;