2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-09-03 17:54:20 +02:00
|
|
|
import classnames from 'classnames';
|
2021-02-04 19:15:23 +01:00
|
|
|
import ContactList from '../../../components/app/contact-list';
|
2019-07-31 21:56:44 +02:00
|
|
|
import {
|
|
|
|
CONTACT_ADD_ROUTE,
|
|
|
|
CONTACT_VIEW_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../helpers/constants/routes';
|
2021-05-01 03:15:19 +02:00
|
|
|
import Button from '../../../components/ui/button';
|
2022-02-22 21:58:21 +01:00
|
|
|
import {
|
|
|
|
getSettingsSectionNumber,
|
|
|
|
handleSettingsRefs,
|
|
|
|
} from '../../../helpers/utils/settings-search';
|
2021-02-04 19:15:23 +01:00
|
|
|
import EditContact from './edit-contact';
|
|
|
|
import AddContact from './add-contact';
|
|
|
|
import ViewContact from './view-contact';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
export default class ContactListTab extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
addressBook: PropTypes.array,
|
|
|
|
history: PropTypes.object,
|
|
|
|
selectedAddress: PropTypes.string,
|
|
|
|
viewingContact: PropTypes.bool,
|
|
|
|
editingContact: PropTypes.bool,
|
|
|
|
addingContact: PropTypes.bool,
|
|
|
|
showContactContent: PropTypes.bool,
|
|
|
|
hideAddressBook: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2022-02-22 21:58:21 +01:00
|
|
|
settingsRefs = Array(
|
|
|
|
getSettingsSectionNumber(this.context.t, this.context.t('contacts')),
|
|
|
|
)
|
|
|
|
.fill(undefined)
|
|
|
|
.map(() => {
|
|
|
|
return React.createRef();
|
|
|
|
});
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
const { t } = this.context;
|
|
|
|
handleSettingsRefs(t, t('contacts'), this.settingsRefs);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const { t } = this.context;
|
|
|
|
handleSettingsRefs(t, t('contacts'), this.settingsRefs);
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderAddresses() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { addressBook, history, selectedAddress } = this.props;
|
|
|
|
const contacts = addressBook.filter(({ name }) => Boolean(name));
|
|
|
|
const nonContacts = addressBook.filter(({ name }) => !name);
|
|
|
|
const { t } = this.context;
|
2021-04-27 20:25:58 +02:00
|
|
|
|
|
|
|
if (addressBook.length) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<ContactList
|
|
|
|
searchForContacts={() => contacts}
|
|
|
|
searchForRecents={() => nonContacts}
|
|
|
|
selectRecipient={(address) => {
|
|
|
|
history.push(`${CONTACT_VIEW_ROUTE}/${address}`);
|
|
|
|
}}
|
|
|
|
selectedAddress={selectedAddress}
|
|
|
|
/>
|
2020-11-03 00:41:28 +01:00
|
|
|
</div>
|
2021-04-27 20:25:58 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div className="address-book__container">
|
|
|
|
<div>
|
2021-06-15 18:31:25 +02:00
|
|
|
<img src="./images/address-book.svg" alt={t('addressBookIcon')} />
|
2021-06-15 04:59:30 +02:00
|
|
|
<h4 className="address-book__title">{t('buildContactList')}</h4>
|
2021-04-27 20:25:58 +02:00
|
|
|
<p className="address-book__sub-title">
|
|
|
|
{t('addFriendsAndAddresses')}
|
|
|
|
</p>
|
|
|
|
<button
|
|
|
|
className="address-book__link"
|
|
|
|
onClick={() => {
|
|
|
|
history.push(CONTACT_ADD_ROUTE);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
+ {t('addContact')}
|
|
|
|
</button>
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2021-05-01 03:15:19 +02:00
|
|
|
renderAddButton() {
|
2021-09-03 17:54:20 +02:00
|
|
|
const { history, viewingContact, editingContact } = this.props;
|
2021-05-01 03:15:19 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="address-book-add-button">
|
|
|
|
<Button
|
2021-09-03 17:54:20 +02:00
|
|
|
className={classnames({
|
|
|
|
'address-book-add-button__button': true,
|
|
|
|
'address-book-add-button__button--hidden':
|
|
|
|
viewingContact || editingContact,
|
|
|
|
})}
|
2021-05-01 03:15:19 +02:00
|
|
|
type="secondary"
|
|
|
|
onClick={() => {
|
|
|
|
history.push(CONTACT_ADD_ROUTE);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{this.context.t('addContact')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderContactContent() {
|
|
|
|
const {
|
|
|
|
viewingContact,
|
|
|
|
editingContact,
|
|
|
|
addingContact,
|
|
|
|
showContactContent,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
if (!showContactContent) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return null;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let ContactContentComponent = null;
|
2019-07-31 21:56:44 +02:00
|
|
|
if (viewingContact) {
|
2021-02-04 19:15:23 +01:00
|
|
|
ContactContentComponent = ViewContact;
|
2019-07-31 21:56:44 +02:00
|
|
|
} else if (editingContact) {
|
2021-02-04 19:15:23 +01:00
|
|
|
ContactContentComponent = EditContact;
|
2019-07-31 21:56:44 +02:00
|
|
|
} else if (addingContact) {
|
2021-02-04 19:15:23 +01:00
|
|
|
ContactContentComponent = AddContact;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
return (
|
|
|
|
ContactContentComponent && (
|
|
|
|
<div className="address-book-contact-content">
|
|
|
|
<ContactContentComponent />
|
|
|
|
</div>
|
|
|
|
)
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderAddressBookContent() {
|
2021-04-27 20:25:58 +02:00
|
|
|
const { hideAddressBook } = this.props;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-27 20:25:58 +02:00
|
|
|
if (!hideAddressBook) {
|
2022-02-22 21:58:21 +01:00
|
|
|
return (
|
|
|
|
<div ref={this.settingsRefs[0]} className="address-book">
|
|
|
|
{this.renderAddresses()}
|
|
|
|
</div>
|
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
return null;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-05-01 03:15:19 +02:00
|
|
|
const { addingContact, addressBook } = this.props;
|
|
|
|
|
2019-07-31 21:56:44 +02:00
|
|
|
return (
|
|
|
|
<div className="address-book-wrapper">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderAddressBookContent()}
|
|
|
|
{this.renderContactContent()}
|
2021-10-21 18:11:31 +02:00
|
|
|
{!addingContact && addressBook.length > 0
|
|
|
|
? this.renderAddButton()
|
|
|
|
: null}
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
}
|