Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
},
"scripts": {
"start-react": "react-scripts start",
"build": "react-scripts build",
"build": "CI=false NODE_OPTIONS=--openssl-legacy-provider react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"start": "node server.js"
"start": "node server.js",
"postinstall": "node scripts/patch-postcss-safe-parser.js"
},
"eslintConfig": {
"extends": [
Expand Down
43 changes: 43 additions & 0 deletions scripts/patch-postcss-safe-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const fs = require('fs');
const path = require('path');

const safeParserPath = path.join(
process.cwd(),
'node_modules',
'postcss-safe-parser',
'lib',
'safe-parser.js'
);

if (!fs.existsSync(safeParserPath)) {
console.log('[patch-postcss-safe-parser] postcss-safe-parser not installed; skipping.');
process.exit(0);
}

const original = fs.readFileSync(safeParserPath, 'utf8');

const headerPattern = /^let tokenizer = require\('postcss\/lib\/tokenize(?:\.js)?'\)\nlet Comment = require\('postcss\/lib\/comment(?:\.js)?'\)\nlet Parser = require\('postcss\/lib\/parser(?:\.js)?'\)\n/;

if (!headerPattern.test(original)) {
console.log('[patch-postcss-safe-parser] unsupported file format; skipping.');
process.exit(0);
}

const replacement = [
"const path = require('path')",
"const postcssLibDir = path.dirname(require.resolve('postcss'))",
"let tokenizer = require(path.join(postcssLibDir, 'tokenize.js'))",
"let Comment = require(path.join(postcssLibDir, 'comment.js'))",
"let Parser = require(path.join(postcssLibDir, 'parser.js'))",
''
].join('\n');

const patched = original.replace(headerPattern, replacement);

if (original === patched) {
console.log('[patch-postcss-safe-parser] no changes needed.');
process.exit(0);
}

fs.writeFileSync(safeParserPath, patched, 'utf8');
console.log('[patch-postcss-safe-parser] applied.');
38 changes: 29 additions & 9 deletions src/routes/FloorProfile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ class FloorProfile extends React.Component {
requestStockInfo = async () => {
let { id: floor_id } = this.props.floor;
let mil_type = this.getStateMilTypeOrDefaultMilType()

let { floor } = this.props;
let variation = floor.Variations.find(x => x.attributes[0].option.split(" ")[0] == mil_type)
let variation = this.getMatchingVariation({ floor, mil_type })
if (!variation) {
this.setState({ stock_info: undefined })
return { boxes: 0, pallets: 0, square_feet_available: 0, price_per_square_foot: 0 }
}
let {
stock_quantity: boxes,
price: price_per_square_foot
Expand Down Expand Up @@ -74,18 +78,33 @@ class FloorProfile extends React.Component {
console.log({available_boxes, desired_boxes})
this.setState({ available: available_boxes >= desired_boxes })
}
getStateMilTypeOrDefaultMilType = () => this.state.selected.mil_type || (this.props.floor &&
Number(this.props.floor.attributes.find(x => x.name === "Wear Layer").options[0].split(" ")[0])
)
getWearLayerOptions = () => {
let floorAttributes = (this.props.floor && this.props.floor.attributes) || []
let wearLayerAttribute = floorAttributes.find(x => x.name === "Wear Layer")
let wearLayerOptions = wearLayerAttribute && wearLayerAttribute.options
if (!Array.isArray(wearLayerOptions)) return []
return wearLayerOptions.map(x => Number(x.split(" ")[0])).filter(Boolean)
}
getVariationMilType = variation => {
let option = variation && variation.attributes && variation.attributes[0] && variation.attributes[0].option
if (!option) return undefined
return Number(String(option).split(" ")[0])
}
getMatchingVariation = ({ floor, mil_type }) => {
let variations = floor && Array.isArray(floor.Variations) ? floor.Variations : []
return variations.find(x => this.getVariationMilType(x) == mil_type) || variations[0]
}
getStateMilTypeOrDefaultMilType = () => this.state.selected.mil_type || this.getWearLayerOptions()[0]
getFloorMilTypesOptionsJSX = ({SelectedMilType}) => {
let mil_types = this.props.floor.attributes.find(x => x.name === "Wear Layer").options.map(x => Number(x.split(" ")[0]))
let mil_types = this.getWearLayerOptions()
return (
<div className="browse-inside__info">
<p className="bi-equal">Wear Layer:</p>
<div className="browse-inside__radios">
{
mil_types.map(x => (
<div
key={x}
style={{ cursor: "pointer" }}
onClick={this.onSelectedChange("mil_type")(x)}
className={SelectedMilType == x ? "" : "opacity_point_3"}
Expand Down Expand Up @@ -119,6 +138,7 @@ class FloorProfile extends React.Component {
let { loading, error, floor } = this.props;

if (loading) return <LoadingPage/>
if (!floor) return <LoadingPage/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle error before floor-null loading fallback

When the floor fetch fails (for example a 404), Redux can provide error while floor remains undefined. With the new if (!floor) return <LoadingPage/> check placed before the error branch, the component now exits early and never renders E404 or ERROR, leaving users on a permanent loading state for failed requests.

Useful? React with 👍 / 👎.

if (error) {
if (error && error.response && error.response.status === 404){
return <E404/>
Expand All @@ -127,12 +147,12 @@ class FloorProfile extends React.Component {
return "ERROR"
}
let mil_type = this.getStateMilTypeOrDefaultMilType()
let variation = floor.Variations.find(x => x.attributes[0].option.split(" ")[0] == mil_type)
let variation = this.getMatchingVariation({ floor, mil_type })
console.log({mil_type,variation})
let square_feet_info = global.sqft_to_boxes(this.state.selected.square_feet)
let price_per_sqft = this.state.stock_info ? this.state.stock_info.price_per_square_foot : undefined
console.log({square_feet_info,price_per_sqft})
let price = square_feet_info.val * variation.price
let price = square_feet_info.val * (variation ? variation.price : 0)
return (
<section className="browse">
<Header/>
Expand Down Expand Up @@ -321,4 +341,4 @@ let mapStateToProps = (state,props) => {
}
return { loading, error, floor }
}
export default compose(withRouter,connect(mapStateToProps, { getSingleFloor }))(FloorProfile);
export default compose(withRouter,connect(mapStateToProps, { getSingleFloor }))(FloorProfile);