rerobe-js-orm 2.9.9 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,24 +5,24 @@ const Order_1 = require("../../models/Order");
|
|
|
5
5
|
const order_constants_1 = require("../../constants/order-constants");
|
|
6
6
|
class OrderFromFormState extends OrderFactory_1.default {
|
|
7
7
|
createOrder(fs) {
|
|
8
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
9
9
|
const currencyCode = fs.fields.currencyCode.inputValue || 'SEK';
|
|
10
10
|
const customer = fs.fields.customer.selectedValue || {};
|
|
11
11
|
const customerAttr = {
|
|
12
12
|
userId: (customer === null || customer === void 0 ? void 0 : customer.uid) || (customer === null || customer === void 0 ? void 0 : customer.documentId) || '',
|
|
13
|
-
customerName:
|
|
13
|
+
customerName: `${fs.fields.firstName.inputValue} ${fs.fields.lastName.inputValue}`.trim(),
|
|
14
14
|
email: fs.fields.email.inputValue || '',
|
|
15
15
|
phone: fs.fields.phone.inputValue || '',
|
|
16
|
-
customerUrl: ((
|
|
16
|
+
customerUrl: ((_a = fs.props) === null || _a === void 0 ? void 0 : _a.customerUrl) || '',
|
|
17
17
|
};
|
|
18
18
|
const discountsAttr = {
|
|
19
19
|
appliedDiscount: {
|
|
20
|
-
amount: ((
|
|
21
|
-
value: ((
|
|
22
|
-
title: fs.fields.presentmentData.selectedValue.discountTitlePresentment || ((
|
|
20
|
+
amount: ((_b = fs.fields) === null || _b === void 0 ? void 0 : _b.totalDiscount.inputValue) || 0,
|
|
21
|
+
value: ((_c = fs.fields) === null || _c === void 0 ? void 0 : _c.totalDiscount.inputValue) || 0,
|
|
22
|
+
title: fs.fields.presentmentData.selectedValue.discountTitlePresentment || ((_d = fs.fields) === null || _d === void 0 ? void 0 : _d.discountTitle.inputValue) || '',
|
|
23
23
|
valueType: 'FIXED_AMOUNT',
|
|
24
24
|
},
|
|
25
|
-
discountApplications: ((
|
|
25
|
+
discountApplications: ((_e = fs.props) === null || _e === void 0 ? void 0 : _e.discountApplications) || [],
|
|
26
26
|
creditDiscount: { amount: fs.fields.creditDiscount.inputValue || 0, currencyCode },
|
|
27
27
|
saleDiscount: { amount: fs.fields.saleDiscount.inputValue || 0, currencyCode },
|
|
28
28
|
additionalDiscount: { amount: fs.fields.additionalDiscount.inputValue || 0, currencyCode },
|
|
@@ -38,11 +38,11 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
38
38
|
zip: '',
|
|
39
39
|
};
|
|
40
40
|
const shippingAndLocationAttr = {
|
|
41
|
-
fulfillmentLocations: ((
|
|
41
|
+
fulfillmentLocations: ((_f = fs.fields.shippingInfo.selectedValue) === null || _f === void 0 ? void 0 : _f.productsLocationsMapping) || [],
|
|
42
42
|
shippingAddress: fs.fields.shippingType.selectedValue === order_constants_1.SHIPPING_TYPES.localPickUp
|
|
43
43
|
? initShippingAddress
|
|
44
44
|
: fs.fields.shippingAddress.selectedValue || initShippingAddress,
|
|
45
|
-
shippingDiscountAllocations: ((
|
|
45
|
+
shippingDiscountAllocations: ((_g = fs.props) === null || _g === void 0 ? void 0 : _g.shippingDiscountAllocations) || [],
|
|
46
46
|
shippingLine: fs.fields.shippingLine
|
|
47
47
|
? fs.fields.shippingLine.selectedValue
|
|
48
48
|
: {
|
|
@@ -93,12 +93,12 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
93
93
|
originalTotalPrice: { amount: fs.fields.originalTotalPrice.inputValue || 0, currencyCode },
|
|
94
94
|
};
|
|
95
95
|
const statusesAttr = {
|
|
96
|
-
state: ((
|
|
96
|
+
state: ((_h = fs.props) === null || _h === void 0 ? void 0 : _h.state) || Order_1.default.ORDER_STATES.draft,
|
|
97
97
|
financialStatus: fs.fields.financialStatus.selectedValue,
|
|
98
98
|
fulfillmentStatus: fs.fields.fulfillmentStatus.selectedValue,
|
|
99
|
-
statusUrl: ((
|
|
99
|
+
statusUrl: ((_j = fs.props) === null || _j === void 0 ? void 0 : _j.statusUrl) || '',
|
|
100
100
|
};
|
|
101
|
-
const orderAttributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, totalPricesAttr), presentmentTotalPricesAttr), discountsAttr), shippingAndLocationAttr), customerAttr), statusesAttr), { id: ((
|
|
101
|
+
const orderAttributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, totalPricesAttr), presentmentTotalPricesAttr), discountsAttr), shippingAndLocationAttr), customerAttr), statusesAttr), { id: ((_k = fs.props) === null || _k === void 0 ? void 0 : _k.id) || '', documentId: ((_l = fs.props) === null || _l === void 0 ? void 0 : _l.documentId) || '', name: ((_m = fs.props) === null || _m === void 0 ? void 0 : _m.name) || '', orderNumber: (_o = fs.props) === null || _o === void 0 ? void 0 : _o.orderNumber, ribbnOrderNumber: (_p = fs.props) === null || _p === void 0 ? void 0 : _p.ribbnOrderNumber, merchantId: ((_q = fs.props) === null || _q === void 0 ? void 0 : _q.merchantId) || '', currencyCode: fs.fields.currencyCode.inputValue, lineItems: fs.fields.lineItems.selectedValues || [], fulfillments: ((_r = fs.props) === null || _r === void 0 ? void 0 : _r.fulfillments) || [], refunds: ((_s = fs.props) === null || _s === void 0 ? void 0 : _s.refunds) || [], paymentType: fs.fields.paymentType.selectedValue, paymentMethod: fs.fields.paymentMethod.selectedValue || '', paymentDetails: fs.fields.paymentDetails.selectedValue || {}, notes: fs.fields.notes.inputValue || '', tags: fs.fields.tags.selectedValues || [], cancelReason: fs.fields.cancelReason.selectedValue || '', canceledAt: ((_t = fs.props) === null || _t === void 0 ? void 0 : _t.canceledAt) || '', processedAt: ((_u = fs.props) === null || _u === void 0 ? void 0 : _u.processedAt) || new Date().toUTCString(), createdAtTimestamp: 0, updatedAtTimestamp: 0 });
|
|
102
102
|
return new Order_1.default(Object.assign({}, orderAttributes));
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -97,13 +97,6 @@ class OrderFormState extends FormState_1.default {
|
|
|
97
97
|
// Update total price
|
|
98
98
|
this.fields.totalPrice.inputValue = Number(Number(this.fields.subtotalPrice.inputValue) - Number(this.fields.totalDiscount.inputValue) + Number(val)).toFixed(2);
|
|
99
99
|
}
|
|
100
|
-
customerChangeHandler(customer) {
|
|
101
|
-
this.fields.customer.selectedValue = customer;
|
|
102
|
-
this.fields.email.inputValue = (customer === null || customer === void 0 ? void 0 : customer.email) || '';
|
|
103
|
-
this.fields.phone.inputValue = (customer === null || customer === void 0 ? void 0 : customer.phone) || '';
|
|
104
|
-
this.fields.firstName.inputValue = (customer === null || customer === void 0 ? void 0 : customer.displayName) || (customer === null || customer === void 0 ? void 0 : customer.firstName) || '';
|
|
105
|
-
this.fields.lastName.inputValue = !(customer === null || customer === void 0 ? void 0 : customer.displayName) && (customer === null || customer === void 0 ? void 0 : customer.lastName) ? customer === null || customer === void 0 ? void 0 : customer.lastName : '';
|
|
106
|
-
}
|
|
107
100
|
fieldFactory(fieldType, fieldKey, fieldOptions) {
|
|
108
101
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
109
102
|
let options = fieldOptions || [];
|
|
@@ -111,10 +104,12 @@ class OrderFormState extends FormState_1.default {
|
|
|
111
104
|
if (fieldType === 'textInput') {
|
|
112
105
|
let inputValue = this.props[fieldKey] || '';
|
|
113
106
|
if (fieldKey === 'firstName') {
|
|
114
|
-
|
|
107
|
+
const { firstName } = this.utilities.getFirstNameAndLastNameFromDisplayName(this.props.customerName || '');
|
|
108
|
+
inputValue = firstName;
|
|
115
109
|
}
|
|
116
110
|
if (fieldKey === 'lastName') {
|
|
117
|
-
|
|
111
|
+
const { lastName } = this.utilities.getFirstNameAndLastNameFromDisplayName(this.props.customerName || '');
|
|
112
|
+
inputValue = lastName;
|
|
118
113
|
}
|
|
119
114
|
if (fieldKey === 'discountTitle') {
|
|
120
115
|
inputValue = ((_b = (_a = this.props) === null || _a === void 0 ? void 0 : _a.appliedDiscount) === null || _b === void 0 ? void 0 : _b.title) || '';
|
|
@@ -186,16 +181,15 @@ class OrderFormState extends FormState_1.default {
|
|
|
186
181
|
additionalDiscountPresentment: ((_y = this.props) === null || _y === void 0 ? void 0 : _y.additionalDiscountPresentment) || { amount: 0 },
|
|
187
182
|
};
|
|
188
183
|
}
|
|
189
|
-
const valid = !!this.props[fieldKey];
|
|
190
|
-
let onChangeHandler = (val) => this.singleSelectChangeHandler(fieldKey, val);
|
|
191
184
|
if (fieldKey === 'customer') {
|
|
192
185
|
selectedValue = {
|
|
193
186
|
uid: this.props.userId,
|
|
194
187
|
email: this.props.email,
|
|
195
188
|
displayName: this.props.customerName,
|
|
196
189
|
};
|
|
197
|
-
onChangeHandler = (val) => this.customerChangeHandler(val);
|
|
198
190
|
}
|
|
191
|
+
const valid = !!this.props[fieldKey];
|
|
192
|
+
const onChangeHandler = (val) => this.singleSelectChangeHandler(fieldKey, val);
|
|
199
193
|
if (fieldKey === 'shippingType') {
|
|
200
194
|
if ((_0 = (_z = this.opts) === null || _z === void 0 ? void 0 : _z.shippingTypeOptions) === null || _0 === void 0 ? void 0 : _0.length) {
|
|
201
195
|
options = this.utilities.uniqObjArray(this.opts.shippingTypeOptions, 'value');
|
|
@@ -17,4 +17,8 @@ export default class Utilities {
|
|
|
17
17
|
isProperString(name: any): boolean;
|
|
18
18
|
toProperString(name: any): string;
|
|
19
19
|
getAddressLabel(address: AddressInput): string;
|
|
20
|
+
getFirstNameAndLastNameFromDisplayName(displayName: string): {
|
|
21
|
+
firstName: string;
|
|
22
|
+
lastName: string;
|
|
23
|
+
};
|
|
20
24
|
}
|
package/lib/helpers/Utilities.js
CHANGED
|
@@ -137,5 +137,14 @@ class Utilities {
|
|
|
137
137
|
return res;
|
|
138
138
|
}, '');
|
|
139
139
|
}
|
|
140
|
+
getFirstNameAndLastNameFromDisplayName(displayName) {
|
|
141
|
+
const res = { firstName: '', lastName: '' };
|
|
142
|
+
const fixedDisplayName = displayName ? displayName.trim() : '';
|
|
143
|
+
if (fixedDisplayName) {
|
|
144
|
+
res.firstName = fixedDisplayName.split(' ')[0];
|
|
145
|
+
res.lastName = fixedDisplayName.split(' ').length > 1 ? fixedDisplayName.split(' ')[1] : '';
|
|
146
|
+
}
|
|
147
|
+
return res;
|
|
148
|
+
}
|
|
140
149
|
}
|
|
141
150
|
exports.default = Utilities;
|