diff --git a/package-lock.json b/package-lock.json index b3654dcbe..db38328bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,21 @@ "@babel/types": "^7.0.0" } }, + "@babel/runtime": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.1.2.tgz", + "integrity": "sha512-Y3SCjmhSupzFB6wcv1KmmFucH6gDVnI30WjOcicV10ju0cZjak3Jcs67YLIXBrmZYw1xCrVeJPbycFwrqNyxpg==", + "requires": { + "regenerator-runtime": "^0.12.0" + }, + "dependencies": { + "regenerator-runtime": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz", + "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==" + } + } + }, "@babel/types": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.1.3.tgz", @@ -171,9 +186,9 @@ } }, "ajv": { - "version": "6.5.4", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.4.tgz", - "integrity": "sha512-4Wyjt8+t6YszqaXnLDfMmG/8AlO5Zbcsy3ATHncCzjW/NoPzAId8AK6749Ybjmdt+kUY1gP60fCu46oDxPv/mg==", + "version": "6.5.5", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.5.tgz", + "integrity": "sha512-7q7gtRQDJSyuEHjuVgHoUa2VuemFiCMrfQc9Tc08XTAc4Zj/5U1buQJ0HU6i7fKjXU09SVgSmxa4sLvuvS8Iyg==", "dev": true, "requires": { "fast-deep-equal": "^2.0.1", @@ -344,7 +359,7 @@ } }, "appirio-tech-react-components": { - "version": "github:appirio-tech/react-components#b3e6ad8e630e5d9f925326f4cb62278ea6215ffc", + "version": "github:appirio-tech/react-components#5a44ba8ba1fe304c1b0f71e5f8f0f127796b89cc", "from": "github:appirio-tech/react-components#feature/connectv2", "requires": { "appirio-tech-api-schemas": "^5.0.69", @@ -546,7 +561,7 @@ }, "util": { "version": "0.10.3", - "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", + "resolved": "http://registry.npmjs.org/util/-/util-0.10.3.tgz", "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", "dev": true, "requires": { @@ -1968,7 +1983,7 @@ }, "bignumber.js": { "version": "2.4.0", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-2.4.0.tgz", + "resolved": "http://registry.npmjs.org/bignumber.js/-/bignumber.js-2.4.0.tgz", "integrity": "sha1-g4qZLan51zfg9LLbC+YrsJ3Qxeg=", "dev": true }, @@ -2365,15 +2380,15 @@ } }, "caniuse-db": { - "version": "1.0.30000903", - "resolved": "https://registry.npmjs.org/caniuse-db/-/caniuse-db-1.0.30000903.tgz", - "integrity": "sha512-x3npiIhv0zDc5qAj+r4rByMETsz2XkukPFsVWzwyY5r5h63XoO8msj9D65BqeNt1aBn17fsBnDDP78yFM/OAqA==", + "version": "1.0.30000904", + "resolved": "https://registry.npmjs.org/caniuse-db/-/caniuse-db-1.0.30000904.tgz", + "integrity": "sha512-iZ36AxtEx7ZiCBKhF2qFL8ED6u9zJGPU7Aq6HwZQYUbetBgYkGZfoPHq9z38jahV2kr8BgDYfXvftA35Ng2AaA==", "dev": true }, "caniuse-lite": { - "version": "1.0.30000903", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000903.tgz", - "integrity": "sha512-T1XVJEpGCoaq7MDw7/6hCdYUukmSaS+1l/OQJkLtw7Cr2+/+d67tNGKEbyiqf7Ck8x6EhNFUxjYFXXka0N/w5g==", + "version": "1.0.30000904", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000904.tgz", + "integrity": "sha512-M4sXvogCoY5Fp6fuXIaQG/MIexlEFQ3Lgwban+KlqiQUbUIkSmjAB8ZJIP79aj2cdqz2F1Lb+Z+5GwHvCrbLtg==", "dev": true }, "caseless": { @@ -3729,7 +3744,7 @@ }, "d": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz", + "resolved": "http://registry.npmjs.org/d/-/d-1.0.0.tgz", "integrity": "sha1-dUu1v+VUUdpppYuU1F9MWwRi1Y8=", "requires": { "es5-ext": "^0.10.9" @@ -4063,9 +4078,12 @@ } }, "dom-helpers": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.3.1.tgz", - "integrity": "sha512-2Sm+JaYn74OiTM2wHvxJOo3roiq/h25Yi69Fqk269cNUwIXsCvATB6CRSFC9Am/20G2b28hGv/+7NiWydIrPvg==" + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.4.0.tgz", + "integrity": "sha512-LnuPJ+dwqKDIyotW1VzmOZ5TONUN7CwkCR5hrgawTUbkBGYdeoNLZo6nNfGkCrjtE1nXXaj7iMMpDa8/d9WoIA==", + "requires": { + "@babel/runtime": "^7.1.2" + } }, "dom-serializer": { "version": "0.1.0", @@ -4264,9 +4282,9 @@ "dev": true }, "electron-to-chromium": { - "version": "1.3.82", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.82.tgz", - "integrity": "sha512-NI4nB2IWGcU4JVT1AE8kBb/dFor4zjLHMLsOROPahppeHrR0FG5uslxMmkp/thO1MvPjM2xhlKoY29/I60s0ew==", + "version": "1.3.83", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.83.tgz", + "integrity": "sha512-DqJoDarxq50dcHsOOlMLNoy+qQitlMNbYb6wwbE0oUw2veHdRkpNrhmngiUYKMErdJ8SJ48rpJsZTQgy5SoEAA==", "dev": true }, "element-class": { @@ -4834,9 +4852,9 @@ } }, "eslint-plugin-jest": { - "version": "21.26.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-21.26.2.tgz", - "integrity": "sha512-SCTBC6q182D4qQlQAN81D351jdte/YwTMo4f+l19Gvh1VemaNZP7ak3MLLvw6xkL9dO2FxVjCLk5DCdl1KfdLw==", + "version": "21.27.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-21.27.1.tgz", + "integrity": "sha512-K+S4Wa20MoRRXICfnQBqjl2g9+ipJBeDUVrB3Csg4wOrxXMGcNxYuPRaiyA0pqmb/vO2cgaLEzurORfsLrztxg==", "dev": true }, "eslint-plugin-jsx-a11y": { @@ -6678,9 +6696,9 @@ } }, "graceful-fs": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", - "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + "version": "4.1.15", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==" }, "graceful-readlink": { "version": "1.0.1", @@ -8153,7 +8171,7 @@ }, "kew": { "version": "0.7.0", - "resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz", + "resolved": "http://registry.npmjs.org/kew/-/kew-0.7.0.tgz", "integrity": "sha1-edk9LTM2PW/dKXCzNdkUGtWR15s=", "dev": true }, @@ -9207,7 +9225,7 @@ }, "next-tick": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", + "resolved": "http://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=" }, "no-case": { @@ -9399,9 +9417,9 @@ } }, "node-sass": { - "version": "4.9.4", - "resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.9.4.tgz", - "integrity": "sha512-MXyurANsUoE4/6KmfMkwGcBzAnJQ5xJBGW7Ei6ea8KnUKuzHr/SguVBIi3uaUAHtZCPUYkvlJ3Ef5T5VAwVpaA==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.10.0.tgz", + "integrity": "sha512-fDQJfXszw6vek63Fe/ldkYXmRYK/QS6NbvM3i5oEo9ntPDy4XX7BcKZyTKv+/kSSxRtXXc7l+MSwEmYc0CSy6Q==", "dev": true, "requires": { "async-foreach": "^0.1.3", @@ -12760,9 +12778,9 @@ "dev": true }, "raf": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.0.tgz", - "integrity": "sha512-pDP/NMRAXoTfrhCfyfSEwJAKLaxBU9eApMeBPB1TkDouZmvPerIClV8lTAd+uF8ZiTaVl69e1FCxQrAd/VTjGw==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.1.tgz", + "integrity": "sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA==", "requires": { "performance-now": "^2.1.0" } @@ -13146,9 +13164,9 @@ } }, "react-hot-loader": { - "version": "4.3.11", - "resolved": "https://registry.npmjs.org/react-hot-loader/-/react-hot-loader-4.3.11.tgz", - "integrity": "sha512-T0G5jURyTsFLoiW6MTr5Q35UHC/B2pmYJ7+VBjk8yMDCEABRmCGy4g6QwxoB4pWg4/xYvVTa/Pbqnsgx/+NLuA==", + "version": "4.3.12", + "resolved": "https://registry.npmjs.org/react-hot-loader/-/react-hot-loader-4.3.12.tgz", + "integrity": "sha512-GMM4TsqUVss2QPe+Y33NlgydA5/+7tAVQxR0rZqWvBpapM8JhD7p6ymMwSZzr5yxjoXXlK/6P6qNQBOqm1dqdg==", "dev": true, "requires": { "fast-levenshtein": "^2.0.6", @@ -13424,7 +13442,7 @@ }, "react-switch-button": { "version": "1.1.2", - "resolved": "https://registry.npmjs.org/react-switch-button/-/react-switch-button-1.1.2.tgz", + "resolved": "http://registry.npmjs.org/react-switch-button/-/react-switch-button-1.1.2.tgz", "integrity": "sha1-jOhPaUa046k3PnttasjngNl/L08=" }, "react-text-truncate": { @@ -15250,9 +15268,9 @@ } }, "spdy-transport": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/spdy-transport/-/spdy-transport-2.1.0.tgz", - "integrity": "sha512-bpUeGpZcmZ692rrTiqf9/2EUakI6/kXX1Rpe0ib/DyOzbiexVfXkw6GnvI9hVGvIwVaUhkaBojjCZwLNRGQg1g==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/spdy-transport/-/spdy-transport-2.1.1.tgz", + "integrity": "sha512-q7D8c148escoB3Z7ySCASadkegMmUZW8Wb/Q1u0/XBgDKMO880rLQDj8Twiew/tYi7ghemKUi/whSYOwE17f5Q==", "dev": true, "requires": { "debug": "^2.6.8", @@ -25395,9 +25413,9 @@ "dev": true }, "util": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/util/-/util-0.11.0.tgz", - "integrity": "sha512-5n12uMzKCjvB2HPFHnbQSjaqAa98L5iIXmHrZCLavuZVe0qe/SJGbDGWlpaHk5lnBkWRDO+dRu1/PgmUYKPPTw==", + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/util/-/util-0.11.1.tgz", + "integrity": "sha512-HShAsny+zS2TZfaXxD9tYj4HQGlBezXZMZuM/S5PKLLoZkShZiGk9o5CzukI1LVHZvjdvZ2Sj1aW/Ndn2NB/HQ==", "requires": { "inherits": "2.0.3" } diff --git a/src/api/users.js b/src/api/users.js index 5f7d01843..b7ab23b59 100644 --- a/src/api/users.js +++ b/src/api/users.js @@ -61,6 +61,21 @@ export const updateMemberTraits = (handle, updatedTraits) => { .then(resp => _.get(resp.data, 'result.content', {})) } +/** + * Create member traits + * + * @param {String} handle member handle + * @param {Array} traits list of traits to create + * + * @returns {Promise} member traits + */ +export const createMemberTraits = (handle, traits) => { + return axios.post(`${TC_API_URL}/v3/members/${handle}/traits`, { + param: traits + }) + .then(resp => _.get(resp.data, 'result.content', {})) +} + /** * Update member photo * diff --git a/src/routes/settings/actions/index.js b/src/routes/settings/actions/index.js index 2dae7498e..5f46ede38 100644 --- a/src/routes/settings/actions/index.js +++ b/src/routes/settings/actions/index.js @@ -37,7 +37,7 @@ import { import settingsService from '../services/settings' import * as memberService from '../../../api/users' import { uploadFileToS3 } from '../../../api/s3' -import { applyProfileSettingsToTraits } from '../helpers/settings' +import { applyProfileSettingsToTraits, customerTraitId } from '../helpers/settings' import Alert from 'react-s-alert' @@ -201,9 +201,28 @@ export const saveProfileSettings = (settings) => (dispatch, getState) => { const state = getState() const handle = _.get(state, 'loadUser.user.handle') const traits = _.get(state, 'settings.profile.traits') + const existentTraitIds = _.map(traits, 'traitId') const updatedTraits = applyProfileSettingsToTraits(traits, settings) - memberService.updateMemberTraits(handle, updatedTraits) + // we will only update on server traits which can be updated on the settings page + const traitsForServer = updatedTraits.filter((trait) => + // TODO Revert to 'connect_info' again when PROD supports it + _.includes(['basic_info', customerTraitId], trait.traitId) + ) + + const traitsToUpdate = traitsForServer.filter((trait) => + _.includes(existentTraitIds, trait.traitId) + ) + const traitsToCreate= traitsForServer.filter((trait) => + !_.includes(existentTraitIds, trait.traitId) + ) + + Promise.all(_.compact([ + // update existent traits + traitsToUpdate.length > 0 && memberService.updateMemberTraits(handle, traitsToUpdate), + // create non-existent traits + traitsToCreate.length > 0 && memberService.createMemberTraits(handle, traitsToCreate), + ])) // TODO, now we don't update store with the data from server as backend returns wrong // data when we update see https://github.com/appirio-tech/ap-member-microservice/issues/165. // So we update the store with the data we sent to the server. @@ -216,7 +235,8 @@ export const saveProfileSettings = (settings) => (dispatch, getState) => { }) }) .catch((err) => { - Alert.error(`Failed to save settings. ${err.message}`) + const errorMsg = _.get(err, 'response.data.result.content', err.message) + Alert.error(`Failed to save settings. ${errorMsg}`) dispatch({ type: SAVE_PROFILE_SETTINGS_FAILURE }) diff --git a/src/routes/settings/constants/settings.js b/src/routes/settings/constants/settings.js new file mode 100644 index 000000000..a6a2de23c --- /dev/null +++ b/src/routes/settings/constants/settings.js @@ -0,0 +1,257 @@ +export const COUNTRIES = +[ + { key: 'country', name: 'Afghanistan' }, + { key: 'country', name: 'Albania' }, + { key: 'country', name: 'Antarctica' }, + { key: 'country', name: 'Algeria' }, + { key: 'country', name: 'American Samoa' }, + { key: 'country', name: 'Andorra' }, + { key: 'country', name: 'Angola' }, + { key: 'country', name: 'Antigua and Barbuda' }, + { key: 'country', name: 'Azerbaijan' }, + { key: 'country', name: 'Argentina' }, + { key: 'country', name: 'Australia' }, + { key: 'country', name: 'Austria' }, + { key: 'country', name: 'Bahamas' }, + { key: 'country', name: 'Bahrain' }, + { key: 'country', name: 'Bangladesh' }, + { key: 'country', name: 'Armenia' }, + { key: 'country', name: 'Barbados' }, + { key: 'country', name: 'Belgium' }, + { key: 'country', name: 'Bermuda' }, + { key: 'country', name: 'Bhutan' }, + { key: 'country', name: 'Bolivia' }, + { key: 'country', name: 'Bosnia & Herzegowina' }, + { key: 'country', name: 'Botswana' }, + { key: 'country', name: 'Bouvet Island' }, + { key: 'country', name: 'Brazil' }, + { key: 'country', name: 'Belize' }, + { key: 'country', name: 'British Indian Ocean Territory' }, + { key: 'country', name: 'Solomon Islands' }, + { key: 'country', name: 'Virgin Islands (British)' }, + { key: 'country', name: 'Brunei Darussalam' }, + { key: 'country', name: 'Bulgaria' }, + { key: 'country', name: 'Myanmar' }, + { key: 'country', name: 'Burundi' }, + { key: 'country', name: 'Belarus' }, + { key: 'country', name: 'Cambodia' }, + { key: 'country', name: 'Cameroon' }, + { key: 'country', name: 'Canada' }, + { key: 'country', name: 'Cape Verde' }, + { key: 'country', name: 'Cayman Islands' }, + { key: 'country', name: 'Central African Republic' }, + { key: 'country', name: 'Sri Lanka' }, + { key: 'country', name: 'Chad' }, + { key: 'country', name: 'Chile' }, + { key: 'country', name: 'China' }, + { key: 'country', name: 'Taiwan' }, + { key: 'country', name: 'Christmas Island' }, + { key: 'country', name: 'Cocos (Keeling) Islands' }, + { key: 'country', name: 'Colombia' }, + { key: 'country', name: 'Comoros' }, + { key: 'country', name: 'Mayotte' }, + { key: 'country', name: 'Congo' }, + { key: 'country', name: 'Zaire' }, + { key: 'country', name: 'Cook Islands' }, + { key: 'country', name: 'Costa Rica' }, + { key: 'country', name: 'Croatia' }, + { key: 'country', name: 'Cuba' }, + { key: 'country', name: 'Cyprus' }, + { key: 'country', name: 'Czech Republic' }, + { key: 'country', name: 'Benin' }, + { key: 'country', name: 'Denmark' }, + { key: 'country', name: 'Dominica' }, + { key: 'country', name: 'Dominican Republic' }, + { key: 'country', name: 'Ecuador' }, + { key: 'country', name: 'El Salvador' }, + { key: 'country', name: 'Equatorial Guinea' }, + { key: 'country', name: 'Ethiopia' }, + { key: 'country', name: 'Eritrea' }, + { key: 'country', name: 'Estonia' }, + { key: 'country', name: 'Faroe Islands' }, + { key: 'country', name: 'Falkland Islands (Malvinas)' }, + { key: 'country', name: 'South Georgia and The S.Sandwich Is.' }, + { key: 'country', name: 'Fiji' }, + { key: 'country', name: 'Finland' }, + { key: 'country', name: 'Aland Islands' }, + { key: 'country', name: 'France' }, + { key: 'country', name: 'French Guiana' }, + { key: 'country', name: 'French Polynesia' }, + { key: 'country', name: 'French Southern Territories' }, + { key: 'country', name: 'Djibouti' }, + { key: 'country', name: 'Gabon' }, + { key: 'country', name: 'Georgia' }, + { key: 'country', name: 'Gambia' }, + { key: 'country', name: 'Palestine, State of' }, + { key: 'country', name: 'Germany' }, + { key: 'country', name: 'Ghana' }, + { key: 'country', name: 'Gibraltar' }, + { key: 'country', name: 'Kiribati' }, + { key: 'country', name: 'Greece' }, + { key: 'country', name: 'Greenland' }, + { key: 'country', name: 'Grenada' }, + { key: 'country', name: 'Guadeloupe' }, + { key: 'country', name: 'Guam' }, + { key: 'country', name: 'Guatemala' }, + { key: 'country', name: 'Guinea' }, + { key: 'country', name: 'Guyana' }, + { key: 'country', name: 'Haiti' }, + { key: 'country', name: 'Heard and Mc Donald Islands' }, + { key: 'country', name: 'Vatican City State (Holy See)' }, + { key: 'country', name: 'Honduras' }, + { key: 'country', name: 'Hong Kong' }, + { key: 'country', name: 'Hungary' }, + { key: 'country', name: 'Iceland' }, + { key: 'country', name: 'India' }, + { key: 'country', name: 'Indonesia' }, + { key: 'country', name: 'Iran' }, + { key: 'country', name: 'Iraq' }, + { key: 'country', name: 'Ireland' }, + { key: 'country', name: 'Israel' }, + { key: 'country', name: 'Italy' }, + { key: 'country', name: 'Cote D\'Ivoire' }, + { key: 'country', name: 'Jamaica' }, + { key: 'country', name: 'Japan' }, + { key: 'country', name: 'Kazakhstan' }, + { key: 'country', name: 'Jordan' }, + { key: 'country', name: 'Kenya' }, + { key: 'country', name: 'North Korea' }, + { key: 'country', name: 'South Korea' }, + { key: 'country', name: 'Kuwait' }, + { key: 'country', name: 'Kyrgyzstan' }, + { key: 'country', name: 'Lao People\'s Democratic Republic' }, + { key: 'country', name: 'Lebanon' }, + { key: 'country', name: 'Lesotho' }, + { key: 'country', name: 'Latvia' }, + { key: 'country', name: 'Liberia' }, + { key: 'country', name: 'Libya' }, + { key: 'country', name: 'Liechtenstein' }, + { key: 'country', name: 'Lithuania' }, + { key: 'country', name: 'Luxembourg' }, + { key: 'country', name: 'Macau' }, + { key: 'country', name: 'Madagascar' }, + { key: 'country', name: 'Malawi' }, + { key: 'country', name: 'Malaysia' }, + { key: 'country', name: 'Maldives' }, + { key: 'country', name: 'Mali' }, + { key: 'country', name: 'Malta' }, + { key: 'country', name: 'Martinique' }, + { key: 'country', name: 'Mauritania' }, + { key: 'country', name: 'Mauritius' }, + { key: 'country', name: 'Mexico' }, + { key: 'country', name: 'Monaco' }, + { key: 'country', name: 'Mongolia' }, + { key: 'country', name: 'Moldova, Republic of' }, + { key: 'country', name: 'Montenegro' }, + { key: 'country', name: 'Montserrat' }, + { key: 'country', name: 'Morocco' }, + { key: 'country', name: 'Mozambique' }, + { key: 'country', name: 'Oman' }, + { key: 'country', name: 'Namibia' }, + { key: 'country', name: 'Nauru' }, + { key: 'country', name: 'Nepal' }, + { key: 'country', name: 'Netherlands' }, + { key: 'country', name: 'Netherlands Antilles' }, + { key: 'country', name: 'Curacao' }, + { key: 'country', name: 'Aruba' }, + { key: 'country', name: 'Sint Maarten (Dutch part)' }, + { key: 'country', name: 'Bonaire, Sint Eustatius and Saba' }, + { key: 'country', name: 'New Caledonia' }, + { key: 'country', name: 'Vanuatu' }, + { key: 'country', name: 'New Zealand' }, + { key: 'country', name: 'Nicaragua' }, + { key: 'country', name: 'Niger' }, + { key: 'country', name: 'Nigeria' }, + { key: 'country', name: 'Niue' }, + { key: 'country', name: 'Norfolk Island' }, + { key: 'country', name: 'Norway' }, + { key: 'country', name: 'Northern Mariana Islands' }, + { key: 'country', name: 'United States Minor Outlying Islands' }, + { key: 'country', name: 'Micronesia, Federated States of' }, + { key: 'country', name: 'Marshall Islands' }, + { key: 'country', name: 'Palau' }, + { key: 'country', name: 'Pakistan' }, + { key: 'country', name: 'Panama' }, + { key: 'country', name: 'Papua New Guinea' }, + { key: 'country', name: 'Paraguay' }, + { key: 'country', name: 'Peru' }, + { key: 'country', name: 'Philippines' }, + { key: 'country', name: 'Pitcairn' }, + { key: 'country', name: 'Poland' }, + { key: 'country', name: 'Portugal' }, + { key: 'country', name: 'Guinea-Bissau' }, + { key: 'country', name: 'East Timor' }, + { key: 'country', name: 'Puerto Rico' }, + { key: 'country', name: 'Qatar' }, + { key: 'country', name: 'Reunion' }, + { key: 'country', name: 'Romania' }, + { key: 'country', name: 'Russia' }, + { key: 'country', name: 'Rwanda' }, + { key: 'country', name: 'Saint Barthelemy' }, + { key: 'country', name: 'St. Helena' }, + { key: 'country', name: 'Saint Kitts and Nevis' }, + { key: 'country', name: 'Anguilla' }, + { key: 'country', name: 'Saint Lucia' }, + { key: 'country', name: 'Saint Martin (French part)' }, + { key: 'country', name: 'St. Pierre and Miquelon' }, + { key: 'country', name: 'Saint Vincent and The Grenadines' }, + { key: 'country', name: 'San Marino' }, + { key: 'country', name: 'Sao Tome and Principe' }, + { key: 'country', name: 'Saudi Arabia' }, + { key: 'country', name: 'Senegal' }, + { key: 'country', name: 'Serbia' }, + { key: 'country', name: 'Seychelles' }, + { key: 'country', name: 'Sierra Leone' }, + { key: 'country', name: 'Singapore' }, + { key: 'country', name: 'Slovakia' }, + { key: 'country', name: 'Viet Nam' }, + { key: 'country', name: 'Slovenia' }, + { key: 'country', name: 'Somalia' }, + { key: 'country', name: 'South Africa' }, + { key: 'country', name: 'Zimbabwe' }, + { key: 'country', name: 'Spain' }, + { key: 'country', name: 'South Sudan' }, + { key: 'country', name: 'Sudan' }, + { key: 'country', name: 'Western Sahara' }, + { key: 'country', name: 'Suriname' }, + { key: 'country', name: 'Svalbard and Jan Mayen Islands' }, + { key: 'country', name: 'Swaziland' }, + { key: 'country', name: 'Sweden' }, + { key: 'country', name: 'Switzerland' }, + { key: 'country', name: 'Syria' }, + { key: 'country', name: 'Tajikistan' }, + { key: 'country', name: 'Thailand' }, + { key: 'country', name: 'Togo' }, + { key: 'country', name: 'Tokelau' }, + { key: 'country', name: 'Tonga' }, + { key: 'country', name: 'Trinidad and Tobago' }, + { key: 'country', name: 'United Arab Emirates' }, + { key: 'country', name: 'Tunisia' }, + { key: 'country', name: 'Turkey' }, + { key: 'country', name: 'Turkmenistan' }, + { key: 'country', name: 'Turks and Caicos Islands' }, + { key: 'country', name: 'Tuvalu' }, + { key: 'country', name: 'Uganda' }, + { key: 'country', name: 'Ukraine' }, + { key: 'country', name: 'Macedonia' }, + { key: 'country', name: 'Egypt' }, + { key: 'country', name: 'United Kingdom' }, + { key: 'country', name: 'Guernsey' }, + { key: 'country', name: 'Jersey' }, + { key: 'country', name: 'Isle of Man' }, + { key: 'country', name: 'Tanzania, United Republic of' }, + { key: 'country', name: 'United States' }, + { key: 'country', name: 'Virgin Islands (U.S.)' }, + { key: 'country', name: 'Burkina Faso' }, + { key: 'country', name: 'Uruguay' }, + { key: 'country', name: 'Uzbekistan' }, + { key: 'country', name: 'Venezuela' }, + { key: 'country', name: 'Wallis and Futuna Islands' }, + { key: 'country', name: 'Samoa' }, + { key: 'country', name: 'Yemen' }, + { key: 'country', name: 'Zambia' }, + { key: 'country', name: 'St. Kitts and Nevis' }, + { key: 'country', name: 'St. Lucia' }, + { key: 'country', name: 'St. Vincent and Grenadines' }, + { key: 'country', name: 'Palestine' } +] \ No newline at end of file diff --git a/src/routes/settings/helpers/settings.js b/src/routes/settings/helpers/settings.js index 4881b1bd4..d996d2967 100644 --- a/src/routes/settings/helpers/settings.js +++ b/src/routes/settings/helpers/settings.js @@ -2,6 +2,37 @@ * Setting related helper methods */ import _ from 'lodash' +import { ENV } from '../../../../config/constants' + +// blank traits object which we can use if trait doesn't exist to create a new one +export const blankTraits = { + 'connect_info': { // eslint-disable-line quote-props + traitId: 'connect_info', + categoryName: 'Connect User Information', + traits: { + data: [{}], + }, + }, + 'basic_info': { // eslint-disable-line quote-props + traitId: 'basic_info', + categoryName: 'Basic Info', + traits: { + data: [{}], + }, + }, + // to use for fallback on PROD for now + 'customer_info': { // eslint-disable-line quote-props + traitId: 'customer_info', + categoryName: 'Customer Information', + traits: { + data: [{}], + }, + }, +} + +// as now DEV environment supports only `connect_info` and PROD environment supports only `customer_info` +// choose depend on ENV +export const customerTraitId = ENV === 'DEV' ? 'connect_info' : 'customer_info' /** * Format row member traits data to the format which can be rendered by the form @@ -12,8 +43,8 @@ import _ from 'lodash' * @returns {Object} data formated for profile settings page form */ export const formatProfileSettings = (traits) => { - // TODO Revert to 'connect_info' again - const connectTrait = _.find(traits, ['traitId', 'customer_info']) + // TODO Revert to 'connect_info' again when PROD supports it + const connectTrait = _.find(traits, ['traitId', customerTraitId]) let data = {} if (connectTrait) { @@ -29,6 +60,7 @@ export const formatProfileSettings = (traits) => { if (traitData && traitData.length > 0) { data.photoUrl = traitData[0].photoURL data.firstNLastName = `${traitData[0].firstName} ${traitData[0].lastName}` + data.country = traitData[0].country } } @@ -45,10 +77,20 @@ export const formatProfileSettings = (traits) => { * @returns {Array} updated member traits data */ export const applyProfileSettingsToTraits = (traits, profileSettings) => { - const updatedTraits = traits.map((trait) => { - // we put all the info from profile settings to `customer_info` trait as it is, skipping `photoUrl` - // TODO Revert to 'connect_info' again - if (trait.traitId === 'customer_info') { + const existentTraits = [...traits] + + // make sure traits exists so we can update them + if (!_.find(existentTraits, { traitId: 'basic_info'})) { + existentTraits.push(blankTraits['basic_info']) + } + if (!_.find(existentTraits, { traitId: customerTraitId})) { + existentTraits.push(blankTraits[customerTraitId]) + } + + const updatedTraits = existentTraits.map((trait) => { + // we put all the info from profile settings to `connect_info` trait as it is, skipping `photoUrl` + // TODO Revert to 'connect_info' again when PROD supports it + if (trait.traitId === customerTraitId) { const updatedTrait = {...trait} const updatedProps = _.omit(profileSettings, 'photoUrl') @@ -59,6 +101,11 @@ export const applyProfileSettingsToTraits = (traits, profileSettings) => { ...updatedProps }] } + + // define categoryName to handle possible data inconsistency + if (!updatedTrait.categoryName) { + updatedTrait.categoryName = blankTraits[customerTraitId].categoryName + } return updatedTrait } @@ -83,6 +130,11 @@ export const applyProfileSettingsToTraits = (traits, profileSettings) => { ...updatedProps }] } + + // define categoryName to handle possible data inconsistency + if (!updatedTrait.categoryName) { + updatedTrait.categoryName = blankTraits['basic_info'].categoryName + } return updatedTrait } diff --git a/src/routes/settings/routes/profile/components/ProfileSettingsForm.jsx b/src/routes/settings/routes/profile/components/ProfileSettingsForm.jsx index d15a0470e..a7fe82bb8 100644 --- a/src/routes/settings/routes/profile/components/ProfileSettingsForm.jsx +++ b/src/routes/settings/routes/profile/components/ProfileSettingsForm.jsx @@ -7,10 +7,22 @@ import FormsyForm from 'appirio-tech-react-components/components/Formsy' const TCFormFields = FormsyForm.Fields const Formsy = FormsyForm.Formsy import ProfileSettingsAvatar from './ProfileSettingsAvatar' +import SelectDropdown from '../../../../../components/SelectDropdown/SelectDropdown' +import { COUNTRIES } from '../../../constants/settings.js' + import './ProfileSettingsForm.scss' const companySizeRadioOptions = ['1-15', '16-50', '51-500', '500+'] +const countries = COUNTRIES.map(country => ({ + title: country.name, + value: country.name, +})) +countries.unshift({ + title: '- Select country -', + value: '', +}) + class ProfileSettingsForm extends Component { constructor(props) { super(props) @@ -52,11 +64,11 @@ class ProfileSettingsForm extends Component { // as form could update not all fields, thus they won't be included in `data` // for example user avatar is not included in `data` thus will be removed if don't use // this.props.values.settings as a base - const updatedDate = { + const updatedData = { ...this.props.values.settings, ...data, } - this.props.saveSettings(updatedDate) + this.props.saveSettings(updatedData) } onValid() { @@ -106,8 +118,9 @@ class ProfileSettingsForm extends Component { options={companySizeRadioOptions.map((label) => ({option: label, label, value: label}))} required /> - -
Business address
+ + {/* TODO as for now PROD doesn't supports `connect_info` we don't have a places where to save this data for now */} + {/*
Business address
{this.getField('Address', 'address')} {this.getField('City', 'city')}
@@ -126,8 +139,19 @@ class ProfileSettingsForm extends Component { onChange={this.onFieldUpdate} />
+ */} +
+
Country
+
+ +
- {this.getField('Country', 'country')}