|
|
@@ -38,6 +38,86 @@ const hasMatchingProperties = (source, target) => {
|
|
38
|
38
|
return Object.entries(target).every(([key, value]) => source[key] === value);
|
|
39
|
39
|
};
|
|
40
|
40
|
|
|
|
41
|
+const renderShopifyRichTextNode = (node, key = "node") => {
|
|
|
42
|
+ if (!node) return null
|
|
|
43
|
+
|
|
|
44
|
+ if (node.type === "text") {
|
|
|
45
|
+ const textValue = node.value || ""
|
|
|
46
|
+
|
|
|
47
|
+ if (node.bold) {
|
|
|
48
|
+ return <Box component="strong" key={key} sx={{ fontWeight: 700 }}>{textValue}</Box>
|
|
|
49
|
+ }
|
|
|
50
|
+
|
|
|
51
|
+ return textValue
|
|
|
52
|
+ }
|
|
|
53
|
+
|
|
|
54
|
+ const children = (node.children || []).map((child, index) => renderShopifyRichTextNode(child, `${key}-${index}`))
|
|
|
55
|
+
|
|
|
56
|
+ if (node.type === "root") {
|
|
|
57
|
+ return <>{children}</>
|
|
|
58
|
+ }
|
|
|
59
|
+
|
|
|
60
|
+ if (node.type === "paragraph") {
|
|
|
61
|
+ return (
|
|
|
62
|
+ <Typography component="p" key={key} sx={{ mt: 0, mb: 1.5 }}>
|
|
|
63
|
+ {children}
|
|
|
64
|
+ </Typography>
|
|
|
65
|
+ )
|
|
|
66
|
+ }
|
|
|
67
|
+
|
|
|
68
|
+ if (node.type === "list") {
|
|
|
69
|
+ return (
|
|
|
70
|
+ <Box
|
|
|
71
|
+ component={node.listType === "ordered" ? "ol" : "ul"}
|
|
|
72
|
+ key={key}
|
|
|
73
|
+ sx={{ mt: 0, mb: 1.5, pl: 2.5 }}
|
|
|
74
|
+ >
|
|
|
75
|
+ {children}
|
|
|
76
|
+ </Box>
|
|
|
77
|
+ )
|
|
|
78
|
+ }
|
|
|
79
|
+
|
|
|
80
|
+ if (node.type === "list-item") {
|
|
|
81
|
+ return (
|
|
|
82
|
+ <Box component="li" key={key} sx={{ mb: 0.5 }}>
|
|
|
83
|
+ {children}
|
|
|
84
|
+ </Box>
|
|
|
85
|
+ )
|
|
|
86
|
+ }
|
|
|
87
|
+
|
|
|
88
|
+ if (node.type === "heading") {
|
|
|
89
|
+ return (
|
|
|
90
|
+ <Typography component={`h${node.level || 3}`} key={key} sx={{ mt: 0, mb: 1, fontWeight: 700 }}>
|
|
|
91
|
+ {children}
|
|
|
92
|
+ </Typography>
|
|
|
93
|
+ )
|
|
|
94
|
+ }
|
|
|
95
|
+
|
|
|
96
|
+ if (node.type === "link") {
|
|
|
97
|
+ return (
|
|
|
98
|
+ <Box component="a" key={key} href={node.url} target="_blank" rel="noreferrer" sx={{ color: "inherit" }}>
|
|
|
99
|
+ {children}
|
|
|
100
|
+ </Box>
|
|
|
101
|
+ )
|
|
|
102
|
+ }
|
|
|
103
|
+
|
|
|
104
|
+ return <Box key={key}>{children}</Box>
|
|
|
105
|
+}
|
|
|
106
|
+
|
|
|
107
|
+const renderShopifyRichText = (value) => {
|
|
|
108
|
+ if (!value) return null
|
|
|
109
|
+
|
|
|
110
|
+ try {
|
|
|
111
|
+ return renderShopifyRichTextNode(JSON.parse(value))
|
|
|
112
|
+ } catch (error) {
|
|
|
113
|
+ return (
|
|
|
114
|
+ <Typography component="p" sx={{ mt: 0, mb: 1.5 }}>
|
|
|
115
|
+ {value}
|
|
|
116
|
+ </Typography>
|
|
|
117
|
+ )
|
|
|
118
|
+ }
|
|
|
119
|
+}
|
|
|
120
|
+
|
|
41
|
121
|
const ProductDetails = () => {
|
|
42
|
122
|
|
|
43
|
123
|
const dispatch = useDispatch()
|
|
|
@@ -307,7 +387,6 @@ const ProductDetails = () => {
|
|
307
|
387
|
})
|
|
308
|
388
|
|
|
309
|
389
|
const emptyInfoPanel = (row) => (
|
|
310
|
|
- // Old empty expanded panel kept for reference:
|
|
311
|
390
|
// expandedInfoRows[row] && (
|
|
312
|
391
|
// <Box
|
|
313
|
392
|
// sx={{
|
|
|
@@ -319,6 +398,33 @@ const ProductDetails = () => {
|
|
319
|
398
|
null
|
|
320
|
399
|
)
|
|
321
|
400
|
|
|
|
401
|
+ const materialMetafield = product?.metafields?.material
|
|
|
402
|
+
|
|
|
403
|
+ const materialPanel = (
|
|
|
404
|
+ <Box
|
|
|
405
|
+ sx={{
|
|
|
406
|
+ maxHeight: expandedInfoRows.material ? 600 : 0,
|
|
|
407
|
+ overflow: "hidden",
|
|
|
408
|
+ borderBottom: "1px solid #DDD",
|
|
|
409
|
+ transition: "max-height 0.25s ease-in-out"
|
|
|
410
|
+ }}
|
|
|
411
|
+ >
|
|
|
412
|
+ <Box
|
|
|
413
|
+ sx={{
|
|
|
414
|
+ color: "text.secondary",
|
|
|
415
|
+ minHeight: materialMetafield?.value ? 0 : 28,
|
|
|
416
|
+ fontSize: {
|
|
|
417
|
+ xs: "0.875rem",
|
|
|
418
|
+ md: "1rem"
|
|
|
419
|
+ },
|
|
|
420
|
+ lineHeight: 1.6
|
|
|
421
|
+ }}
|
|
|
422
|
+ >
|
|
|
423
|
+ {renderShopifyRichText(materialMetafield?.value)}
|
|
|
424
|
+ </Box>
|
|
|
425
|
+ </Box>
|
|
|
426
|
+ )
|
|
|
427
|
+
|
|
322
|
428
|
const productDetailsPanel = (
|
|
323
|
429
|
<Box
|
|
324
|
430
|
sx={{
|
|
|
@@ -726,14 +832,19 @@ const ProductDetails = () => {
|
|
726
|
832
|
{/* Material */}
|
|
727
|
833
|
<Box
|
|
728
|
834
|
onClick={() => toggleInfoRow("material")}
|
|
729
|
|
- sx={infoRowSx(expandedInfoRows.material)}
|
|
|
835
|
+ sx={{
|
|
|
836
|
+ ...infoRowSx(expandedInfoRows.material),
|
|
|
837
|
+ pb: expandedInfoRows.material ? 5 : 2,
|
|
|
838
|
+ pb: 2,
|
|
|
839
|
+ borderBottom: "none"
|
|
|
840
|
+ }}
|
|
730
|
841
|
>
|
|
731
|
842
|
<Typography variant="body2" sx={{ textTransform: "uppercase", fontWeight: "400", fontSize: { xs: "0.875rem", md: "1.1rem" } }}>
|
|
732
|
843
|
Material
|
|
733
|
844
|
</Typography>
|
|
734
|
845
|
{expandedInfoRows.material ? <RemoveIcon sx={{ fontSize: 18 }} /> : <AddIcon sx={{ fontSize: 18 }} />}
|
|
735
|
846
|
</Box>
|
|
736
|
|
- {emptyInfoPanel("material")}
|
|
|
847
|
+ {materialPanel}
|
|
737
|
848
|
|
|
738
|
849
|
{/* Care Instruction */}
|
|
739
|
850
|
<Box
|