1 import type { MutableRefObject } from 'react';
3 import { c } from 'ttag';
5 import { useAddresses } from '@proton/account/addresses/hooks';
6 import { useOrganizationKey } from '@proton/account/organizationKey/hooks';
7 import { Button } from '@proton/atoms';
8 import Alert from '@proton/components/components/alert/Alert';
9 import Loader from '@proton/components/components/loader/Loader';
10 import Table from '@proton/components/components/table/Table';
11 import TableBody from '@proton/components/components/table/TableBody';
12 import TableHeader from '@proton/components/components/table/TableHeader';
13 import TableRow from '@proton/components/components/table/TableRow';
14 import SettingsParagraph from '@proton/components/containers/account/SettingsParagraph';
15 import SettingsSection from '@proton/components/containers/account/SettingsSection';
16 import { getKnowledgeBaseUrl } from '@proton/shared/lib/helpers/url';
17 import type { Organization } from '@proton/shared/lib/interfaces';
21 getOrganizationKeyInfo,
22 } from '@proton/shared/lib/organization/helper';
24 import useDisplayOrganizationKey from './useDisplayOrganizationKey';
25 import useOrganizationModals from './useOrganizationModals';
28 organization?: Organization;
29 onceRef: MutableRefObject<boolean>;
32 const OrganizationPasswordSection = ({ organization, onceRef }: Props) => {
33 const [organizationKey, loadingOrganizationKey] = useOrganizationKey();
34 const [addresses] = useAddresses();
35 const organizationKeyInfo = getOrganizationKeyInfo(organization, organizationKey, addresses);
36 const displayOrganizationKey = useDisplayOrganizationKey(organizationKey);
37 const { modals, info, handleChangeOrganizationPassword, handleChangeOrganizationKeys } =
38 useOrganizationModals(onceRef);
40 const tableHeaders = [c('Header').t`Organization key fingerprint`, c('Header').t`Key type`];
42 const loading = !organization || loadingOrganizationKey;
52 // Organization is not setup.
53 if (!organization?.HasKeys) {
55 <Alert className="mb-4" type="warning">{c('Info').t`Multi-user support not enabled.`}</Alert>
61 <SettingsParagraph learnMoreUrl={getKnowledgeBaseUrl('/organization-key')}>
63 .t`Your organization's emails are protected with end-to-end encryption using the organization key. This fingerprint can be used to verify that all administrators in your account have the same key.`}
65 <div className="mb-4">
66 {organizationKeyInfo.state === OrganizationKeyState.Active && (
68 {organizationKeyInfo.mode !== OrganizationKeyMode.Passwordless && (
71 onClick={handleChangeOrganizationPassword}
74 {c('Action').t`Change password`}
77 <Button className="mb-2" onClick={() => handleChangeOrganizationKeys()}>
78 {c('passwordless').t`Change organization key`}
84 {displayOrganizationKey.fingerprint && (
85 <Table responsive="cards">
86 <TableHeader cells={tableHeaders} />
87 <TableBody colSpan={2}>
91 <code key={1} className="max-w-full block text-ellipsis">
92 {displayOrganizationKey.fingerprint}
94 displayOrganizationKey.algorithm,
107 export default OrganizationPasswordSection;