|
|
|
@ -21,7 +21,7 @@ import tw from "tailwind-rn"; |
|
|
|
|
const width = Dimensions.get("window").width; |
|
|
|
|
const ios = Platform.OS === "ios"; |
|
|
|
|
|
|
|
|
|
function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
function Product({ product, grades, pushToCart, loading, mobile, theme, addActionFlag, getList }) { |
|
|
|
|
const [selectedProduct, setSelectedProduct] = React.useState(null); |
|
|
|
|
|
|
|
|
|
const submit = async (action) => { |
|
|
|
@ -30,12 +30,13 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
|
if(!loading){ |
|
|
|
|
if (!loading) { |
|
|
|
|
setSelectedProduct(null); |
|
|
|
|
} |
|
|
|
|
},[loading]); |
|
|
|
|
}, [loading]); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
product && ( |
|
|
|
|
<View |
|
|
|
|
style={[ |
|
|
|
|
tw( |
|
|
|
@ -51,7 +52,8 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
<View style={tw(`flex ${ios ? "flex-row" : "flex-row-reverse"}`)}> |
|
|
|
|
<Image |
|
|
|
|
source={{ |
|
|
|
|
uri: "https://dnvn.ir/api/v1/file/" + product.product.book.fileIds, |
|
|
|
|
uri: |
|
|
|
|
"https://dnvn.ir/api/v1/file/" + product.product.book.fileIds, |
|
|
|
|
}} |
|
|
|
|
style={[ |
|
|
|
|
tw(""), |
|
|
|
@ -72,7 +74,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{product?.product?.book?.name || " "} |
|
|
|
|
{product.product.book.name || " "} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
@ -82,7 +84,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{"پایه" + " " + grades[product?.product?.book?.gradeId] || " "} |
|
|
|
|
{"پایه" + " " + grades[product.product.book.gradeId] || " "} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
@ -91,7 +93,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{product?.productType || 1 === 2 ? "نسخه فیزیکی" : "نسخه دیجیتال"} |
|
|
|
|
{product.productType || 1 === 2 ? "نسخه فیزیکی" : "نسخه دیجیتال"} |
|
|
|
|
</Text> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
@ -118,13 +120,15 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{separate(product?.product?.price) || " "} |
|
|
|
|
{separate(product.product.price) || " "} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
<View |
|
|
|
|
style={tw(`flex justify-between ${ios ? "items-end" : "items-start"}`)} |
|
|
|
|
style={tw( |
|
|
|
|
`flex justify-between ${ios ? "items-end" : "items-start"}` |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<AntDesign |
|
|
|
|
name="close" |
|
|
|
@ -134,12 +138,12 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
submit( |
|
|
|
|
pushToCart( |
|
|
|
|
{ |
|
|
|
|
productId: product?.productId, |
|
|
|
|
userId: product?.userId, |
|
|
|
|
count: product?.productType === 1 ? -1 : -product?.count, |
|
|
|
|
productId: product.productId, |
|
|
|
|
userId: product.userId, |
|
|
|
|
count: product.productType === 1 ? -1 : -product?.count, |
|
|
|
|
}, |
|
|
|
|
{}, |
|
|
|
|
{ id: product?.factorId } |
|
|
|
|
{ id: product.factorId } |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
@ -147,15 +151,17 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
<View style={tw("flex items-center mt-2")}> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
`flex items-center mb-3 ${ios ? "flex-row" : "flex-row-reverse"}` |
|
|
|
|
`flex items-center mb-3 ${ |
|
|
|
|
ios ? "flex-row" : "flex-row-reverse" |
|
|
|
|
}` |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<Pressable |
|
|
|
|
onPress={() => |
|
|
|
|
submit( |
|
|
|
|
pushToCart({ |
|
|
|
|
productId: product?.productId, |
|
|
|
|
userId: product?.userId, |
|
|
|
|
productId: product.productId, |
|
|
|
|
userId: product.userId, |
|
|
|
|
count: 1, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
@ -181,7 +187,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
+ |
|
|
|
|
</Text> |
|
|
|
|
</Pressable> |
|
|
|
|
{loading && selectedProduct === product?.productId ? ( |
|
|
|
|
{(loading && selectedProduct === product.productId) ? ( |
|
|
|
|
<ActivityIndicator |
|
|
|
|
style={tw("mx-2")} |
|
|
|
|
size="small" |
|
|
|
@ -198,7 +204,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{product?.count} |
|
|
|
|
{product.count} |
|
|
|
|
</Text> |
|
|
|
|
)} |
|
|
|
|
|
|
|
|
@ -206,8 +212,8 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
onPress={() => |
|
|
|
|
submit( |
|
|
|
|
pushToCart({ |
|
|
|
|
productId: product?.productId, |
|
|
|
|
userId: product?.userId, |
|
|
|
|
productId: product.productId, |
|
|
|
|
userId: product.userId, |
|
|
|
|
count: -1, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
@ -252,12 +258,13 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{separate(product?.product?.price * product?.count) || " "} |
|
|
|
|
{separate(product.product.price * product.count) || " "} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -265,10 +272,12 @@ const mapStateToProps = (state) => ({ |
|
|
|
|
grades: state.publicApi.grades, |
|
|
|
|
mobile: state.publicApi.mobile, |
|
|
|
|
theme: state.publicApi.theme, |
|
|
|
|
addActionFlag: state.userProduct.addActionFlag, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
|
|
pushToCart: userProduct.add, |
|
|
|
|
getList: userProduct.list |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Product); |
|
|
|
|