This repository has been archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
ContactDetails.js
59 lines (51 loc) · 1.91 KB
/
ContactDetails.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { c } from 'ttag';
import { useApi, useLoading, Loader, FormModal, PrimaryButton } from 'react-components';
import { splitKeys } from 'proton-shared/lib/keys/keys';
import { getContact } from 'proton-shared/lib/api/contacts';
import { FAIL_TO_LOAD } from '../../constants';
import { prepareContact } from '../../helpers/decrypt';
import ContactViewErrors from '../ContactViewErrors';
import MergedContactSummary from './MergedContactSummary';
const ContactDetails = ({ contactID, userKeysList, hasPaidMail, ...rest }) => {
const api = useApi();
const [loading, withLoading] = useLoading(true);
const [model, setModel] = useState({ properties: [], errors: [] });
useEffect(() => {
const request = async () => {
const { Contact } = await api(getContact(contactID));
const { properties, errors } = await prepareContact(Contact, splitKeys(userKeysList));
setModel({ properties, errors });
};
try {
withLoading(request());
} catch (error) {
setModel({ ...model, errors: [FAIL_TO_LOAD] });
}
}, []);
return (
<FormModal
small
title={c('Title').t`Contact Details`}
onSubmit={rest.onClose}
footer={<PrimaryButton type="submit">{c('Action').t`Close`}</PrimaryButton>}
{...rest}
>
{loading ? (
<Loader />
) : (
<>
<ContactViewErrors errors={model.errors} />
<MergedContactSummary properties={model.properties} hasPaidMail={hasPaidMail} />
</>
)}
</FormModal>
);
};
ContactDetails.propTypes = {
contactID: PropTypes.string,
userKeysList: PropTypes.array,
hasPaidMail: PropTypes.bool
};
export default ContactDetails;