Add options for the cards #93
|
@ -258,6 +258,7 @@ class Layout extends React.PureComponent {
|
||||||
conf_obj.items = conf_obj.items.map(function (item) {
|
conf_obj.items = conf_obj.items.map(function (item) {
|
||||||
return {
|
return {
|
||||||
pn: item.pn,
|
pn: item.pn,
|
||||||
|
options: item.options ? item.options : null,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -606,7 +607,6 @@ class ProductCartItem extends React.PureComponent {
|
||||||
|
|
||||||
|
|
||||||
if (data && data.options) {
|
if (data && data.options) {
|
||||||
console.log(data.options_data);
|
|
||||||
options = data.options;
|
options = data.options;
|
||||||
if (!data.options_data) data.options_data = {};
|
if (!data.options_data) data.options_data = {};
|
||||||
options_data = data.options_data;
|
options_data = data.options_data;
|
||||||
|
@ -867,7 +867,6 @@ class Cart extends React.PureComponent {
|
||||||
let itemData;
|
let itemData;
|
||||||
if (data.itemsData && index in data.itemsData) {
|
if (data.itemsData && index in data.itemsData) {
|
||||||
itemData = data.itemsData[index];
|
itemData = data.itemsData[index];
|
||||||
console.log(itemData.options_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1422,7 +1421,7 @@ class OrderSumary extends React.PureComponent {
|
||||||
let alert;
|
let alert;
|
||||||
let warning;
|
let warning;
|
||||||
|
|
||||||
if (itemsData[index]) {
|
if (itemsData[index] && itemsData[index].warnings) {
|
||||||
alert = itemsData[index];
|
alert = itemsData[index];
|
||||||
const warningsKeys = Object.keys(alert.warnings);
|
const warningsKeys = Object.keys(alert.warnings);
|
||||||
if (warningsKeys && warningsKeys.length > 0) {
|
if (warningsKeys && warningsKeys.length > 0) {
|
||||||
|
@ -1459,7 +1458,7 @@ class OrderSumary extends React.PureComponent {
|
||||||
) : (
|
) : (
|
||||||
<img
|
<img
|
||||||
style={{'marginLeft': '10px'}}
|
style={{'marginLeft': '10px'}}
|
||||||
className="alert-warning"
|
className="alert-info"
|
||||||
src="/images/shop/icon-customize.svg"
|
src="/images/shop/icon-customize.svg"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -1827,11 +1826,14 @@ class Shop extends React.PureComponent {
|
||||||
type: this.state.currentMode,
|
type: this.state.currentMode,
|
||||||
};
|
};
|
||||||
const clonedCart = Array.from(this.state.columns.cart.items);
|
const clonedCart = Array.from(this.state.columns.cart.items);
|
||||||
console.log(clonedCart);
|
const clonedCartData = Array.from(this.state.columns.cart.itemsData);
|
||||||
|
console.log(clonedCartData);
|
||||||
for (const i in clonedCart) {
|
for (const i in clonedCart) {
|
||||||
const item = clonedCart[i];
|
const item = clonedCart[i];
|
||||||
|
const item_data = clonedCartData[i];
|
||||||
crate.items.push({
|
crate.items.push({
|
||||||
'pn': item.name_number
|
'pn': item.name_number,
|
||||||
|
'options': item_data.options_data ? item_data.options_data : null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1855,9 +1857,11 @@ class Shop extends React.PureComponent {
|
||||||
if (!customconf) {return; }
|
if (!customconf) {return; }
|
||||||
|
|
||||||
const items = this.props.data.items;
|
const items = this.props.data.items;
|
||||||
|
console.trace(customconf);
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
let new_items = [];
|
let new_items = [];
|
||||||
|
let new_items_data = [];
|
||||||
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -1878,14 +1882,15 @@ class Shop extends React.PureComponent {
|
||||||
...items[key],
|
...items[key],
|
||||||
}, {
|
}, {
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
|
options_data: item.options ? item.options : null,
|
||||||
}));
|
}));
|
||||||
|
new_items_data.push({options_data: item.options? item.options : null});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
...this.state,
|
...this.state,
|
||||||
columns: {
|
columns: {
|
||||||
|
@ -1893,6 +1898,7 @@ class Shop extends React.PureComponent {
|
||||||
cart: {
|
cart: {
|
||||||
...this.state.columns.cart,
|
...this.state.columns.cart,
|
||||||
items: new_items,
|
items: new_items,
|
||||||
|
itemsData: new_items_data,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
currentMode: customconf.type,
|
currentMode: customconf.type,
|
||||||
|
@ -1906,10 +1912,13 @@ class Shop extends React.PureComponent {
|
||||||
type: this.state.currentMode,
|
type: this.state.currentMode,
|
||||||
};
|
};
|
||||||
const clonedCart = Array.from(this.state.columns.cart.items);
|
const clonedCart = Array.from(this.state.columns.cart.items);
|
||||||
|
const clonedCartData = Array.from(this.state.columns.cart.itemsData);
|
||||||
for (const i in clonedCart) {
|
for (const i in clonedCart) {
|
||||||
const item = clonedCart[i];
|
const item = clonedCart[i];
|
||||||
|
const item_data = clonedCartData[i];
|
||||||
crate.items.push({
|
crate.items.push({
|
||||||
'pn': item.name_number,
|
'pn': item.name_number,
|
||||||
|
'options': item_data.options_data ? item_data.options_data : null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2042,8 +2051,6 @@ class Shop extends React.PureComponent {
|
||||||
|
|
||||||
const itemsCloned = Array.from(newItems);
|
const itemsCloned = Array.from(newItems);
|
||||||
const itemsData = [];
|
const itemsData = [];
|
||||||
console.log(prevItems);
|
|
||||||
console.log(this.state);
|
|
||||||
const rules = {};
|
const rules = {};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2136,9 +2143,6 @@ class Shop extends React.PureComponent {
|
||||||
rules[ddkali.rules.follow.type] = {...ddkali.rules.follow};
|
rules[ddkali.rules.follow.type] = {...ddkali.rules.follow};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(idx);
|
|
||||||
if (idx in this.state.columns.cart.itemsData && this.state.columns.cart.itemsData[idx].options_data)
|
|
||||||
itemsData[idx].options_data = this.state.columns.cart.itemsData[idx].options_data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idxK.length === 0) {
|
if (idxK.length === 0) {
|
||||||
|
@ -2322,6 +2326,13 @@ class Shop extends React.PureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemsCloned.forEach((_elem, idx) => {
|
||||||
|
if (!(idx in itemsData)) itemsData[idx] = {};
|
||||||
|
if (idx in this.state.columns.cart.itemsData && this.state.columns.cart.itemsData[idx].options_data) {
|
||||||
|
itemsData[idx].options_data = this.state.columns.cart.itemsData[idx].options_data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// update state with rules
|
// update state with rules
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import React, {Component} from "react";
|
import React, {Component} from "react";
|
||||||
import jsonLogic from 'json-logic-js';
|
import jsonLogic from 'json-logic-js';
|
||||||
import {v4 as uuidv4} from 'uuid';
|
|
||||||
|
|
||||||
// https://stackoverflow.com/a/70511311
|
// https://stackoverflow.com/a/70511311
|
||||||
const trueTypeOf = (obj) => Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
|
const trueTypeOf = (obj) => Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
|
||||||
|
@ -15,7 +14,7 @@ class Radio extends Component {
|
||||||
target: props.target,
|
target: props.target,
|
||||||
outvar: props.outvar,
|
outvar: props.outvar,
|
||||||
variants: props.variants,
|
variants: props.variants,
|
||||||
variant: props.variants[0],
|
variant: props.outvar in props.data ? props.data[props.outvar] : props.variants[0],
|
||||||
id: props.id
|
id: props.id
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,8 +59,8 @@ class Radio extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function RadioWrapper(target, id, {title, variants, outvar}) {
|
function RadioWrapper(target, id, data, {title, variants, outvar}) {
|
||||||
return <Radio target={target} title={title} variants={variants} outvar={outvar} key={id} id={id}/>;
|
return <Radio target={target} title={title} variants={variants} outvar={outvar} key={id} id={id} data={data} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,7 +93,7 @@ export default function ProcessOptions({options, data, target, id}) {
|
||||||
trueTypeOf(options.args) === "object"
|
trueTypeOf(options.args) === "object"
|
||||||
) {
|
) {
|
||||||
if (options.type in componentsList) {
|
if (options.type in componentsList) {
|
||||||
return componentsList[options.type](target, id + options.type, options.args);
|
return componentsList[options.type](target, id + options.type, data, options.args);
|
||||||
} else {
|
} else {
|
||||||
return componentsList["Default"](options.type, id + "missing");
|
return componentsList["Default"](options.type, id + "missing");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue