import React from 'react'; import {useShopStore} from "./shop_store"; /** * Component that provides a base layout (aside/main) for the page. */ /* export function Layout({aside, main}) { static get defaultProps() { return { mobileSideMenuShouldOpen: false, }; } constructor(props) { super(props); this.state = { customconf: '', error: null, }; this.handleCustomConfig = this.handleCustomConfig.bind(this); this.handleClickLoad = this.handleClickLoad.bind(this); this.checkValidation = this.checkValidation.bind(this); // retrieve list of available pn const items_keys = Object.keys(props.items); this.list_pn = items_keys.map(function (key) { return props.items[key].name_number; }); } handleCustomConfig(e) { const value = e.target.value; this.checkValidation(value); } checkValidation(conf) { let conf_obj; try { conf_obj = JSON.parse(conf); } catch (e) { return this.setState({ ...this.state, customconf: conf, customconf_ready: null, error: 'invalid format', }); } if (!conf_obj) { return this.setState({ ...this.state, customconf: conf, customconf_ready: null, error: 'invalid format', }); } if ((!conf_obj.items || !conf_obj.type) && (Object.prototype.toString.call(conf_obj.items) !== '[object Array]' || Object.prototype.toString.call(conf_obj.type) !== '[object String]')) { return this.setState({ ...this.state, customconf: conf, customconf_ready: null, error: 'invalid format', }); } if (conf_obj.type !== "desktop" && conf_obj.type !== "rack") { return this.setState({ ...this.state, customconf: conf, customconf_ready: null, error: 'invalid format', }); } conf_obj.items.map(function (item) { try { return JSON.parse(item); } catch (e) { return null; } }); conf_obj.items = conf_obj.items.filter(function (item) { return item; }); if (conf_obj.items.filter(function (item) { return Object.prototype.toString.call(item) !== '[object Object]' || !item.pn || Object.prototype.toString.call(item.pn) !== '[object String]'; }).length > 0) { return this.setState({ ...this.state, customconf: conf, customconf_ready: null, error: 'invalid format', }); } conf_obj.items = conf_obj.items.map(function (item) { return { pn: item.pn, options: item.options ? item.options : null, }; }); const self = this; const unknow_pn = conf_obj.items.filter(function (item_pn) { return self.list_pn.includes(item_pn.pn) === false; }).map(function (item_pn) { return item_pn.pn; }); if (unknow_pn.length > 0) { return this.setState({ ...this.state, customconf: conf, customconf_ready: null, error: `${unknow_pn.join(', ')} unknown${unknow_pn.length > 1 ? 's':''} pn number`, }); } this.setState({ ...this.state, customconf: conf, error: null, customconf_ready: conf_obj, }); } handleClickLoad() { this.checkValidation(this.state.customconf); if (this.props.onClickLoadCustomConf) { this.props.onClickLoadCustomConf(this.state.customconf_ready); } } render() { const { aside, main, mobileSideMenuShouldOpen, isMobile, newCardJustAdded, onClickToggleMobileSideMenu, onClickCloseRFQFeedback, showRFQFeedback, RFQBodyType, RFQBodyOrder, } = this.props; return (