Skip to content

Commit

Permalink
feat: show base prices for all options
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Nov 20, 2020
1 parent f0e7ad4 commit e393561
Show file tree
Hide file tree
Showing 33 changed files with 530 additions and 247 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ window.MyParcelConfig = {
dropOffDelay: 1,
},
strings: {
wrongPostalCodeCity: 'Zaterdaglevering',
saturdayDeliveryTitle: 'Combinatie postcode/plaats onbekend',
saturdayDeliveryTitle: 'Zaterdaglevering',
wrongPostalCodeCity: 'Combinatie postcode/plaats onbekend',

// Address strings
city: 'Plaats',
Expand All @@ -102,7 +102,6 @@ window.MyParcelConfig = {

// Other strings
closed: 'Gesloten',
free: 'Gratis',
from: 'Vanaf',
loadMore: 'Laad meer',
retry: 'Opnieuw',
Expand All @@ -120,7 +119,7 @@ When there is no title set for `deliveryMorningTitle`, `deliveryStandardTitle` o
To get the object with the selected options from the delivery options do the following:
```js
const data = document.querySelector('#mypa-input').value;
const obj = CODE_FORMAT_JSON.parse(data);
const obj = JSON.parse(data);

// `obj` will be something like this:
// {
Expand Down
15 changes: 13 additions & 2 deletions src/assets/scss/delivery-options/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,27 @@ table.#{$classBase}__table {

td {
padding: 0;
vertical-align: top;
word-break: normal;
vertical-align: middle;

label {
display: block;
/*
* Elements this applies to also have a helper class applying "float: right" so it will still look alright-ish on
* IE9, just not as nice as with flexbox.
*/
display: flex;
justify-content: space-between;
text-align: left;

& > * {
margin-top: auto;
margin-bottom: auto;
}
}

&.#{$classBase} {
&__input {
vertical-align: top;
width: 1px;
padding-right: 6px;
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/scss/delivery-options/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}

&__d-block {
display: block;
display: block !important;
}

&__w-100 {
Expand Down
2 changes: 1 addition & 1 deletion src/config/defaultStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getDefaultStrings = () => ({

// Other strings
[STRINGS.CLOSED]: 'Gesloten',
[STRINGS.FREE]: 'Gratis',
[STRINGS.DISCOUNT]: 'Korting',
[STRINGS.FROM]: 'Vanaf',
[STRINGS.LOAD_MORE]: 'Laad meer',
[STRINGS.RETRY]: 'Opnieuw',
Expand Down
158 changes: 83 additions & 75 deletions src/config/formConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as SETTINGS from '@/data/keys/configKeys';
import * as CONFIG from '@/data/keys/configKeys';
import * as STRINGS from '@/data/keys/stringsKeys';

export const DELIVERY = 'delivery';
Expand Down Expand Up @@ -46,83 +46,91 @@ export const PICKUP_EXPRESS = 'pickup_express';
export const MONDAY_DELIVERY = 'monday';
export const SATURDAY_DELIVERY = 'saturday';

/**
* Delivery options.
*
* @type {MyParcelDeliveryOptions.FormConfig}
* @see https://myparcelnl.github.io/api/#8
*/
export const formConfigDelivery = {
name: DELIVERY,
enabled: CONFIG.ALLOW_DELIVERY_OPTIONS,
options: [
{
name: DELIVERY_MORNING,
enabled: CONFIG.ALLOW_MORNING_DELIVERY,
label: STRINGS.DELIVERY_MORNING_TITLE,
price: CONFIG.PRICE_MORNING_DELIVERY,
},
{
name: DELIVERY_STANDARD,
label: STRINGS.DELIVERY_STANDARD_TITLE,
price: CONFIG.PRICE_STANDARD_DELIVERY,
selected: true,
},
{
name: DELIVERY_EVENING,
enabled: CONFIG.ALLOW_EVENING_DELIVERY,
label: STRINGS.DELIVERY_EVENING_TITLE,
price: CONFIG.PRICE_EVENING_DELIVERY,
},
],
};

/**
* Shipment options for delivery.
*
* @type {MyParcelDeliveryOptions.FormConfig}
* @see https://myparcelnl.github.io/api/#7_C
*/
export const formConfigShipmentOptions = {
name: SHIPMENT_OPTIONS,
options: [
{
name: SIGNATURE,
enabled: CONFIG.ALLOW_SIGNATURE,
label: STRINGS.SIGNATURE_TITLE,
price: CONFIG.PRICE_SIGNATURE,
},
{
name: ONLY_RECIPIENT,
enabled: CONFIG.ALLOW_ONLY_RECIPIENT,
label: STRINGS.ONLY_RECIPIENT_TITLE,
price: CONFIG.PRICE_ONLY_RECIPIENT,
},
],
};

/**
* Pickup locations.
*
* @type {MyParcelDeliveryOptions.FormConfig}
* @see https://myparcelnl.github.io/api/#7_O
*/
export const formConfigPickup = {
name: PICKUP,
enabled: CONFIG.ALLOW_PICKUP_LOCATIONS,
options: [
{
name: PICKUP_EXPRESS,
enabled: CONFIG.ALLOW_PICKUP_EXPRESS,
price: CONFIG.PRICE_PICKUP_EXPRESS,
},
{
name: PICKUP_STANDARD,
price: CONFIG.PRICE_PICKUP,
selected: true,
},
],
};

/**
* Base form config.
*
* @type {Object}
* @type {MyParcelDeliveryOptions.FormConfig[]}
*/
export const formConfig = [
/**
* Delivery options.
*
* @see https://myparcelnl.github.io/api/#8
*/
{
enabled: SETTINGS.ALLOW_DELIVERY_OPTIONS,
name: DELIVERY,
options: [
{
name: DELIVERY_MORNING,
enabled: SETTINGS.ALLOW_MORNING_DELIVERY,
label: STRINGS.DELIVERY_MORNING_TITLE,
price: SETTINGS.PRICE_MORNING_DELIVERY,
},
{
name: DELIVERY_STANDARD,
label: STRINGS.DELIVERY_STANDARD_TITLE,
price: SETTINGS.PRICE_STANDARD_DELIVERY,
selected: true,
},
{
name: DELIVERY_EVENING,
enabled: SETTINGS.ALLOW_EVENING_DELIVERY,
label: STRINGS.DELIVERY_EVENING_TITLE,
price: SETTINGS.PRICE_EVENING_DELIVERY,
},
],
},

/**
* Shipment options for delivery.
*
* @see https://myparcelnl.github.io/api/#7_C
*/
{
name: SHIPMENT_OPTIONS,
options: [
{
name: SIGNATURE,
enabled: SETTINGS.ALLOW_SIGNATURE,
label: STRINGS.SIGNATURE_TITLE,
price: SETTINGS.PRICE_SIGNATURE,
},
{
name: ONLY_RECIPIENT,
enabled: SETTINGS.ALLOW_ONLY_RECIPIENT,
label: STRINGS.ONLY_RECIPIENT_TITLE,
price: SETTINGS.PRICE_ONLY_RECIPIENT,
},
],
},

/**
* Pickup locations.
*/
{
name: PICKUP,
enabled: SETTINGS.ALLOW_PICKUP_LOCATIONS,
options: [
{
name: PICKUP_EXPRESS,
enabled: SETTINGS.ALLOW_PICKUP_EXPRESS,
price: SETTINGS.PRICE_PICKUP_EXPRESS,
},
{
name: PICKUP_STANDARD,
enabled: SETTINGS.ALLOW_PICKUP_LOCATIONS,
price: SETTINGS.PRICE_PICKUP,
selected: true,
},
],
},
formConfigDelivery,
formConfigShipmentOptions,
formConfigPickup,
];
28 changes: 28 additions & 0 deletions src/data/defaultCarrierConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as CARRIERS from '@/data/keys/carrierKeys';
import * as CONFIG from '@/data/keys/configKeys';

/**
* All settings are enabled by default, this object is used to turn off settings individually.
*
* @type {Object<MyParcel.CarrierName, Object>}
*/
export const defaultCarrierConfig = {
[CARRIERS.POSTNL]: {
[CONFIG.ALLOW_SATURDAY_DELIVERY]: false,
},
[CARRIERS.BPOST]: {
[CONFIG.ALLOW_MORNING_DELIVERY]: false,
[CONFIG.ALLOW_EVENING_DELIVERY]: false,
[CONFIG.ALLOW_MONDAY_DELIVERY]: false,
[CONFIG.ALLOW_ONLY_RECIPIENT]: false,
[CONFIG.ALLOW_SIGNATURE]: false,
[CONFIG.ALLOW_PICKUP_EXPRESS]: false,
},
[CARRIERS.DPD]: {
[CONFIG.ALLOW_MORNING_DELIVERY]: false,
[CONFIG.ALLOW_EVENING_DELIVERY]: false,
[CONFIG.ALLOW_MONDAY_DELIVERY]: false,
[CONFIG.ALLOW_ONLY_RECIPIENT]: false,
[CONFIG.ALLOW_PICKUP_EXPRESS]: false,
},
};
5 changes: 5 additions & 0 deletions src/data/keys/carrierKeys.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/** @type {MyParcel.CarrierName} */
export const POSTNL = 'postnl';

/** @type {MyParcel.CarrierName} */
export const DPD = 'dpd';

/** @type {MyParcel.CarrierName} */
export const BPOST = 'bpost';
1 change: 1 addition & 0 deletions src/data/keys/stringsKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const NUMBER = 'number';
export const ADDRESS_NOT_FOUND = 'addressNotFound';

export const CLOSED = 'closed';
export const DISCOUNT = 'discount';
export const FREE = 'free';
export const FROM = 'from';
export const LOAD_MORE = 'loadMore';
Expand Down
37 changes: 20 additions & 17 deletions src/data/locales/be/config.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
import * as SETTINGS from '@/data/keys/configKeys';
import * as CARRIERS from '@/data/keys/carrierKeys';
import * as CONFIG from '@/data/keys/configKeys';
import { DEFAULT_MAX_PAGE_ITEMS, DEFAULT_PRICE } from '@/data/keys/settingsConsts';
import { getDefaultCarrierConfig } from '@/delivery-options/data/carriers/getDefaultCarrierConfig';

export const config = {
[SETTINGS.LOCALE]: 'nl-BE',
[CONFIG.LOCALE]: 'nl-BE',

[SETTINGS.ALLOW_SATURDAY_DELIVERY]: true,
[SETTINGS.PRICE_SATURDAY_DELIVERY]: DEFAULT_PRICE,
[SETTINGS.FRIDAY_CUTOFF_TIME]: '15:00',
[CONFIG.ALLOW_SATURDAY_DELIVERY]: true,
[CONFIG.PRICE_SATURDAY_DELIVERY]: DEFAULT_PRICE,
[CONFIG.FRIDAY_CUTOFF_TIME]: '15:00',

/**
* BE pickup location distance is not based on the customer's address but to the center of the city so the distance is
* mostly irrelevant.
*/
[SETTINGS.FEATURE_PICKUP_SHOW_DISTANCE]: false,
[CONFIG.FEATURE_PICKUP_SHOW_DISTANCE]: false,

/**
* For the same reason as above, prefer the map view to the list view.
*/
[SETTINGS.FEATURE_PICKUP_LOCATIONS_DEFAULT_VIEW]: true,
[CONFIG.FEATURE_PICKUP_LOCATIONS_DEFAULT_VIEW]: true,

/**
* Show more pickup items by default for BE because it doesn't show the distance.
*/
[SETTINGS.FEATURE_MAX_PAGE_ITEMS]: DEFAULT_MAX_PAGE_ITEMS,
[CONFIG.FEATURE_MAX_PAGE_ITEMS]: DEFAULT_MAX_PAGE_ITEMS,

[SETTINGS.CARRIER_SETTINGS]: {
bpost: {
[SETTINGS.ALLOW_DELIVERY_OPTIONS]: true,
[SETTINGS.ALLOW_PICKUP_LOCATIONS]: true,
},
dpd: {
[SETTINGS.ALLOW_DELIVERY_OPTIONS]: true,
[SETTINGS.ALLOW_PICKUP_LOCATIONS]: true,
},
[CONFIG.CARRIER_SETTINGS]: {
...getDefaultCarrierConfig(CARRIERS.BPOST),
...getDefaultCarrierConfig(CARRIERS.DPD),
...getDefaultCarrierConfig(CARRIERS.POSTNL, {
[CONFIG.ALLOW_MONDAY_DELIVERY]: false,
[CONFIG.ALLOW_SATURDAY_DELIVERY]: false,
[CONFIG.ALLOW_MORNING_DELIVERY]: false,
[CONFIG.ALLOW_EVENING_DELIVERY]: false,
[CONFIG.ALLOW_PICKUP_EXPRESS]: false,
}),
},
};
6 changes: 2 additions & 4 deletions src/data/locales/nl/config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import * as CARRIERS from '@/data/keys/carrierKeys';
import * as CONFIG from '@/data/keys/configKeys';
import { getDefaultCarrierConfig } from '@/delivery-options/data/carriers/getDefaultCarrierConfig';

export const config = {
[CONFIG.LOCALE]: 'nl-NL',
[CONFIG.ALLOW_MONDAY_DELIVERY]: true,
[CONFIG.SATURDAY_CUTOFF_TIME]: '16:00',

[CONFIG.CARRIER_SETTINGS]: {
[CARRIERS.POSTNL]: {
[CONFIG.ALLOW_DELIVERY_OPTIONS]: true,
[CONFIG.ALLOW_PICKUP_LOCATIONS]: true,
},
...getDefaultCarrierConfig(CARRIERS.POSTNL),
},
};
Loading

0 comments on commit e393561

Please sign in to comment.