From 7212f785ddb51a37eea983e2330ddb4b034c549b Mon Sep 17 00:00:00 2001 From: Marian Ene Date: Thu, 4 Nov 2021 15:46:40 +0200 Subject: [PATCH 1/5] SMSLink integration --- CHANGELOG.MD | 4 +++ common/constants.ts | 4 +++ docs/README.md | 5 +-- messages/context.json | 1 + messages/en.json | 1 + messages/it.json | 1 + messages/ro.json | 1 + node/package.json | 4 +-- node/yarn.lock | 10 +++--- react/admin/ReturnForm.tsx | 58 ++++++++++++++++++++++++++++++++ react/admin/ReturnsSettings.tsx | 18 +++++++++- react/common/fetch.tsx | 1 + react/store/MyReturnsPageAdd.tsx | 18 ++++++++++ 13 files changed, 116 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 70b65a2bc..d9035850b 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +- SMSLink integration + ### Fixed - Update the refundedShippingValue in the front if it was declared via API. diff --git a/common/constants.ts b/common/constants.ts index d6b81ac32..8d3d2be47 100644 --- a/common/constants.ts +++ b/common/constants.ts @@ -6,6 +6,7 @@ export const SETTINGS_SCHEMA = { paymentCard: { type: 'boolean' }, paymentVoucher: { type: 'boolean' }, termsUrl: { type: 'string' }, + allowSMSLinkIntegration: { type: 'boolean' }, options: { type: 'array', items: { $ref: '#/$defs/options' }, @@ -29,6 +30,7 @@ export const SETTINGS_SCHEMA = { 'v-security': { allowGetAll: true, publicFilter: [ + 'allowSMSLinkIntegration', 'maxDays', 'excludedCategories', 'paymentBank', @@ -44,6 +46,7 @@ export const SETTINGS_SCHEMA = { 'v-default-fields': [ 'id', 'createdIn', + 'allowSMSLinkIntegration', 'maxDays', 'excludedCategories', 'paymentBank', @@ -56,6 +59,7 @@ export const SETTINGS_SCHEMA = { 'v-indexed': [ 'id', 'createdIn', + 'allowSMSLinkIntegration', 'maxDays', 'excludedCategories', 'paymentBank', diff --git a/docs/README.md b/docs/README.md index d11053b1f..9368b5104 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,13 +6,14 @@ VTEX Return App - Open the VTEX App Store and install this app on your store, or run the following command on VTEX toolbelt: -> vtex install vtex.return-app@1.x +> vtex install vtex.return-app@2.x - From the left side access the `Returns > Requests` page. The first time you access it, the application creates the masterdata schema and settings it needs automatically. ## Settings - Go to `Returns > Returns Settings` and fill up the form with the settings you need. + - `Enable SMSLink integration`: Allow SMSLink integration. Customers will receive messages when a new return request is registered or the request reaches the states of: picked up, approved or denied. For this option you also need to install `vtex.smslink`. - `Max days:` The maximum number of days that customers can request the return of products, from the moment the order was invoiced. - `Terms and conditions URL:` The URL of the page with the return terms and conditions. The customer can access this URL from the form they fill out to request a return. - If you have the terms on conditions page on `http://example.com/terms-and-conditions` it's enough for you to type just `/terms-and-conditions` @@ -26,7 +27,7 @@ The return application serves the necessary functionalities for requesting retur #### Installation and configuration -The application can be installed using the following command in VTEX Toolbelt: `vtex install vtex.return-app@0.x` +The application can be installed using the following command in VTEX Toolbelt: `vtex install vtex.return-app@2.x` After the installation you must access the `Returns > Requests` page from the admin menu. At this point, the application creates the masterdata schema and email templates automatically. diff --git a/messages/context.json b/messages/context.json index ec5c730f2..23ffb6a7f 100644 --- a/messages/context.json +++ b/messages/context.json @@ -3,6 +3,7 @@ "navigation.labelRequests": "Requests", "navigation.labelSettings": "Returns Settings", "settings.updateSchema": "Updating Settings...", + "settings.allowSMSLinkIntegration_label": "Enable SMSLink integration", "settings.maxDays_label": "Max days:", "settings.terms_label": "Terms and conditions URL:", "settings.paymentMethods_label": "Available payment methods:", diff --git a/messages/en.json b/messages/en.json index bcb2c3a18..18c2954fa 100644 --- a/messages/en.json +++ b/messages/en.json @@ -3,6 +3,7 @@ "navigation.labelRequests": "Requests", "navigation.labelSettings": "Returns Settings", "settings.updateSchema": "Updating Settings", + "settings.allowSMSLinkIntegration_label": "Enable SMSLink integration", "settings.maxDays_label": "Max days:", "settings.terms_label": "Terms and conditions URL:", "settings.paymentMethods_label": "Available payment methods:", diff --git a/messages/it.json b/messages/it.json index dc0440e2b..cbf1c05c3 100644 --- a/messages/it.json +++ b/messages/it.json @@ -3,6 +3,7 @@ "navigation.labelRequests": "Richieste", "navigation.labelSettings": "Impostazioni di reso", "settings.updateSchema": "Aggiornamento delle impostazioni in corso", + "settings.allowSMSLinkIntegration_label": "Abilita l'integrazione di SMSLink", "settings.maxDays_label": "Numero massimo di giorni:", "settings.terms_label": "URL dei termini e delle condizioni:", "settings.paymentMethods_label": "Metodi di pagamento disponibili:", diff --git a/messages/ro.json b/messages/ro.json index 48976c259..b1446725f 100644 --- a/messages/ro.json +++ b/messages/ro.json @@ -3,6 +3,7 @@ "navigation.labelRequests": "Cereri de retur", "navigation.labelSettings": "Setari", "settings.updateSchema": "Un moment, facem cateva actualizari pentru tine!", + "settings.allowSMSLinkIntegration_label": "Permite integrarea cu SMSLink", "settings.maxDays_label": "Numar maxim de zile:", "settings.terms_label": "URL pentru termeni si conditii:", "settings.paymentMethods_label": "Metode de plata:", diff --git a/node/package.json b/node/package.json index 431cdb286..25c47e8ca 100644 --- a/node/package.json +++ b/node/package.json @@ -3,7 +3,7 @@ "axios": "^0.20.0", "co-body": "^6.0.0", "ramda": "^0.25.0", - "@vtex/api": "6.45.4", + "@vtex/api": "6.45.3", "@vtex/clients": "^2.13.0" }, "devDependencies": { @@ -11,7 +11,7 @@ "@types/jest": "^24.0.18", "@types/node": "^12.0.0", "@types/ramda": "types/npm-ramda#dist", - "@vtex/api": "6.45.4", + "@vtex/api": "6.45.3", "@vtex/test-tools": "^1.0.0", "vtex.css-handles": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles", "vtex.device-detector": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.device-detector@0.2.6/public/@types/vtex.device-detector", diff --git a/node/yarn.lock b/node/yarn.lock index a71cffa5f..f830cc256 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -1532,10 +1532,10 @@ resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.3.tgz#781d360c282436494b32fe7d9f7f8e64b3118aa3" integrity sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw== -"@vtex/api@6.45.4": - version "6.45.4" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.4.tgz#58be7497c0c0f91a388fabd42149e48cb95e271d" - integrity sha512-DVAJr5BkSjXupjn2h5Z1In8C3Li9kZwCXPwRQbpIgyS7s9dN2ZEFQc6nQlJm6ZoDCoyYBg62LgD7Kurvz9jc3w== +"@vtex/api@6.45.3": + version "6.45.3" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.3.tgz#fe7d08adb4eab1fda5e34143cc6302a4c5aa5f52" + integrity sha512-kiD7We1TCKDyBdpYoh2Se3An+jTJRUzXGNpKifoDZylWQ1PyIx+3oL5ZAif9InlY3uJkfEisSAI6nxoKTgvPfw== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3" @@ -5539,7 +5539,7 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" -stats-lite@vtex/node-stats-lite#dist: +"stats-lite@github:vtex/node-stats-lite#dist": version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: diff --git a/react/admin/ReturnForm.tsx b/react/admin/ReturnForm.tsx index 6407f68d7..e8da70bad 100644 --- a/react/admin/ReturnForm.tsx +++ b/react/admin/ReturnForm.tsx @@ -94,14 +94,38 @@ class ReturnForm extends Component { showLabelError: false, labelDisabled: false, totalAmount: 0, + settings: {} } } componentDidMount(): void { this.getProfile().then() + this.getSettings() this.getFullData() } + getSettings = async () => { + // eslint-disable-next-line react/no-access-state-in-setstate + this.setState({ ...this.state, loading: true }) + await fetch( + `${fetchPath.getDocuments + schemaNames.settings}/${ + schemaTypes.settings + }/1`, + { + method: fetchMethod.get, + headers: fetchHeaders, + } + ) + .then((response) => { + return response.json() + }) + .then((json) => { + if (!json?.[0]) return + this.setState({settings: json[0] }) + }) + .catch((err) => this.setState({ error: err })) + } + getGiftCardInfo(request: any) { return `RA${request.id.split('-')[0]}` } @@ -405,6 +429,7 @@ class ReturnForm extends Component { product, registeredUser, comment, + settings } = this.state let requestData = request @@ -498,6 +523,39 @@ class ReturnForm extends Component { this.savePartial(schemaNames.request, requestBody) this.saveMasterData(schemaNames.history, statusHistoryData) + let smsLinkBody: any = { + requestId: request.id, + orderId: request.orderId, + phone: request.phoneNumber + } + + let sendSMS = false + if(statusInput === requestsStatuses.denied || statusInput === requestsStatuses.refunded) { + smsLinkBody = { + ...smsLinkBody, + event: statusInput === requestsStatuses.denied ? 'request-denied': 'request-finalized', + } + sendSMS = true + } else if (statusInput === requestsStatuses.picked) { + smsLinkBody = { + ...smsLinkBody, + event: 'parcel-received', + } + sendSMS = true + } + + if(sendSMS && settings.allowSMSLinkIntegration) { + try { + fetch(`${fetchPath.sendSMS}`, { + method: fetchMethod.post, + body: JSON.stringify(smsLinkBody), + headers: fetchHeaders, + }) + } catch { + // console.log(e) + } + } + if ( request.status === requestsStatuses.picked && statusInput === requestsStatuses.pendingVerification diff --git a/react/admin/ReturnsSettings.tsx b/react/admin/ReturnsSettings.tsx index 91f5a31c0..1d01d0d65 100644 --- a/react/admin/ReturnsSettings.tsx +++ b/react/admin/ReturnsSettings.tsx @@ -10,6 +10,7 @@ import { IconClear, Button, CheckboxGroup, + Checkbox, IconDeny, Table, Modal, @@ -33,6 +34,7 @@ const messages = defineMessages({ settingsSaved: { id: 'returns.settingsSaved' }, labelSettings: { id: 'navigation.labelSettings' }, updateSchema: { id: 'settings.updateSchema' }, + smsLinkIntegrationLabel: {id: 'settings.allowSMSLinkIntegration_label'}, maxDaysLabel: { id: 'settings.maxDays_label' }, termsLabel: { id: 'settings.terms_label' }, searchCategories: { id: 'settings.searchCategories' }, @@ -61,6 +63,7 @@ class ReturnsSettings extends Component { this.state = { id: '', updatingSchema: false, + allowSMSLinkIntegration: '', maxDays: '', termsUrl: '', categoryFilterQuery: '', @@ -161,6 +164,7 @@ class ReturnsSettings extends Component { } this.setState({ id: json[0].id, + allowSMSLinkIntegration: json[0].allowSMSLinkIntegration, maxDays: json[0].maxDays, termsUrl: json[0].termsUrl, paymentBank, @@ -299,7 +303,7 @@ class ReturnsSettings extends Component { errorMessage: '', loading: true, }) - const { maxDays, excludedCategories, termsUrl, id, payments, options } = + const { allowSMSLinkIntegration, maxDays, excludedCategories, termsUrl, id, payments, options } = this.state let hasErrors = false @@ -346,6 +350,7 @@ class ReturnsSettings extends Component { const postData = { id, + allowSMSLinkIntegration: allowSMSLinkIntegration, maxDays: parseInt(maxDays, 10), excludedCategories: JSON.stringify(excludedCategories), termsUrl, @@ -417,6 +422,7 @@ class ReturnsSettings extends Component { render() { const { + allowSMSLinkIntegration, maxDays, termsUrl, excludedCategories, @@ -469,6 +475,16 @@ class ReturnsSettings extends Component { ) : (
+
+
+ this.setState({ allowSMSLinkIntegration: !allowSMSLinkIntegration })} + /> +
+
diff --git a/react/common/fetch.tsx b/react/common/fetch.tsx index 1e75930bb..e4f65bfe8 100644 --- a/react/common/fetch.tsx +++ b/react/common/fetch.tsx @@ -14,6 +14,7 @@ export const fetchPath = { getOrder: '/returns/getOrder/', renderTemplates: '/api/template-render/pvt/templates', createRefund: '/returns/createRefund/', + sendSMS: '/sms-link-app/send-sms', } export const fetchMethod = { diff --git a/react/store/MyReturnsPageAdd.tsx b/react/store/MyReturnsPageAdd.tsx index a38208b4c..22584f119 100644 --- a/react/store/MyReturnsPageAdd.tsx +++ b/react/store/MyReturnsPageAdd.tsx @@ -728,6 +728,7 @@ class MyReturnsPageAdd extends Component { iban, accountHolder, orderProducts, + settings } = this.state orderProducts.forEach((product: any) => { @@ -776,6 +777,23 @@ class MyReturnsPageAdd extends Component { }) .then(() => { this.showTable() + if(settings.allowSMSLinkIntegration) { + let smsLinkBody: any = { + requestId: response.DocumentId, + orderId: requestData.orderId, + phone: requestData.phoneNumber, + event: 'request-created' + } + try { + fetch(`${fetchPath.sendSMS}`, { + method: fetchMethod.post, + body: JSON.stringify(smsLinkBody), + headers: fetchHeaders, + }) + } catch { + // console.log(e) + } + } }) } else { this.setState({ From 530fcbe3fc88f8376d3aa9b7eb646893f4047e12 Mon Sep 17 00:00:00 2001 From: Marian Ene Date: Mon, 15 Nov 2021 15:30:47 +0200 Subject: [PATCH 2/5] Change requests --- react/admin/ReturnForm.tsx | 64 +++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/react/admin/ReturnForm.tsx b/react/admin/ReturnForm.tsx index e8da70bad..80743063b 100644 --- a/react/admin/ReturnForm.tsx +++ b/react/admin/ReturnForm.tsx @@ -523,36 +523,44 @@ class ReturnForm extends Component { this.savePartial(schemaNames.request, requestBody) this.saveMasterData(schemaNames.history, statusHistoryData) - let smsLinkBody: any = { - requestId: request.id, - orderId: request.orderId, - phone: request.phoneNumber - } - - let sendSMS = false - if(statusInput === requestsStatuses.denied || statusInput === requestsStatuses.refunded) { - smsLinkBody = { - ...smsLinkBody, - event: statusInput === requestsStatuses.denied ? 'request-denied': 'request-finalized', + if(settings.allowSMSLinkIntegration) { + let smsLinkBody: any = { + requestId: request.id, + orderId: request.orderId, + phone: request.phoneNumber } - sendSMS = true - } else if (statusInput === requestsStatuses.picked) { - smsLinkBody = { - ...smsLinkBody, - event: 'parcel-received', + + let sendSMS = true + let SMSLinkEvent = '' + + switch (statusInput) { + case requestsStatuses.denied: + SMSLinkEvent = 'request-denied' + break; + case requestsStatuses.refunded: + SMSLinkEvent = 'request-finalized' + break; + case requestsStatuses.picked: + SMSLinkEvent = 'parcel-received' + break; + default: + sendSMS = false } - sendSMS = true - } - - if(sendSMS && settings.allowSMSLinkIntegration) { - try { - fetch(`${fetchPath.sendSMS}`, { - method: fetchMethod.post, - body: JSON.stringify(smsLinkBody), - headers: fetchHeaders, - }) - } catch { - // console.log(e) + + if (sendSMS){ + smsLinkBody = { + ...smsLinkBody, + event: SMSLinkEvent, + } + try { + fetch(`${fetchPath.sendSMS}`, { + method: fetchMethod.post, + body: JSON.stringify(smsLinkBody), + headers: fetchHeaders, + }) + } catch { + // console.log(e) + } } } From 4f4dfaba0712163ec4b7446c8fcd1df76c9518dd Mon Sep 17 00:00:00 2001 From: Marian Ene Date: Mon, 15 Nov 2021 15:32:11 +0200 Subject: [PATCH 3/5] Vtex Api version --- node/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/package.json b/node/package.json index 25c47e8ca..431cdb286 100644 --- a/node/package.json +++ b/node/package.json @@ -3,7 +3,7 @@ "axios": "^0.20.0", "co-body": "^6.0.0", "ramda": "^0.25.0", - "@vtex/api": "6.45.3", + "@vtex/api": "6.45.4", "@vtex/clients": "^2.13.0" }, "devDependencies": { @@ -11,7 +11,7 @@ "@types/jest": "^24.0.18", "@types/node": "^12.0.0", "@types/ramda": "types/npm-ramda#dist", - "@vtex/api": "6.45.3", + "@vtex/api": "6.45.4", "@vtex/test-tools": "^1.0.0", "vtex.css-handles": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles", "vtex.device-detector": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.device-detector@0.2.6/public/@types/vtex.device-detector", From e57f50979e82b8be857e40cdb2e90058ed772c9a Mon Sep 17 00:00:00 2001 From: Robert Diaconeasa Date: Mon, 15 Nov 2021 16:10:58 +0200 Subject: [PATCH 4/5] Revert yarn.lock file --- node/yarn.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/node/yarn.lock b/node/yarn.lock index f830cc256..a71cffa5f 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -1532,10 +1532,10 @@ resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.3.tgz#781d360c282436494b32fe7d9f7f8e64b3118aa3" integrity sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw== -"@vtex/api@6.45.3": - version "6.45.3" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.3.tgz#fe7d08adb4eab1fda5e34143cc6302a4c5aa5f52" - integrity sha512-kiD7We1TCKDyBdpYoh2Se3An+jTJRUzXGNpKifoDZylWQ1PyIx+3oL5ZAif9InlY3uJkfEisSAI6nxoKTgvPfw== +"@vtex/api@6.45.4": + version "6.45.4" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.4.tgz#58be7497c0c0f91a388fabd42149e48cb95e271d" + integrity sha512-DVAJr5BkSjXupjn2h5Z1In8C3Li9kZwCXPwRQbpIgyS7s9dN2ZEFQc6nQlJm6ZoDCoyYBg62LgD7Kurvz9jc3w== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3" @@ -5539,7 +5539,7 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" -"stats-lite@github:vtex/node-stats-lite#dist": +stats-lite@vtex/node-stats-lite#dist: version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: From 22e77e9ddfd5e4f744cedea3f1780f1ea5e99b46 Mon Sep 17 00:00:00 2001 From: Marian Ene Date: Mon, 17 Jan 2022 14:21:37 +0200 Subject: [PATCH 5/5] added missing refundedShippingValue prop when creating a return request --- manifest.json | 2 +- react/store/MyReturnsPageAdd.tsx | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/manifest.json b/manifest.json index 95673b9fa..5b8c0b22c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "vendor": "vtex", "name": "return-app", - "version": "2.16.1", + "version": "2.16.2", "title": "Return app", "description": "Return app", "dependencies": { diff --git a/react/store/MyReturnsPageAdd.tsx b/react/store/MyReturnsPageAdd.tsx index 90105f390..1d8199ca3 100644 --- a/react/store/MyReturnsPageAdd.tsx +++ b/react/store/MyReturnsPageAdd.tsx @@ -770,7 +770,7 @@ class MyReturnsPageAdd extends Component { iban, accountHolder, orderProducts, - settings + settings, } = this.state orderProducts.forEach((product: any) => { @@ -797,6 +797,7 @@ class MyReturnsPageAdd extends Component { iban, accountHolder, status: requestsStatuses.new, + refundedShippingValue: 0, dateSubmitted: getCurrentDate(), type: schemaTypes.requests, } @@ -819,13 +820,14 @@ class MyReturnsPageAdd extends Component { }) .then(() => { this.showTable() - if(settings.allowSMSLinkIntegration) { - let smsLinkBody: any = { + if (settings.allowSMSLinkIntegration) { + const smsLinkBody: any = { requestId: response.DocumentId, orderId: requestData.orderId, phone: requestData.phoneNumber, - event: 'request-created' + event: 'request-created', } + try { fetch(`${fetchPath.sendSMS}`, { method: fetchMethod.post,