tee3apps-cms-sdk-react 0.0.14 → 0.0.16
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.
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/PageComponents/Visual-Components/GroupProductComponent.tsx +86 -4
- package/src/PageComponents/Visual-Components/Styles/ProductListViewOne.tsx +69 -8
- package/src/PageComponents/Visual-Components/Styles/ProductListViewTwo.tsx +70 -9
- package/src/PageComponents/Visual-Components/TabComponent.tsx +261 -67
package/package.json
CHANGED
|
@@ -3,6 +3,83 @@ import ProductListViewOne from '../Visual-Components/Styles/ProductListViewOne';
|
|
|
3
3
|
import ProductListViewTwo from '../Visual-Components/Styles/ProductListViewTwo';
|
|
4
4
|
import { Linodeurl } from '../../const';
|
|
5
5
|
|
|
6
|
+
// Utility function to extract price value from different formats
|
|
7
|
+
const getPriceValue = (price: any): number => {
|
|
8
|
+
if (price === null || price === undefined) return 0;
|
|
9
|
+
|
|
10
|
+
// If it's already a number
|
|
11
|
+
if (typeof price === 'number') {
|
|
12
|
+
return isNaN(price) ? 0 : price;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// If it's an object with $numberDecimal (but not an array)
|
|
16
|
+
if (typeof price === 'object' && price !== null && !Array.isArray(price)) {
|
|
17
|
+
if (price.$numberDecimal !== undefined && price.$numberDecimal !== null) {
|
|
18
|
+
const value = parseFloat(String(price.$numberDecimal));
|
|
19
|
+
return isNaN(value) ? 0 : value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// If it's a string, try to parse it
|
|
24
|
+
if (typeof price === 'string') {
|
|
25
|
+
const value = parseFloat(price);
|
|
26
|
+
return isNaN(value) ? 0 : value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return 0;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Utility function to get price from pricing array (mrp, costPrice, nlcPrice)
|
|
33
|
+
const getPriceFromPricingArray = (pricingArray: any[]): number => {
|
|
34
|
+
if (!Array.isArray(pricingArray) || pricingArray.length === 0) return 0;
|
|
35
|
+
|
|
36
|
+
// First, try to find the default price with default currency
|
|
37
|
+
const defaultPrice = pricingArray.find(
|
|
38
|
+
(item: any) => item.isDefault === true && item.isDefaultCurrency === true
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (defaultPrice && defaultPrice.price) {
|
|
42
|
+
return getPriceValue(defaultPrice.price);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Fallback: find any default price
|
|
46
|
+
const anyDefault = pricingArray.find((item: any) => item.isDefault === true);
|
|
47
|
+
if (anyDefault && anyDefault.price) {
|
|
48
|
+
return getPriceValue(anyDefault.price);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Fallback: use first item
|
|
52
|
+
if (pricingArray[0] && pricingArray[0].price) {
|
|
53
|
+
return getPriceValue(pricingArray[0].price);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return 0;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Utility function to get MRP and Selling Price from product pricing object
|
|
60
|
+
const getProductPrices = (product: any) => {
|
|
61
|
+
// Use pricing object first, fallback to price for backward compatibility
|
|
62
|
+
const mrp = product.pricing?.mrp ? getPriceFromPricingArray(product.pricing.mrp) : 0;
|
|
63
|
+
const sellingPrice = product.pricing?.nlcPrice
|
|
64
|
+
? getPriceFromPricingArray(product.pricing.nlcPrice)
|
|
65
|
+
: product.pricing?.costPrice
|
|
66
|
+
? getPriceFromPricingArray(product.pricing.costPrice)
|
|
67
|
+
: 0;
|
|
68
|
+
|
|
69
|
+
// Fallback to old price structure if pricing is not available
|
|
70
|
+
const fallbackMRP = product.price?.MRP
|
|
71
|
+
? getPriceValue(product.price.MRP)
|
|
72
|
+
: 0;
|
|
73
|
+
const fallbackSP = product.price?.SP
|
|
74
|
+
? getPriceValue(product.price.SP)
|
|
75
|
+
: 0;
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
mrp: mrp || fallbackMRP,
|
|
79
|
+
sellingPrice: sellingPrice || fallbackSP
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
6
83
|
|
|
7
84
|
interface Product {
|
|
8
85
|
_id: string;
|
|
@@ -127,7 +204,7 @@ const GroupProductComponent: React.FC<GroupProductComponentMainProps> = ({
|
|
|
127
204
|
};
|
|
128
205
|
|
|
129
206
|
const products = getProducts();
|
|
130
|
-
|
|
207
|
+
|
|
131
208
|
// Helper function to render product based on style
|
|
132
209
|
const renderProduct = (product: Product, key: string) => {
|
|
133
210
|
if (currentstyle === 'STYLE1') {
|
|
@@ -207,9 +284,14 @@ const GroupProductComponent: React.FC<GroupProductComponentMainProps> = ({
|
|
|
207
284
|
}}
|
|
208
285
|
>
|
|
209
286
|
{typeof product.name === 'object' ? product.name.all : product.name}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
287
|
+
{(() => {
|
|
288
|
+
const prices = getProductPrices(product);
|
|
289
|
+
return prices.sellingPrice > 0 ? (
|
|
290
|
+
<h1 style={{ fontSize: '16px', fontWeight: '700', color: '#333' }}>
|
|
291
|
+
₹{prices.sellingPrice.toLocaleString("en-IN")}
|
|
292
|
+
</h1>
|
|
293
|
+
) : null;
|
|
294
|
+
})()}
|
|
213
295
|
</div>
|
|
214
296
|
)}
|
|
215
297
|
</div>
|
|
@@ -2,6 +2,59 @@ import React from "react";
|
|
|
2
2
|
import "./product-list-view-one.css";
|
|
3
3
|
import { Linodeurl } from '../../../const';
|
|
4
4
|
|
|
5
|
+
// Utility function to extract price value from different formats
|
|
6
|
+
const getPriceValue = (price: any): number => {
|
|
7
|
+
if (price === null || price === undefined) return 0;
|
|
8
|
+
|
|
9
|
+
// If it's already a number
|
|
10
|
+
if (typeof price === 'number') {
|
|
11
|
+
return isNaN(price) ? 0 : price;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// If it's an object with $numberDecimal (but not an array)
|
|
15
|
+
if (typeof price === 'object' && price !== null && !Array.isArray(price)) {
|
|
16
|
+
if (price.$numberDecimal !== undefined && price.$numberDecimal !== null) {
|
|
17
|
+
const value = parseFloat(String(price.$numberDecimal));
|
|
18
|
+
return isNaN(value) ? 0 : value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// If it's a string, try to parse it
|
|
23
|
+
if (typeof price === 'string') {
|
|
24
|
+
const value = parseFloat(price);
|
|
25
|
+
return isNaN(value) ? 0 : value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return 0;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Utility function to get price from pricing array (mrp, costPrice, nlcPrice)
|
|
32
|
+
const getPriceFromPricingArray = (pricingArray: any[]): number => {
|
|
33
|
+
if (!Array.isArray(pricingArray) || pricingArray.length === 0) return 0;
|
|
34
|
+
|
|
35
|
+
// First, try to find the default price with default currency
|
|
36
|
+
const defaultPrice = pricingArray.find(
|
|
37
|
+
(item: any) => item.isDefault === true && item.isDefaultCurrency === true
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (defaultPrice && defaultPrice.price) {
|
|
41
|
+
return getPriceValue(defaultPrice.price);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Fallback: find any default price
|
|
45
|
+
const anyDefault = pricingArray.find((item: any) => item.isDefault === true);
|
|
46
|
+
if (anyDefault && anyDefault.price) {
|
|
47
|
+
return getPriceValue(anyDefault.price);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Fallback: use first item
|
|
51
|
+
if (pricingArray[0] && pricingArray[0].price) {
|
|
52
|
+
return getPriceValue(pricingArray[0].price);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return 0;
|
|
56
|
+
};
|
|
57
|
+
|
|
5
58
|
const ProductListViewOne = (props: any) => {
|
|
6
59
|
const [target, setTarget] = React.useState("_blank");
|
|
7
60
|
console.warn(props)
|
|
@@ -23,13 +76,21 @@ const ProductListViewOne = (props: any) => {
|
|
|
23
76
|
const data = props.props || props;
|
|
24
77
|
const slug = data?.code; // Using code instead of slug
|
|
25
78
|
|
|
26
|
-
// Updated price extraction to
|
|
27
|
-
const
|
|
28
|
-
const
|
|
79
|
+
// Updated price extraction to use pricing object
|
|
80
|
+
const mrp = data.pricing?.mrp ? getPriceFromPricingArray(data.pricing.mrp) : 0;
|
|
81
|
+
const sellingPrice = data.pricing?.nlcPrice
|
|
82
|
+
? getPriceFromPricingArray(data.pricing.nlcPrice)
|
|
83
|
+
: data.pricing?.costPrice
|
|
84
|
+
? getPriceFromPricingArray(data.pricing.costPrice)
|
|
85
|
+
: 0;
|
|
86
|
+
|
|
87
|
+
// Fallback to old price structure if pricing is not available
|
|
88
|
+
const mrpPrice = mrp || (data.price?.MRP ? getPriceValue(data.price.MRP) : 0);
|
|
89
|
+
const finalSellingPrice = sellingPrice || (data.price?.SP ? getPriceValue(data.price.SP) : 0);
|
|
29
90
|
|
|
30
91
|
const calculateDiscount = (): number | null => {
|
|
31
|
-
if (!
|
|
32
|
-
return Math.round(100 - (
|
|
92
|
+
if (!finalSellingPrice || !mrpPrice || mrpPrice <= finalSellingPrice) return null;
|
|
93
|
+
return Math.round(100 - (finalSellingPrice / mrpPrice) * 100);
|
|
33
94
|
};
|
|
34
95
|
|
|
35
96
|
const discount = calculateDiscount();
|
|
@@ -62,11 +123,11 @@ const ProductListViewOne = (props: any) => {
|
|
|
62
123
|
<h5>{variantOptions}</h5>
|
|
63
124
|
</div>
|
|
64
125
|
<div className="card_value">
|
|
65
|
-
{
|
|
126
|
+
{finalSellingPrice !== 0 && (
|
|
66
127
|
<div className="card_price">
|
|
67
|
-
<h4>₹{
|
|
128
|
+
<h4>₹{finalSellingPrice.toLocaleString("en-IN")}</h4>
|
|
68
129
|
<div className="card_right_grid">
|
|
69
|
-
{mrpPrice >
|
|
130
|
+
{mrpPrice > finalSellingPrice && (
|
|
70
131
|
<p >₹{mrpPrice.toLocaleString("en-IN")}</p>
|
|
71
132
|
)}
|
|
72
133
|
{discount !== null && discount > 0 && (
|
|
@@ -2,6 +2,59 @@ import React from "react";
|
|
|
2
2
|
import "./product-list-view-two.css";
|
|
3
3
|
import { Linodeurl } from '../../../const';
|
|
4
4
|
|
|
5
|
+
// Utility function to extract price value from different formats
|
|
6
|
+
const getPriceValue = (price: any): number => {
|
|
7
|
+
if (price === null || price === undefined) return 0;
|
|
8
|
+
|
|
9
|
+
// If it's already a number
|
|
10
|
+
if (typeof price === 'number') {
|
|
11
|
+
return isNaN(price) ? 0 : price;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// If it's an object with $numberDecimal (but not an array)
|
|
15
|
+
if (typeof price === 'object' && price !== null && !Array.isArray(price)) {
|
|
16
|
+
if (price.$numberDecimal !== undefined && price.$numberDecimal !== null) {
|
|
17
|
+
const value = parseFloat(String(price.$numberDecimal));
|
|
18
|
+
return isNaN(value) ? 0 : value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// If it's a string, try to parse it
|
|
23
|
+
if (typeof price === 'string') {
|
|
24
|
+
const value = parseFloat(price);
|
|
25
|
+
return isNaN(value) ? 0 : value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return 0;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Utility function to get price from pricing array (mrp, costPrice, nlcPrice)
|
|
32
|
+
const getPriceFromPricingArray = (pricingArray: any[]): number => {
|
|
33
|
+
if (!Array.isArray(pricingArray) || pricingArray.length === 0) return 0;
|
|
34
|
+
|
|
35
|
+
// First, try to find the default price with default currency
|
|
36
|
+
const defaultPrice = pricingArray.find(
|
|
37
|
+
(item: any) => item.isDefault === true && item.isDefaultCurrency === true
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (defaultPrice && defaultPrice.price) {
|
|
41
|
+
return getPriceValue(defaultPrice.price);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Fallback: find any default price
|
|
45
|
+
const anyDefault = pricingArray.find((item: any) => item.isDefault === true);
|
|
46
|
+
if (anyDefault && anyDefault.price) {
|
|
47
|
+
return getPriceValue(anyDefault.price);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Fallback: use first item
|
|
51
|
+
if (pricingArray[0] && pricingArray[0].price) {
|
|
52
|
+
return getPriceValue(pricingArray[0].price);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return 0;
|
|
56
|
+
};
|
|
57
|
+
|
|
5
58
|
const ProductListViewTwo = (props: any) => {
|
|
6
59
|
console.warn(props);
|
|
7
60
|
const [target, setTarget] = React.useState("_blank");
|
|
@@ -24,13 +77,21 @@ const ProductListViewTwo = (props: any) => {
|
|
|
24
77
|
const data = props.props || props;
|
|
25
78
|
const slug = data?.code; // Using code instead of slug since slug doesn't exist in your data
|
|
26
79
|
|
|
27
|
-
// Updated price extraction to
|
|
28
|
-
const
|
|
29
|
-
const
|
|
80
|
+
// Updated price extraction to use pricing object
|
|
81
|
+
const mrp = data.pricing?.mrp ? getPriceFromPricingArray(data.pricing.mrp) : 0;
|
|
82
|
+
const sellingPrice = data.pricing?.nlcPrice
|
|
83
|
+
? getPriceFromPricingArray(data.pricing.nlcPrice)
|
|
84
|
+
: data.pricing?.costPrice
|
|
85
|
+
? getPriceFromPricingArray(data.pricing.costPrice)
|
|
86
|
+
: 0;
|
|
87
|
+
|
|
88
|
+
// Fallback to old price structure if pricing is not available
|
|
89
|
+
const mrpPrice = mrp || (data.price?.MRP ? getPriceValue(data.price.MRP) : 0);
|
|
90
|
+
const finalSellingPrice = sellingPrice || (data.price?.SP ? getPriceValue(data.price.SP) : 0);
|
|
30
91
|
|
|
31
92
|
const calculateDiscount = () => {
|
|
32
|
-
if (!
|
|
33
|
-
return Math.round(100 - (
|
|
93
|
+
if (!finalSellingPrice || !mrpPrice || mrpPrice <= finalSellingPrice) return null;
|
|
94
|
+
return Math.round(100 - (finalSellingPrice / mrpPrice) * 100);
|
|
34
95
|
};
|
|
35
96
|
|
|
36
97
|
const discount = calculateDiscount();
|
|
@@ -66,16 +127,16 @@ const ProductListViewTwo = (props: any) => {
|
|
|
66
127
|
</div>
|
|
67
128
|
<div className="card_bottom">
|
|
68
129
|
<div className="price_container">
|
|
69
|
-
{
|
|
130
|
+
{finalSellingPrice !== 0 && (
|
|
70
131
|
<>
|
|
71
132
|
<div className="price_row">
|
|
72
|
-
<h4 className="selling_price">₹{
|
|
133
|
+
<h4 className="selling_price">₹{finalSellingPrice.toLocaleString("en-IN")}</h4>
|
|
73
134
|
{discount !== null && discount > 0 && (
|
|
74
135
|
<span className="discounts">{discount}% OFF</span>
|
|
75
136
|
)}
|
|
76
137
|
</div>
|
|
77
|
-
{mrpPrice >
|
|
78
|
-
<p className="save_amount">Save ₹{(mrpPrice -
|
|
138
|
+
{mrpPrice > finalSellingPrice && (
|
|
139
|
+
<p className="save_amount">Save ₹{(mrpPrice - finalSellingPrice).toLocaleString("en-IN")}</p>
|
|
79
140
|
)}
|
|
80
141
|
</>
|
|
81
142
|
)}
|