Skip to content

Commit

Permalink
List contact accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Sep 6, 2023
1 parent a149db5 commit f6f01b0
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { useContext, useState } from 'react'
import { useDispatch } from 'react-redux'
import { useTranslation } from 'react-i18next'
import { Box } from 'grommet/es6/components/Box'
import { ResponsiveContext } from 'grommet/es6/contexts/ResponsiveContext'
import { Tabs } from 'grommet/es6/components/Tabs'
import { Tab } from 'grommet/es6/components/Tab'
import { contactsActions } from 'app/state/contacts'
import { Contact } from 'app/state/contacts/types'
import { Account } from '../Account/Account'
import { ResponsiveLayer } from '../../../ResponsiveLayer'
import { ContactAccountForm } from './ContactAccountForm'

interface ContactAccountProps {
contact: Contact
}

export const ContactAccount = ({ contact }: ContactAccountProps) => {
const { t } = useTranslation()
const [layerVisibility, setLayerVisibility] = useState(false)
const isMobile = useContext(ResponsiveContext) === 'small'
const dispatch = useDispatch()
const submitHandler = (contact: Contact) => dispatch(contactsActions.update(contact))

Check warning on line 23 in src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx#L19-L23

Added lines #L19 - L23 were not covered by tests

return (

Check warning on line 25 in src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx#L25

Added line #L25 was not covered by tests
<Box>
<Account
address={contact.address}
balance={undefined}
displayBalance={false}
displayManageButton={{
onClickManage: () => setLayerVisibility(true),

Check warning on line 32 in src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx#L32

Added line #L32 was not covered by tests
}}
isActive={false}
key={contact.address}
name={contact.name}
onClick={() => setLayerVisibility(true)}

Check warning on line 37 in src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx#L37

Added line #L37 was not covered by tests
/>
{layerVisibility && (
<ResponsiveLayer
onClickOutside={() => setLayerVisibility(false)}
onEsc={() => setLayerVisibility(false)}

Check warning on line 42 in src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx#L39-L42

Added lines #L39 - L42 were not covered by tests
animation="none"
background="background-front"
modal
position="top"
margin={isMobile ? 'none' : 'xlarge'}

Check warning on line 47 in src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx#L47

Added line #L47 was not covered by tests
>
<Box margin="medium" width={isMobile ? 'auto' : '700px'}>

Check warning on line 49 in src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/ContactAccount.tsx#L49

Added line #L49 was not covered by tests
<Tabs alignControls="start">
<Tab title={t('toolbar.contacts.manage', 'Manage Contact')}>
<Box
gap="small"
pad={{ vertical: 'medium', right: 'small' }}
overflow={{ vertical: 'auto' }}
height="400px"
>
<ContactAccountForm
contact={contact}
setLayerVisibility={setLayerVisibility}
submitHandler={submitHandler}
/>
</Box>
</Tab>
</Tabs>
</Box>
</ResponsiveLayer>
)}
</Box>
)
}
6 changes: 6 additions & 0 deletions src/app/components/Toolbar/Features/Contacts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Box } from 'grommet/es6/components/Box'
import { Button } from 'grommet/es6/components/Button'
import { Inbox } from 'grommet-icons/es6/icons/Inbox'
import { selectContactsList } from 'app/state/contacts/selectors'
import { ContactAccount } from './ContactAccount'
import { AddContact } from './AddContact'

const ContactsListEmptyState = () => {
Expand Down Expand Up @@ -35,6 +36,11 @@ export const Contacts = () => {
<ContactsListEmptyState />
</Box>
)}
{!!contacts.length && (
<Box flex="grow" gap="small">
{contacts?.map(contact => <ContactAccount key={contact.address} contact={contact} />)}

Check warning on line 41 in src/app/components/Toolbar/Features/Contacts/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/index.tsx#L39-L41

Added lines #L39 - L41 were not covered by tests
</Box>
)}
<Box align="center">
<Button
primary
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@
"addContact": "Add Contact",
"address": "Address",
"cancel": "Cancel",
"manage": "Manage Contact",
"name": "Name",
"save": "Save",
"validation": {
Expand Down

0 comments on commit f6f01b0

Please sign in to comment.