From fe8258bf38d527538d3fa5e8906ef565c9c2e662 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 26 Sep 2019 17:16:24 +0200 Subject: [PATCH] change date format used in the background --- .../RecursiveForm/RecursiveForm.vue | 11 ++++++- src/config/configBus.js | 9 ++++++ src/data/delivery/getDeliveryDates.js | 29 +++++++------------ 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/components/RecursiveForm/RecursiveForm.vue b/src/components/RecursiveForm/RecursiveForm.vue index ca096cd4..9fed632f 100644 --- a/src/components/RecursiveForm/RecursiveForm.vue +++ b/src/components/RecursiveForm/RecursiveForm.vue @@ -348,7 +348,11 @@ export default { * @param {*} value - New value for current option. */ handler(value) { - this.$configBus.$emit(EVENTS.UPDATE, { name: this.mutableOption.name, value }); + this.$configBus.$emit(EVENTS.UPDATE, + { + name: this.mutableOption.name, + value, + }); }, deep: typeof selected !== 'string', immediate: true, @@ -392,6 +396,11 @@ export default { */ getChoicesByDependency({ name }) { const dependencies = this.$configBus.dependencies[this.$configBus.currentCarrier]; + + if (!dependencies) { + return; + } + const { dependency } = this.mutableOption; let dependencyName = dependency.name; diff --git a/src/config/configBus.js b/src/config/configBus.js index d1bf4898..9cd53c07 100644 --- a/src/config/configBus.js +++ b/src/config/configBus.js @@ -70,9 +70,18 @@ export const createConfigBus = () => { /** * The object where settings will be stored. + * + * @type {Object} */ values: {}, + /** + * The object where the values that are sent to the external platform will be stored. Similar to `this.values`, + * but this object is tweaked to comply with our API and conventions and to maximize readability for the + * developers using it. + * + * @type {Object} + */ exportValues: {}, /** diff --git a/src/data/delivery/getDeliveryDates.js b/src/data/delivery/getDeliveryDates.js index 6bb25459..78cb7fc4 100644 --- a/src/data/delivery/getDeliveryDates.js +++ b/src/data/delivery/getDeliveryDates.js @@ -1,18 +1,6 @@ import * as SETTINGS from '@/config/data/settingsConfig'; import { configBus } from '@/config/configBus'; -/** - * Helper function for date.toLocaleDateString with locale from the config bus and default format. - * - * @param {Date} date - Date to format. - * @param {Object} format - The format to apply. - * - * @returns {string} - */ -function toLocaleDateString(date, format = { month: 'numeric', day: 'numeric', year: 'numeric' }) { - return date.toLocaleDateString(configBus.get(SETTINGS.LOCALE), format); -} - /** * @param {MyParcel.DeliveryOption[]} deliveryOptions - Delivery options object. * @@ -28,7 +16,7 @@ export function getDeliveryDates(deliveryOptions) { if (configBus.get(SETTINGS.DELIVERY_DAYS_WINDOW) === 0) { return [ { - name: toLocaleDateString(new Date(deliveryOptions[0].date.date)), + name: new Date(deliveryOptions[0].date.date).toString(), label: '', }, ]; @@ -36,13 +24,16 @@ export function getDeliveryDates(deliveryOptions) { return deliveryOptions.map(({ date: option }) => { const date = new Date(option.date); - const name = toLocaleDateString(date); + const name = date.toISOString(); - const dateString = toLocaleDateString(date, { - weekday: 'long', - month: 'long', - day: 'numeric', - }); + const dateString = date.toLocaleDateString( + configBus.get(SETTINGS.LOCALE), + { + weekday: 'long', + month: 'long', + day: 'numeric', + } + ); const label = dateString.charAt(0).toUpperCase() + dateString.slice(1);