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