Skip to content

Commit

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

interface AddContactProps {
setLayerVisibility: (isVisible: boolean) => void
}

export const AddContact = ({ setLayerVisibility }: AddContactProps) => {
const { t } = useTranslation()
const isMobile = useContext(ResponsiveContext) === 'small'
const dispatch = useDispatch()
const submitHandler = (contact: Contact) => dispatch(contactsActions.add(contact))

Check warning on line 21 in src/app/components/Toolbar/Features/Contacts/AddContact.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/AddContact.tsx#L18-L21

Added lines #L18 - L21 were not covered by tests

return (

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

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/AddContact.tsx#L23

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

Check warning on line 26 in src/app/components/Toolbar/Features/Contacts/AddContact.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/AddContact.tsx#L25-L26

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

Check warning on line 31 in src/app/components/Toolbar/Features/Contacts/AddContact.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/AddContact.tsx#L31

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

Check warning on line 33 in src/app/components/Toolbar/Features/Contacts/AddContact.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Contacts/AddContact.tsx#L33

Added line #L33 was not covered by tests
<Tabs alignControls="start">
<Tab title={t('toolbar.contacts.addContact', 'Add Contact')}>
<Box
gap="small"
pad={{ vertical: 'medium', right: 'small' }}
overflow={{ vertical: 'auto' }}
height="400px"
>
<ContactAccountForm setLayerVisibility={setLayerVisibility} submitHandler={submitHandler} />
</Box>
</Tab>
</Tabs>
</Box>
</ResponsiveLayer>
)
}
13 changes: 13 additions & 0 deletions src/app/components/Toolbar/Features/Contacts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useState } from 'react'
import { useSelector } from 'react-redux'
import { useTranslation } from 'react-i18next'
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 { AddContact } from './AddContact'

const ContactsListEmptyState = () => {
const { t } = useTranslation()

Check warning on line 11 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#L11

Added line #L11 was not covered by tests
Expand All @@ -16,6 +19,8 @@ const ContactsListEmptyState = () => {
}

export const Contacts = () => {
const { t } = useTranslation()
const [layerVisibility, setLayerVisibility] = useState(false)
const contacts = useSelector(selectContactsList)

Check warning on line 24 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#L22-L24

Added lines #L22 - L24 were not covered by tests

return (

Check warning on line 26 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#L26

Added line #L26 was not covered by tests
Expand All @@ -30,6 +35,14 @@ export const Contacts = () => {
<ContactsListEmptyState />
</Box>
)}
<Box align="center">
<Button
primary
label={t('toolbar.contacts.add', 'Add contact')}
onClick={() => setLayerVisibility(true)}

Check warning on line 42 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#L42

Added line #L42 was not covered by tests
/>
</Box>
{layerVisibility && <AddContact setLayerVisibility={setLayerVisibility} />}

Check warning on line 45 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#L45

Added line #L45 was not covered by tests
</Box>
)
}
2 changes: 2 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@
},
"toolbar": {
"contacts": {
"add": "Add contact",
"addContact": "Add Contact",
"address": "Address",
"cancel": "Cancel",
"name": "Name",
Expand Down

0 comments on commit a149db5

Please sign in to comment.