cozy-ui 62.11.0 → 64.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/CODEOWNERS +2 -0
- package/package.json +5 -6
- package/react/ActionMenu/index.jsx +2 -1
- package/react/BottomSheet/BottomSheet.jsx +53 -45
- package/react/ContactsListModal/AddContact/AddContactActions.jsx +15 -0
- package/react/ContactsListModal/AddContact/AddContactContent.jsx +52 -0
- package/react/ContactsListModal/AddContact/AddContactDialog.jsx +38 -0
- package/react/ContactsListModal/AddContact/AddContactTitle.jsx +9 -0
- package/react/ContactsListModal/AddContact/helpers.js +18 -0
- package/react/ContactsListModal/AddContact/helpers.spec.js +74 -0
- package/react/ContactsListModal/AddContact/styles.styl +2 -0
- package/react/ContactsListModal/ContactsListContent.jsx +69 -0
- package/react/ContactsListModal/DemoProvider.jsx +2 -0
- package/react/ContactsListModal/MobileHeader.jsx +40 -0
- package/react/ContactsListModal/index.jsx +60 -124
- package/react/ContactsListModal/locales/en.json +8 -0
- package/react/ContactsListModal/locales/fr.json +8 -0
- package/react/ContactsListModal/withContactsListLocales.jsx +11 -0
- package/react/Dialog/index.jsx +7 -3
- package/react/SelectionBar/index.jsx +8 -4
- package/react/Sidebar/index.jsx +2 -1
- package/react/Viewer/Footer/FooterContent.jsx +6 -3
- package/react/Viewer/Footer/ForwardButton.jsx +28 -70
- package/react/Viewer/Footer/ForwardButton.spec.jsx +83 -0
- package/react/Viewer/Footer/helpers.js +75 -0
- package/react/Viewer/Footer/helpers.spec.js +77 -0
- package/react/Viewer/Viewer.jsx +131 -0
- package/react/Viewer/ViewerContainer.jsx +88 -0
- package/react/Viewer/ViewerInformationsWrapper.jsx +61 -0
- package/react/Viewer/ViewerWithCustomPanelAndFooter.jsx +52 -0
- package/react/Viewer/index.jsx +8 -310
- package/react/Viewer/locales/en.json +3 -0
- package/react/Viewer/locales/fr.json +3 -0
- package/react/Viewer/proptypes.js +9 -0
- package/react/__snapshots__/examples.spec.jsx.snap +0 -11
- package/react/examples.spec.jsx +0 -1
- package/react/hooks/useSetFlagshipUi/useSetFlagshipUI.spec.ts +122 -31
- package/react/hooks/useSetFlagshipUi/useSetFlagshipUI.ts +7 -5
- package/transpiled/react/ActionMenu/index.js +1 -1
- package/transpiled/react/BottomSheet/BottomSheet.js +16 -6
- package/transpiled/react/ContactsListModal/AddContact/AddContactActions.js +19 -0
- package/transpiled/react/ContactsListModal/AddContact/AddContactContent.js +58 -0
- package/transpiled/react/ContactsListModal/AddContact/AddContactDialog.js +42 -0
- package/transpiled/react/ContactsListModal/AddContact/AddContactTitle.js +9 -0
- package/transpiled/react/ContactsListModal/AddContact/helpers.js +48 -0
- package/transpiled/react/ContactsListModal/ContactsListContent.js +64 -0
- package/transpiled/react/ContactsListModal/DemoProvider.js +6 -0
- package/transpiled/react/ContactsListModal/MobileHeader.js +40 -0
- package/transpiled/react/ContactsListModal/index.js +65 -109
- package/transpiled/react/ContactsListModal/withContactsListLocales.js +22 -0
- package/transpiled/react/Dialog/index.js +4 -3
- package/transpiled/react/SelectionBar/index.js +1 -1
- package/transpiled/react/Sidebar/index.js +1 -1
- package/transpiled/react/Viewer/Footer/FooterContent.js +4 -3
- package/transpiled/react/Viewer/Footer/ForwardButton.js +66 -133
- package/transpiled/react/Viewer/Footer/helpers.js +124 -0
- package/transpiled/react/Viewer/Viewer.js +169 -0
- package/transpiled/react/Viewer/ViewerContainer.js +99 -0
- package/transpiled/react/Viewer/ViewerInformationsWrapper.js +41 -0
- package/transpiled/react/Viewer/ViewerWithCustomPanelAndFooter.js +48 -0
- package/transpiled/react/Viewer/index.js +5 -337
- package/transpiled/react/Viewer/proptypes.js +9 -0
- package/transpiled/react/Viewer/withViewerLocales.js +6 -0
- package/transpiled/react/hooks/useSetFlagshipUi/useSetFlagshipUI.js +5 -5
- package/transpiled/react/stylesheet.css +1 -1
- package/react/ContactsListModal/AddContactButton.jsx +0 -72
- package/transpiled/react/ContactsListModal/AddContactButton.js +0 -67
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
+
# [64.0.0](https://github.com/cozy/cozy-ui/compare/v63.0.0...v64.0.0) (2022-04-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Add AddContactDialog to add a contact from the contact list ([7333bf9](https://github.com/cozy/cozy-ui/commit/7333bf9))
|
|
7
|
+
* Add ContactsList locales and HOC to get them ([e315f40](https://github.com/cozy/cozy-ui/commit/e315f40))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### BREAKING CHANGES
|
|
11
|
+
|
|
12
|
+
* the app must now have `POST` permission on `io.cozy.contacts` doctype to use `ContactsListModal`
|
|
13
|
+
|
|
14
|
+
# [63.0.0](https://github.com/cozy/cozy-ui/compare/v62.12.0...v63.0.0) (2022-04-26)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **Viewer:** Improve ForwardButton ([2195cb4](https://github.com/cozy/cozy-ui/commit/2195cb4))
|
|
20
|
+
* Update cozy-client ([45a4a48](https://github.com/cozy/cozy-ui/commit/45a4a48))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### BREAKING CHANGES
|
|
24
|
+
|
|
25
|
+
* You need to update `cozy-client` to `>28.1.0`.
|
|
26
|
+
|
|
27
|
+
# [62.12.0](https://github.com/cozy/cozy-ui/compare/v62.11.0...v62.12.0) (2022-04-26)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Bug Fixes
|
|
31
|
+
|
|
32
|
+
* Hide bottom of screen in immersive mode ([65fcc5f](https://github.com/cozy/cozy-ui/commit/65fcc5f))
|
|
33
|
+
* Revert icons to white in immersive mode ([43bc925](https://github.com/cozy/cozy-ui/commit/43bc925))
|
|
34
|
+
* Upgrade cozy-intent and cozy-device-helper ([44904b4](https://github.com/cozy/cozy-ui/commit/44904b4))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
* Use new caller API in components ([10742b0](https://github.com/cozy/cozy-ui/commit/10742b0))
|
|
40
|
+
|
|
1
41
|
# [62.11.0](https://github.com/cozy/cozy-ui/compare/v62.10.0...v62.11.0) (2022-04-22)
|
|
2
42
|
|
|
3
43
|
|
package/CODEOWNERS
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "64.0.0",
|
|
4
4
|
"description": "Cozy apps UI SDK",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"prebuild:css:kss": "mkdir -p build/styleguide && stylus -C node_modules/normalize.css/normalize.css node_modules/normalize.css/normalize.styl",
|
|
44
44
|
"prebuild:doc:kss": "run-s clean:doc:kss build:css:kss",
|
|
45
45
|
"prepare": "yarn release",
|
|
46
|
-
"prepush": "[[ $(git rev-parse --abbrev-ref HEAD) != 'gh-pages' ]] && yarn lint || true",
|
|
47
46
|
"release": "npm-run-all --parallel sprite palette && yarn build",
|
|
48
47
|
"semantic-release": "semantic-release",
|
|
49
48
|
"sprite": "scripts/make-icon-sprite.sh",
|
|
@@ -91,11 +90,11 @@
|
|
|
91
90
|
"commitlint": "7.6.1",
|
|
92
91
|
"commitlint-config-cozy": "0.6.0",
|
|
93
92
|
"copyfiles": "2.4.1",
|
|
94
|
-
"cozy-client": "
|
|
95
|
-
"cozy-device-helper": "
|
|
93
|
+
"cozy-client": "28.1.0",
|
|
94
|
+
"cozy-device-helper": "1.18.0",
|
|
96
95
|
"cozy-doctypes": "^1.69.0",
|
|
97
96
|
"cozy-harvest-lib": "^6.7.3",
|
|
98
|
-
"cozy-intent": "1.
|
|
97
|
+
"cozy-intent": "1.16.1",
|
|
99
98
|
"cozy-sharing": "^3.10.0",
|
|
100
99
|
"cozy-stack-client": "27.19.1",
|
|
101
100
|
"css-loader": "0.28.11",
|
|
@@ -176,7 +175,7 @@
|
|
|
176
175
|
},
|
|
177
176
|
"peerDependencies": {
|
|
178
177
|
"@material-ui/core": ">=4.12",
|
|
179
|
-
"cozy-client": ">=
|
|
178
|
+
"cozy-client": ">=28.1.0",
|
|
180
179
|
"cozy-device-helper": "^1.16.0",
|
|
181
180
|
"cozy-doctypes": "^1.69.0",
|
|
182
181
|
"cozy-harvest-lib": "^6.7.3",
|
|
@@ -2,6 +2,8 @@ import React, { useState, useEffect, useRef, useMemo } from 'react'
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import { BottomSheet as MuiBottomSheet } from 'mui-bottom-sheet'
|
|
4
4
|
|
|
5
|
+
import { flagshipMetadata } from 'cozy-device-helper'
|
|
6
|
+
|
|
5
7
|
import Stack from 'cozy-ui/transpiled/react/Stack'
|
|
6
8
|
import Paper from 'cozy-ui/transpiled/react/Paper'
|
|
7
9
|
|
|
@@ -27,6 +29,15 @@ const makeStyles = ({ isTopPosition }) => ({
|
|
|
27
29
|
},
|
|
28
30
|
stack: {
|
|
29
31
|
backgroundColor: 'var(--defaultBackgroundColor)'
|
|
32
|
+
},
|
|
33
|
+
flagshipImmersive: {
|
|
34
|
+
backgroundColor: 'var(--paperBackgroundColor)',
|
|
35
|
+
bottom: 0,
|
|
36
|
+
content: '',
|
|
37
|
+
height: 'var(--flagship-bottom-height)',
|
|
38
|
+
position: 'fixed',
|
|
39
|
+
width: '100%',
|
|
40
|
+
zIndex: 'var(--zIndex-modal)'
|
|
30
41
|
}
|
|
31
42
|
})
|
|
32
43
|
|
|
@@ -97,18 +108,11 @@ const BottomSheet = ({ toolbarProps, settings, children }) => {
|
|
|
97
108
|
)
|
|
98
109
|
: 0
|
|
99
110
|
|
|
100
|
-
// Will return 0 if the variable is not set
|
|
101
|
-
const flagshipBottomOffset = Number(
|
|
102
|
-
getComputedStyle(document.body)
|
|
103
|
-
.getPropertyValue('--flagship-bottom-height')
|
|
104
|
-
.replace('px', '')
|
|
105
|
-
)
|
|
106
|
-
|
|
107
111
|
const minHeight =
|
|
108
112
|
headerRef.current.offsetHeight +
|
|
109
113
|
actionButtonsHeight +
|
|
110
114
|
actionButtonsBottomMargin +
|
|
111
|
-
|
|
115
|
+
(flagshipMetadata.navbarHeight || 0)
|
|
112
116
|
|
|
113
117
|
// Used so that the bottomSheet can be opened to the top,
|
|
114
118
|
// without stopping at the content height
|
|
@@ -149,43 +153,47 @@ const BottomSheet = ({ toolbarProps, settings, children }) => {
|
|
|
149
153
|
})
|
|
150
154
|
|
|
151
155
|
return (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
156
|
+
<>
|
|
157
|
+
{flagshipMetadata.immersive && <span style={styles.flagshipImmersive} />}
|
|
158
|
+
|
|
159
|
+
<MuiBottomSheet
|
|
160
|
+
peekHeights={peekHeights}
|
|
161
|
+
defaultHeight={initPos}
|
|
162
|
+
backdrop={false}
|
|
163
|
+
fullHeight={false}
|
|
164
|
+
onIndexChange={snapIndex => handleOnIndexChange(snapIndex)}
|
|
165
|
+
styles={{ root: styles.root }}
|
|
166
|
+
threshold={0}
|
|
167
|
+
// springConfig doc : https://docs.pmnd.rs/react-spring/common/configs
|
|
168
|
+
springConfig={{
|
|
169
|
+
tension: defaultBottomSheetSpringConfig.tension,
|
|
170
|
+
friction: defaultBottomSheetSpringConfig.friction,
|
|
171
|
+
clamp: defaultBottomSheetSpringConfig.clamp
|
|
172
|
+
}}
|
|
173
|
+
disabledClosing={true}
|
|
174
|
+
snapPointSeekerMode="next"
|
|
175
|
+
>
|
|
176
|
+
<div ref={innerContentRef}>
|
|
177
|
+
<Paper
|
|
178
|
+
data-testid="bottomSheet-header"
|
|
179
|
+
className="u-w-100 u-h-2-half u-pos-relative u-flex u-flex-items-center u-flex-justify-center"
|
|
180
|
+
ref={headerRef}
|
|
181
|
+
elevation={0}
|
|
182
|
+
square
|
|
183
|
+
>
|
|
184
|
+
<div style={styles.indicator} />
|
|
185
|
+
</Paper>
|
|
186
|
+
<Stack
|
|
187
|
+
style={styles.stack}
|
|
188
|
+
className="u-flex u-flex-column u-ov-hidden"
|
|
189
|
+
spacing="s"
|
|
190
|
+
>
|
|
191
|
+
{overriddenChildren}
|
|
192
|
+
</Stack>
|
|
193
|
+
</div>
|
|
194
|
+
<div style={{ height: bottomSpacerHeight }} />
|
|
195
|
+
</MuiBottomSheet>
|
|
196
|
+
</>
|
|
189
197
|
)
|
|
190
198
|
}
|
|
191
199
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import Button from '../../Buttons'
|
|
4
|
+
import { withContactsListLocales } from '../withContactsListLocales'
|
|
5
|
+
|
|
6
|
+
const AddContactActions = ({ t, onCancel, onSave }) => {
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
<Button variant="secondary" label={t('cancel')} onClick={onCancel} />
|
|
10
|
+
<Button label={t('save')} onClick={onSave} />
|
|
11
|
+
</>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default withContactsListLocales(AddContactActions)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Typography } from '@material-ui/core'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { Media, Img, Bd } from '../../Media'
|
|
5
|
+
import Icon from '../../Icon'
|
|
6
|
+
import PeopleIcon from 'cozy-ui/transpiled/react/Icons/People'
|
|
7
|
+
import TextField from '../../MuiCozyTheme/TextField'
|
|
8
|
+
|
|
9
|
+
import { withContactsListLocales } from '../withContactsListLocales'
|
|
10
|
+
import styles from './styles.styl'
|
|
11
|
+
|
|
12
|
+
const AddContactContent = ({ t, setContactValues }) => {
|
|
13
|
+
const handleChange = ev => {
|
|
14
|
+
const { name, value } = ev.target
|
|
15
|
+
setContactValues(v => ({ ...v, [name]: value }))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
<Typography variant="h5">{t('coordinates')}</Typography>
|
|
21
|
+
<Media>
|
|
22
|
+
<Img className={styles.icon}>
|
|
23
|
+
<Icon icon={PeopleIcon} />
|
|
24
|
+
</Img>
|
|
25
|
+
<Bd className="u-mr-1">
|
|
26
|
+
<TextField
|
|
27
|
+
className="u-mt-1"
|
|
28
|
+
variant="outlined"
|
|
29
|
+
fullWidth={true}
|
|
30
|
+
name="givenName"
|
|
31
|
+
label={t('givenName')}
|
|
32
|
+
onChange={handleChange}
|
|
33
|
+
/>
|
|
34
|
+
</Bd>
|
|
35
|
+
</Media>
|
|
36
|
+
<Media>
|
|
37
|
+
<Bd className="u-ml-3 u-mr-1">
|
|
38
|
+
<TextField
|
|
39
|
+
className="u-mt-1"
|
|
40
|
+
variant="outlined"
|
|
41
|
+
fullWidth={true}
|
|
42
|
+
name="familyName"
|
|
43
|
+
label={t('familyName')}
|
|
44
|
+
onChange={handleChange}
|
|
45
|
+
/>
|
|
46
|
+
</Bd>
|
|
47
|
+
</Media>
|
|
48
|
+
</>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default withContactsListLocales(AddContactContent)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { useClient } from 'cozy-client'
|
|
4
|
+
|
|
5
|
+
import { FixedDialog } from '../../CozyDialogs'
|
|
6
|
+
import AddContactTitle from './AddContactTitle'
|
|
7
|
+
import AddContactContent from './AddContactContent'
|
|
8
|
+
import AddContactActions from './AddContactActions'
|
|
9
|
+
import { handleSubmit } from './helpers'
|
|
10
|
+
|
|
11
|
+
const AddContactDialog = ({ onListClose, onCreate, onClose }) => {
|
|
12
|
+
const [contactValues, setContactValues] = useState({})
|
|
13
|
+
const client = useClient()
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<FixedDialog
|
|
17
|
+
open={true}
|
|
18
|
+
onClose={onClose}
|
|
19
|
+
title={<AddContactTitle />}
|
|
20
|
+
content={<AddContactContent setContactValues={setContactValues} />}
|
|
21
|
+
actions={
|
|
22
|
+
<AddContactActions
|
|
23
|
+
onCancel={onClose}
|
|
24
|
+
onSave={() =>
|
|
25
|
+
handleSubmit({
|
|
26
|
+
client,
|
|
27
|
+
contactValues,
|
|
28
|
+
onCreate,
|
|
29
|
+
onListClose
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
/>
|
|
33
|
+
}
|
|
34
|
+
/>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default AddContactDialog
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const handleSubmit = async ({
|
|
2
|
+
client,
|
|
3
|
+
contactValues,
|
|
4
|
+
onCreate,
|
|
5
|
+
onListClose
|
|
6
|
+
}) => {
|
|
7
|
+
const { givenName, familyName } = contactValues
|
|
8
|
+
|
|
9
|
+
if (!givenName && !familyName) return
|
|
10
|
+
|
|
11
|
+
const { data: contact } = await client.save({
|
|
12
|
+
_type: 'io.cozy.contacts',
|
|
13
|
+
name: { familyName, givenName }
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
onCreate(contact)
|
|
17
|
+
onListClose()
|
|
18
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createMockClient } from 'cozy-client'
|
|
2
|
+
|
|
3
|
+
import { handleSubmit } from './helpers'
|
|
4
|
+
|
|
5
|
+
const client = createMockClient({})
|
|
6
|
+
client.save = jest.fn(x => ({ data: x }))
|
|
7
|
+
const onCreate = jest.fn()
|
|
8
|
+
const onListClose = jest.fn()
|
|
9
|
+
|
|
10
|
+
describe('handleSubmit', () => {
|
|
11
|
+
it('should not create the contact if no givenName of familyName', async () => {
|
|
12
|
+
await handleSubmit({ contactValues: {}, client, onCreate, onListClose })
|
|
13
|
+
|
|
14
|
+
expect(onCreate).not.toHaveBeenCalled()
|
|
15
|
+
expect(onListClose).not.toHaveBeenCalled()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('should create the contact if there is only the givenName', async () => {
|
|
19
|
+
await handleSubmit({
|
|
20
|
+
contactValues: { givenName: 'John' },
|
|
21
|
+
client,
|
|
22
|
+
onCreate,
|
|
23
|
+
onListClose
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
expect(client.save).toHaveBeenCalled()
|
|
27
|
+
expect(onCreate).toHaveBeenCalledWith({
|
|
28
|
+
_type: 'io.cozy.contacts',
|
|
29
|
+
name: {
|
|
30
|
+
familyName: undefined,
|
|
31
|
+
givenName: 'John'
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
expect(onListClose).toHaveBeenCalled()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should create the contact if there is only the familyName', async () => {
|
|
38
|
+
await handleSubmit({
|
|
39
|
+
contactValues: { familyName: 'Connor' },
|
|
40
|
+
client,
|
|
41
|
+
onCreate,
|
|
42
|
+
onListClose
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
expect(client.save).toHaveBeenCalled()
|
|
46
|
+
expect(onCreate).toHaveBeenCalledWith({
|
|
47
|
+
_type: 'io.cozy.contacts',
|
|
48
|
+
name: {
|
|
49
|
+
familyName: 'Connor',
|
|
50
|
+
givenName: undefined
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
expect(onListClose).toHaveBeenCalled()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('should create the contact if there is the givenName and familyName', async () => {
|
|
57
|
+
await handleSubmit({
|
|
58
|
+
contactValues: { givenName: 'John', familyName: 'Connor' },
|
|
59
|
+
client,
|
|
60
|
+
onCreate,
|
|
61
|
+
onListClose
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
expect(client.save).toHaveBeenCalled()
|
|
65
|
+
expect(onCreate).toHaveBeenCalledWith({
|
|
66
|
+
_type: 'io.cozy.contacts',
|
|
67
|
+
name: {
|
|
68
|
+
familyName: 'Connor',
|
|
69
|
+
givenName: 'John'
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
expect(onListClose).toHaveBeenCalled()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { Contact } from 'cozy-doctypes'
|
|
4
|
+
|
|
5
|
+
import ContactsList from '../ContactsList'
|
|
6
|
+
import Spinner from '../Spinner'
|
|
7
|
+
import EmptyMessage from './EmptyMessage'
|
|
8
|
+
|
|
9
|
+
const mkFilter = filterStr => contacts => {
|
|
10
|
+
if (!filterStr) {
|
|
11
|
+
return contacts
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const f = filterStr.toLowerCase()
|
|
15
|
+
|
|
16
|
+
// TODO better filtering methods can be extracted from drive. See https://github.com/cozy/cozy-ui/pull/1273#discussion_r351845385
|
|
17
|
+
return contacts.filter(contact => {
|
|
18
|
+
const displayName = Contact.getDisplayName(contact)
|
|
19
|
+
|
|
20
|
+
if (!displayName) {
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return displayName.toLowerCase().includes(f)
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ContactsListContent = ({
|
|
29
|
+
filter,
|
|
30
|
+
contacts,
|
|
31
|
+
emptyMessage,
|
|
32
|
+
onItemClick,
|
|
33
|
+
dismissAction
|
|
34
|
+
}) => {
|
|
35
|
+
const loading =
|
|
36
|
+
(contacts.fetchStatus === 'loading' ||
|
|
37
|
+
contacts.fetchStatus === 'pending') &&
|
|
38
|
+
!contacts.lastFetch
|
|
39
|
+
|
|
40
|
+
const filterContacts = mkFilter(filter)
|
|
41
|
+
const filteredContacts = filterContacts(contacts.data)
|
|
42
|
+
|
|
43
|
+
const handleItemClick = contact => {
|
|
44
|
+
if (!onItemClick) {
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
onItemClick(contact)
|
|
49
|
+
dismissAction()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (loading) {
|
|
53
|
+
return (
|
|
54
|
+
<div className="u-mv-2">
|
|
55
|
+
<Spinner size="xxlarge" />
|
|
56
|
+
</div>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (filteredContacts.length === 0) {
|
|
61
|
+
return <EmptyMessage>{emptyMessage}</EmptyMessage>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<ContactsList contacts={filteredContacts} onItemClick={handleItemClick} />
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default ContactsListContent
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import CozyTheme from '../CozyTheme'
|
|
4
|
+
import Icon from '../Icon'
|
|
5
|
+
import PreviousIcon from '../Icons/Previous'
|
|
6
|
+
import Paper from '../Paper'
|
|
7
|
+
import IconButton from '@material-ui/core/IconButton'
|
|
8
|
+
import Input from '@material-ui/core/Input'
|
|
9
|
+
|
|
10
|
+
const barStyle = {
|
|
11
|
+
height: 48
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const MobileHeader = ({ filter, placeholder, onChange, onDismiss }) => {
|
|
15
|
+
return (
|
|
16
|
+
<CozyTheme variant="inverted">
|
|
17
|
+
<Paper
|
|
18
|
+
square
|
|
19
|
+
elevation={0}
|
|
20
|
+
className="u-flex u-flex-items-center u-pr-3 u-pl-half"
|
|
21
|
+
style={barStyle}
|
|
22
|
+
>
|
|
23
|
+
<IconButton className="u-mr-half" onClick={onDismiss}>
|
|
24
|
+
<Icon icon={PreviousIcon} />
|
|
25
|
+
</IconButton>
|
|
26
|
+
<Input
|
|
27
|
+
type="text"
|
|
28
|
+
placeholder={placeholder}
|
|
29
|
+
value={filter}
|
|
30
|
+
onChange={onChange}
|
|
31
|
+
autoFocus
|
|
32
|
+
fullWidth
|
|
33
|
+
disableUnderline
|
|
34
|
+
/>
|
|
35
|
+
</Paper>
|
|
36
|
+
</CozyTheme>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default MobileHeader
|