2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
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';
|
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
|
|
|
|
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-05-25 02:20:09 +02:00
|
|
|
<img src="./images/address-book.svg" alt="Address book icon" />
|
2021-04-27 20:25:58 +02:00
|
|
|
<h4 className="address-book__title">{t('builContactList')}</h4>
|
|
|
|
<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() {
|
|
|
|
const { history } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="address-book-add-button">
|
|
|
|
<Button
|
|
|
|
className="address-book-add-button__button"
|
|
|
|
type="secondary"
|
|
|
|
rounded
|
|
|
|
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) {
|
|
|
|
return <div 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-05-01 03:15:19 +02:00
|
|
|
{!addingContact && addressBook.length > 0 && this.renderAddButton()}
|
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
|
|
|
}
|
|
|
|
}
|