From 0cff7e0e963b0940d771f2a4980ea21fd100a96b Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Thu, 23 Jul 2020 12:56:57 +0200 Subject: [PATCH 01/12] refactor: Use list instead of object for ordered data --- package.json | 6 ++-- src/ducks/transfers/TransferPage.jsx | 19 ++++++------ yarn.lock | 43 ++++++++++++++++------------ 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 1d95e24395..81f354691d 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,7 @@ "cozy-authentication": "2.1.0", "cozy-bar": "7.13.3", "cozy-ci": "0.4.1", - "cozy-client": "13.15.1", + "cozy-client": "13.16.0", "cozy-client-js": "0.16.4", "cozy-device-helper": "1.9.2", "cozy-doctypes": "1.69.0", @@ -170,10 +170,10 @@ "cozy-konnector-libs": "4.30.3-beta.1", "cozy-logger": "1.6.0", "cozy-notifications": "0.5.0", - "cozy-pouch-link": "13.15.1", + "cozy-pouch-link": "13.16.0", "cozy-realtime": "3.9.0", "cozy-scripts": "4.1.0", - "cozy-stack-client": "13.8.3", + "cozy-stack-client": "13.16.0", "cozy-ui": "35.33.1", "d3": "5.11.0", "date-fns": "1.30.1", diff --git a/src/ducks/transfers/TransferPage.jsx b/src/ducks/transfers/TransferPage.jsx index ea78e3c423..dd9088fee8 100644 --- a/src/ducks/transfers/TransferPage.jsx +++ b/src/ducks/transfers/TransferPage.jsx @@ -34,14 +34,14 @@ import { isCollectionLoading, hasBeenLoaded } from 'ducks/client/utils' const THIRTY_SECONDS = 30 * 1000 -const slideIndexes = { - category: 0, - beneficiary: 1, - sender: 2, - amount: 3, - summary: 4, - password: 5 -} +const slideIndexes = [ + 'category', + 'beneficiary', + 'sender', + 'amount', + 'summary', + 'password' +] const subscribe = (rt, event, doc, id, cb) => { let handler @@ -304,7 +304,8 @@ class TransferPage extends React.Component { } selectSlideByName(slideName) { - this.setState({ slide: slideIndexes[slideName] || 0 }) + const idx = slideIndexes.findIndex(x => x == slideName) + this.setState({ slide: idx !== -1 ? idx : 0 }) this.props.router.push(slideName ? `/transfers/${slideName}` : '/transfers') } diff --git a/yarn.lock b/yarn.lock index 8434344de8..1c62a058ca 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5023,15 +5023,15 @@ cozy-client-js@^0.15.0: pouchdb-browser "7.0.0" pouchdb-find "7.0.0" -cozy-client@13.15.1, cozy-client@^13.15.1: - version "13.15.1" - resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-13.15.1.tgz#66f13066f653b5577468167a0c3e4fd64ccc7b06" - integrity sha512-CM202LvrxC+OBr8ZBwnqekfQDuwLfZmoiO/ScNvY3DMTivw4qH08s17co+cFHvcN9I+ty9LqTR9q/ZA4wdPnjg== +cozy-client@13.16.0, cozy-client@^13.16.0: + version "13.16.0" + resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-13.16.0.tgz#424727f3c735db9ab5e5750778c81cb98f59267a" + integrity sha512-zFvd5b6ZExNJkgdfzfpkpQW6JNnetKotiwPgh6XPLtSdu2cGa+HaOiv+63LEoQSZD0FfRNCh+4jB6mM2wMa8YA== dependencies: btoa "^1.2.1" cozy-device-helper "^1.7.3" cozy-logger "^1.6.0" - cozy-stack-client "^13.15.1" + cozy-stack-client "^13.16.0" isomorphic-fetch "^2.2.1" lodash "^4.17.13" microee "^0.0.6" @@ -5373,12 +5373,12 @@ cozy-notifications@0.5.0: mjml "4.3.1" word-wrap "^1.2.3" -cozy-pouch-link@13.15.1: - version "13.15.1" - resolved "https://registry.yarnpkg.com/cozy-pouch-link/-/cozy-pouch-link-13.15.1.tgz#d9d78e625ed4c5a52247f3662afb070a6bfa169e" - integrity sha512-A9zU3I73vOX+b2UVmZpLmI6jUZf+7IzycUFI09HvJtNPakFkoh8Ya5iWFraztxonBjW+EWVKn4pDtQDSOFAydA== +cozy-pouch-link@13.16.0: + version "13.16.0" + resolved "https://registry.yarnpkg.com/cozy-pouch-link/-/cozy-pouch-link-13.16.0.tgz#2b4601f2e619eb7f3537a8602c2ef32cde528ee0" + integrity sha512-dVOxpXjVcci/5kheVrQtrllD2YDTTLVvClCFg79mu9UjRiFn4qJGkjoHDzodNxSxFoQ53Ew6ZN0Nh99tdC0+fw== dependencies: - cozy-client "^13.15.1" + cozy-client "^13.16.0" cozy-device-helper "^1.7.3" minilog "^3.1.0" pouchdb-browser "^7.0.0" @@ -5451,19 +5451,19 @@ cozy-scripts@4.1.0: webpack-dev-server "3.10.3" webpack-merge "4.2.2" -cozy-stack-client@13.8.3, cozy-stack-client@^13.8.3: - version "13.8.3" - resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-13.8.3.tgz#7e87b18b853ae60b0df5bee1b78203d04e5ebc4a" - integrity sha512-ffSC6DVCi+LU8KP6dhV+A7u5aMeRtSvrhEGTdeZn1AbrS6cD11OZPOveCzMHYUXzuAwbov8sRLi0BF8cTENWfQ== +cozy-stack-client@13.16.0, cozy-stack-client@^13.16.0: + version "13.16.0" + resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-13.16.0.tgz#e4e7043df34132dc6c1578b030d823e994a7e210" + integrity sha512-pAzBsB5pFL0wyccquLK4Hgw5uayMhoAVKJOThU+u+vYFpnYlNEZQ+iY9eFFOpQa47dWy0vTkmI0N0wk5chN/2g== dependencies: detect-node "^2.0.4" mime "^2.4.0" qs "^6.7.0" -cozy-stack-client@^13.15.1: - version "13.15.1" - resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-13.15.1.tgz#6beb2703ab916c568b226ea5a572c0cba13d02df" - integrity sha512-ZNGphplNg98P2bFqIvYRHm7wJKpjTCVL5oed5GBKb4DDwW/CogVaYaiGfF8sfm/1AZqQWyRMfvZjLaIZtH1/QQ== +cozy-stack-client@^13.8.3: + version "13.8.3" + resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-13.8.3.tgz#7e87b18b853ae60b0df5bee1b78203d04e5ebc4a" + integrity sha512-ffSC6DVCi+LU8KP6dhV+A7u5aMeRtSvrhEGTdeZn1AbrS6cD11OZPOveCzMHYUXzuAwbov8sRLi0BF8cTENWfQ== dependencies: detect-node "^2.0.4" mime "^2.4.0" @@ -12448,6 +12448,13 @@ minilog@3.1.0, minilog@^3.1.0, "minilog@https://github.com/cozy/minilog.git#mast dependencies: microee "0.0.6" +"minilog@git+https://github.com/cozy/minilog.git#master": + version "3.1.0" + uid f01f7d9dfe20981177dd34b9662c2f077d818f82 + resolved "git+https://github.com/cozy/minilog.git#f01f7d9dfe20981177dd34b9662c2f077d818f82" + dependencies: + microee "0.0.6" + minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" From fe03d1189180ab418567f7cf47cd3e575422a134 Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Thu, 23 Jul 2020 13:43:03 +0200 Subject: [PATCH 02/12] feat: Add Form to edit myself contact --- src/doctypes.js | 5 + src/ducks/personal-info/Form.jsx | 118 ++ src/ducks/personal-info/Infos.jsx | 22 + src/ducks/personal-info/countries.json | 1745 ++++++++++++++++++++++++ src/ducks/personal-info/index.jsx | 76 ++ src/locales/en.json | 12 + src/locales/fr.json | 12 + 7 files changed, 1990 insertions(+) create mode 100644 src/ducks/personal-info/Form.jsx create mode 100644 src/ducks/personal-info/Infos.jsx create mode 100644 src/ducks/personal-info/countries.json create mode 100644 src/ducks/personal-info/index.jsx diff --git a/src/doctypes.js b/src/doctypes.js index 55a402d214..8fa6ce824c 100644 --- a/src/doctypes.js +++ b/src/doctypes.js @@ -234,3 +234,8 @@ export const recurrenceConn = { as: 'recurrence', fetchPolicy: older30s } + +export const myselfConn = { + query: () => Q('io.cozy.contacts').where({ me: true }), + as: 'myself' +} diff --git a/src/ducks/personal-info/Form.jsx b/src/ducks/personal-info/Form.jsx new file mode 100644 index 0000000000..eddf7244ad --- /dev/null +++ b/src/ducks/personal-info/Form.jsx @@ -0,0 +1,118 @@ +import React from 'react' +import { translate } from 'cozy-ui/transpiled/react/I18n' +import { withClient } from 'cozy-client' +import Button from 'cozy-ui/transpiled/react/Button' +import Field from 'cozy-ui/transpiled/react/Field' +import compose from 'lodash/flowRight' + +import countries from './countries.json' +import PersonalInfoInfos from 'ducks/personal-info/Infos' + +const defaultNationality = { label: 'French', value: 'FR' } + +const nationalities = countries.map(country => { + return { + label: country.nationality, + value: country.alpha_2_code + } +}) + +/** + * Displays a form to fill personal info into the myself contact. + */ +class PersonalInfoForm extends React.Component { + constructor(props, context) { + super(props, context) + this.handleChangeField = this.handleChangeField.bind(this) + this.handleSave = this.handleSave.bind(this) + + const myself = this.props.myself + + this.state = { + saving: false, + formData: { + birthcity: myself.birthcity, + nationality: + nationalities.find( + x => myself.nationality && x.value === myself.nationality + ) || defaultNationality + } + } + } + + render() { + const { t } = this.props + const { saving, formData } = this.state + + return ( + <> + this.handleChangeField('birthcity', ev.target.value)} + type="text" + name="birthcity" + label={t('PersonalInfo.birthcity')} + /> + this.handleChangeField('nationality', option)} + value={formData.nationality} + type="select" + name="nationality" + options={nationalities} + label={t('PersonalInfo.nationality')} + /> + +