You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.0 KiB
117 lines
3.0 KiB
4 years ago
|
import React, { Component } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import ContactList from '../../../components/app/contact-list';
|
||
5 years ago
|
import {
|
||
|
CONTACT_ADD_ROUTE,
|
||
|
CONTACT_VIEW_ROUTE,
|
||
4 years ago
|
} from '../../../helpers/constants/routes';
|
||
|
import EditContact from './edit-contact';
|
||
|
import AddContact from './add-contact';
|
||
|
import ViewContact from './view-contact';
|
||
5 years ago
|
|
||
|
export default class ContactListTab extends Component {
|
||
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
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,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
renderAddresses() {
|
||
4 years ago
|
const { addressBook, history, selectedAddress } = this.props;
|
||
|
const contacts = addressBook.filter(({ name }) => Boolean(name));
|
||
|
const nonContacts = addressBook.filter(({ name }) => !name);
|
||
|
const { t } = this.context;
|
||
4 years ago
|
|
||
|
if (addressBook.length) {
|
||
|
return (
|
||
|
<div>
|
||
|
<ContactList
|
||
|
searchForContacts={() => contacts}
|
||
|
searchForRecents={() => nonContacts}
|
||
|
selectRecipient={(address) => {
|
||
|
history.push(`${CONTACT_VIEW_ROUTE}/${address}`);
|
||
|
}}
|
||
|
selectedAddress={selectedAddress}
|
||
|
/>
|
||
4 years ago
|
</div>
|
||
4 years ago
|
);
|
||
|
}
|
||
|
return (
|
||
|
<div className="address-book__container">
|
||
|
<div>
|
||
|
<img src="/images/address-book.svg" alt="Address book icon" />
|
||
|
<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>
|
||
5 years ago
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
renderContactContent() {
|
||
|
const {
|
||
|
viewingContact,
|
||
|
editingContact,
|
||
|
addingContact,
|
||
|
showContactContent,
|
||
4 years ago
|
} = this.props;
|
||
5 years ago
|
|
||
|
if (!showContactContent) {
|
||
4 years ago
|
return null;
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
let ContactContentComponent = null;
|
||
5 years ago
|
if (viewingContact) {
|
||
4 years ago
|
ContactContentComponent = ViewContact;
|
||
5 years ago
|
} else if (editingContact) {
|
||
4 years ago
|
ContactContentComponent = EditContact;
|
||
5 years ago
|
} else if (addingContact) {
|
||
4 years ago
|
ContactContentComponent = AddContact;
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
return (
|
||
|
ContactContentComponent && (
|
||
|
<div className="address-book-contact-content">
|
||
|
<ContactContentComponent />
|
||
|
</div>
|
||
|
)
|
||
4 years ago
|
);
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
renderAddressBookContent() {
|
||
4 years ago
|
const { hideAddressBook } = this.props;
|
||
5 years ago
|
|
||
4 years ago
|
if (!hideAddressBook) {
|
||
|
return <div className="address-book">{this.renderAddresses()}</div>;
|
||
5 years ago
|
}
|
||
4 years ago
|
return null;
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
render() {
|
||
5 years ago
|
return (
|
||
|
<div className="address-book-wrapper">
|
||
4 years ago
|
{this.renderAddressBookContent()}
|
||
|
{this.renderContactContent()}
|
||
5 years ago
|
</div>
|
||
4 years ago
|
);
|
||
5 years ago
|
}
|
||
|
}
|