Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / lib / organization / organization.requests.ts
blob429f15eff9d10b18d0c1176c7688af6b9b4edbf2
1 import { api } from '@proton/pass/lib/api/api';
2 import type { OrganizationState } from '@proton/pass/store/reducers/organization';
3 import type { MaybeNull, OrganizationGetResponse } from '@proton/pass/types';
4 import type { OrganizationSettings } from '@proton/pass/types/data/organization';
5 import { logger } from '@proton/pass/utils/logger';
6 import { getOrganization as coreGetOrganization } from '@proton/shared/lib/api/organization';
7 import type { Organization } from '@proton/shared/lib/interfaces';
9 export const getUserOrganization = async (): Promise<MaybeNull<Organization>> => {
10     try {
11         logger.info(`[User] Syncing organization info`);
12         return (await api<{ Organization: Organization }>(coreGetOrganization())).Organization;
13     } catch {
14         return null;
15     }
18 export const getOrganizationSettings = async (): Promise<OrganizationGetResponse> =>
19     (await api({ url: 'pass/v1/organization', method: 'get' })).Organization!;
21 export const setOrganizationSettings = async (
22     settings: Partial<OrganizationSettings>
23 ): Promise<OrganizationGetResponse> =>
24     (
25         await api({
26             url: 'pass/v1/organization/settings',
27             method: 'put',
28             data: settings,
29         })
30     ).Organization!;
32 export const getOrganization = async (): Promise<MaybeNull<OrganizationState>> => {
33     const organization = await getUserOrganization();
34     if (!organization) return null;
36     const { Settings, CanUpdate }: OrganizationGetResponse = await getOrganizationSettings();
38     return {
39         settings: Settings!,
40         canUpdate: CanUpdate,
41         organization,
42     };