|
|
|
@ -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,234 +30,241 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
|
if(!loading){ |
|
|
|
|
if (!loading) { |
|
|
|
|
setSelectedProduct(null); |
|
|
|
|
} |
|
|
|
|
},[loading]); |
|
|
|
|
}, [loading]); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<View |
|
|
|
|
style={[ |
|
|
|
|
tw( |
|
|
|
|
`flex justify-between py-2 ${ios ? "flex-row" : "flex-row-reverse"}` |
|
|
|
|
), |
|
|
|
|
{ |
|
|
|
|
borderBottomWidth: 1, |
|
|
|
|
borderColor: Colors.theme1[theme].grayE3, |
|
|
|
|
direction: "rtl", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
<View style={tw(`flex ${ios ? "flex-row" : "flex-row-reverse"}`)}> |
|
|
|
|
<Image |
|
|
|
|
source={{ |
|
|
|
|
uri: "https://dnvn.ir/api/v1/file/" + product.product.book.fileIds, |
|
|
|
|
}} |
|
|
|
|
style={[ |
|
|
|
|
tw(""), |
|
|
|
|
{ |
|
|
|
|
width: mobile ? width / 5 : width / 7, |
|
|
|
|
height: ((mobile ? width / 5 : width / 7) * 4) / 2.8, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
/> |
|
|
|
|
<View |
|
|
|
|
style={tw(`flex ${ios ? "items-start pl-3" : "items-end pr-2"}`)} |
|
|
|
|
> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: mobile ? fontSize.lg : fontSize.xl4, |
|
|
|
|
color: Colors.theme1[theme].green79, |
|
|
|
|
marginBottom: 5, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{product?.product?.book?.name || " "} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: mobile ? fontSize.sm : fontSize.lg, |
|
|
|
|
color: Colors.theme1[theme].gray2077, |
|
|
|
|
marginBottom: 3, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{"پایه" + " " + grades[product?.product?.book?.gradeId] || " "} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: mobile ? fontSize.sm : fontSize.lg, |
|
|
|
|
color: Colors.theme1[theme].gray2077, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
product && ( |
|
|
|
|
<View |
|
|
|
|
style={[ |
|
|
|
|
tw( |
|
|
|
|
`flex justify-between py-2 ${ios ? "flex-row" : "flex-row-reverse"}` |
|
|
|
|
), |
|
|
|
|
{ |
|
|
|
|
borderBottomWidth: 1, |
|
|
|
|
borderColor: Colors.theme1[theme].grayE3, |
|
|
|
|
direction: "rtl", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
<View style={tw(`flex ${ios ? "flex-row" : "flex-row-reverse"}`)}> |
|
|
|
|
<Image |
|
|
|
|
source={{ |
|
|
|
|
uri: |
|
|
|
|
"https://dnvn.ir/api/v1/file/" + product.product.book.fileIds, |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{product?.productType || 1 === 2 ? "نسخه فیزیکی" : "نسخه دیجیتال"} |
|
|
|
|
</Text> |
|
|
|
|
style={[ |
|
|
|
|
tw(""), |
|
|
|
|
{ |
|
|
|
|
width: mobile ? width / 5 : width / 7, |
|
|
|
|
height: ((mobile ? width / 5 : width / 7) * 4) / 2.8, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
/> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
`flex items-center justify-center mt-4 ${ |
|
|
|
|
ios ? "flex-row-reverse" : "flex-row" |
|
|
|
|
}` |
|
|
|
|
)} |
|
|
|
|
style={tw(`flex ${ios ? "items-start pl-3" : "items-end pr-2"}`)} |
|
|
|
|
> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
{ |
|
|
|
|
fontSize: mobile ? fontSize.xs : fontSize.tiny, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
style={{ |
|
|
|
|
fontSize: mobile ? fontSize.lg : fontSize.xl4, |
|
|
|
|
color: Colors.theme1[theme].green79, |
|
|
|
|
marginBottom: 5, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{" " + "تومان"} |
|
|
|
|
{product.product.book.name || " "} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
{ |
|
|
|
|
fontSize: mobile ? fontSize.lg : fontSize.xl, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
style={{ |
|
|
|
|
fontSize: mobile ? fontSize.sm : fontSize.lg, |
|
|
|
|
color: Colors.theme1[theme].gray2077, |
|
|
|
|
marginBottom: 3, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{separate(product?.product?.price) || " "} |
|
|
|
|
{"پایه" + " " + grades[product.product.book.gradeId] || " "} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
<View |
|
|
|
|
style={tw(`flex justify-between ${ios ? "items-end" : "items-start"}`)} |
|
|
|
|
> |
|
|
|
|
<AntDesign |
|
|
|
|
name="close" |
|
|
|
|
size={mobile ? 20 : 30} |
|
|
|
|
color={Colors.theme1[theme].redFF1} |
|
|
|
|
onPress={() => |
|
|
|
|
submit( |
|
|
|
|
pushToCart( |
|
|
|
|
{ |
|
|
|
|
productId: product?.productId, |
|
|
|
|
userId: product?.userId, |
|
|
|
|
count: product?.productType === 1 ? -1 : -product?.count, |
|
|
|
|
}, |
|
|
|
|
{}, |
|
|
|
|
{ id: product?.factorId } |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
|
<View style={tw("flex items-center mt-2")}> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
`flex items-center mb-3 ${ios ? "flex-row" : "flex-row-reverse"}` |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<Pressable |
|
|
|
|
onPress={() => |
|
|
|
|
submit( |
|
|
|
|
pushToCart({ |
|
|
|
|
productId: product?.productId, |
|
|
|
|
userId: product?.userId, |
|
|
|
|
count: 1, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
style={[ |
|
|
|
|
tw( |
|
|
|
|
`rounded-md py-0 flex flex-row justify-center items-center border ${ |
|
|
|
|
mobile ? "px-2" : "px-3" |
|
|
|
|
}` |
|
|
|
|
), |
|
|
|
|
{ |
|
|
|
|
borderColor: Colors.theme1[theme].greenCF, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: mobile ? fontSize.sm : fontSize.lg, |
|
|
|
|
color: Colors.theme1[theme].gray2077, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{product.productType || 1 === 2 ? "نسخه فیزیکی" : "نسخه دیجیتال"} |
|
|
|
|
</Text> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
`flex items-center justify-center mt-4 ${ |
|
|
|
|
ios ? "flex-row-reverse" : "flex-row" |
|
|
|
|
}` |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: mobile ? fontSize.xl : fontSize.xl4, |
|
|
|
|
color: Colors.theme1[theme].greenCF, |
|
|
|
|
fontFamily: "light", |
|
|
|
|
}} |
|
|
|
|
style={[ |
|
|
|
|
{ |
|
|
|
|
fontSize: mobile ? fontSize.xs : fontSize.tiny, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
+ |
|
|
|
|
{" " + "تومان"} |
|
|
|
|
</Text> |
|
|
|
|
</Pressable> |
|
|
|
|
{loading && selectedProduct === product?.productId ? ( |
|
|
|
|
<ActivityIndicator |
|
|
|
|
style={tw("mx-2")} |
|
|
|
|
size="small" |
|
|
|
|
color={Colors.theme1[theme].greenBA} |
|
|
|
|
/> |
|
|
|
|
) : ( |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
tw("mx-2.5"), |
|
|
|
|
{ |
|
|
|
|
fontSize: fontSize.xl6, |
|
|
|
|
color: Colors.theme1[theme].greenBA, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
fontSize: mobile ? fontSize.lg : fontSize.xl, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{product?.count} |
|
|
|
|
{separate(product.product.price) || " "} |
|
|
|
|
</Text> |
|
|
|
|
)} |
|
|
|
|
|
|
|
|
|
<Pressable |
|
|
|
|
onPress={() => |
|
|
|
|
submit( |
|
|
|
|
pushToCart({ |
|
|
|
|
productId: product?.productId, |
|
|
|
|
userId: product?.userId, |
|
|
|
|
count: -1, |
|
|
|
|
}) |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
`flex justify-between ${ios ? "items-end" : "items-start"}` |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<AntDesign |
|
|
|
|
name="close" |
|
|
|
|
size={mobile ? 20 : 30} |
|
|
|
|
color={Colors.theme1[theme].redFF1} |
|
|
|
|
onPress={() => |
|
|
|
|
submit( |
|
|
|
|
pushToCart( |
|
|
|
|
{ |
|
|
|
|
productId: product.productId, |
|
|
|
|
userId: product.userId, |
|
|
|
|
count: product.productType === 1 ? -1 : -product?.count, |
|
|
|
|
}, |
|
|
|
|
{}, |
|
|
|
|
{ id: product.factorId } |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
style={[ |
|
|
|
|
tw( |
|
|
|
|
`rounded-md py-0 flex flex-row justify-center items-center border ${ |
|
|
|
|
mobile ? "px-2.5" : "px-3.5" |
|
|
|
|
}` |
|
|
|
|
), |
|
|
|
|
{ |
|
|
|
|
borderColor: Colors.theme1[theme].greenCF, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
|
<View style={tw("flex items-center mt-2")}> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
`flex items-center mb-3 ${ |
|
|
|
|
ios ? "flex-row" : "flex-row-reverse" |
|
|
|
|
}` |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<Pressable |
|
|
|
|
onPress={() => |
|
|
|
|
submit( |
|
|
|
|
pushToCart({ |
|
|
|
|
productId: product.productId, |
|
|
|
|
userId: product.userId, |
|
|
|
|
count: 1, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
style={[ |
|
|
|
|
tw( |
|
|
|
|
`rounded-md py-0 flex flex-row justify-center items-center border ${ |
|
|
|
|
mobile ? "px-2" : "px-3" |
|
|
|
|
}` |
|
|
|
|
), |
|
|
|
|
{ |
|
|
|
|
borderColor: Colors.theme1[theme].greenCF, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: mobile ? fontSize.xl : fontSize.xl4, |
|
|
|
|
color: Colors.theme1[theme].greenCF, |
|
|
|
|
fontFamily: "light", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
+ |
|
|
|
|
</Text> |
|
|
|
|
</Pressable> |
|
|
|
|
{(loading && selectedProduct === product.productId) ? ( |
|
|
|
|
<ActivityIndicator |
|
|
|
|
style={tw("mx-2")} |
|
|
|
|
size="small" |
|
|
|
|
color={Colors.theme1[theme].greenBA} |
|
|
|
|
/> |
|
|
|
|
) : ( |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
tw("mx-2.5"), |
|
|
|
|
{ |
|
|
|
|
fontSize: fontSize.xl6, |
|
|
|
|
color: Colors.theme1[theme].greenBA, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{product.count} |
|
|
|
|
</Text> |
|
|
|
|
)} |
|
|
|
|
|
|
|
|
|
<Pressable |
|
|
|
|
onPress={() => |
|
|
|
|
submit( |
|
|
|
|
pushToCart({ |
|
|
|
|
productId: product.productId, |
|
|
|
|
userId: product.userId, |
|
|
|
|
count: -1, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
style={[ |
|
|
|
|
tw( |
|
|
|
|
`rounded-md py-0 flex flex-row justify-center items-center border ${ |
|
|
|
|
mobile ? "px-2.5" : "px-3.5" |
|
|
|
|
}` |
|
|
|
|
), |
|
|
|
|
{ |
|
|
|
|
borderColor: Colors.theme1[theme].greenCF, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: mobile ? fontSize.xl : fontSize.xl4, |
|
|
|
|
color: Colors.theme1[theme].greenCF, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
- |
|
|
|
|
</Text> |
|
|
|
|
</Pressable> |
|
|
|
|
</View> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
`flex items-center justify-center ${ |
|
|
|
|
ios ? "flex-row-reverse" : "flex-row" |
|
|
|
|
}` |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<Text style={[{ fontSize: fontSize.sm, fontFamily: "regular" }]}> |
|
|
|
|
{" " + "تومان"} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: mobile ? fontSize.xl : fontSize.xl4, |
|
|
|
|
color: Colors.theme1[theme].greenCF, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
}} |
|
|
|
|
style={[ |
|
|
|
|
{ |
|
|
|
|
fontSize: mobile ? fontSize.xl : fontSize.xl4, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
- |
|
|
|
|
{separate(product.product.price * product.count) || " "} |
|
|
|
|
</Text> |
|
|
|
|
</Pressable> |
|
|
|
|
</View> |
|
|
|
|
<View |
|
|
|
|
style={tw( |
|
|
|
|
`flex items-center justify-center ${ |
|
|
|
|
ios ? "flex-row-reverse" : "flex-row" |
|
|
|
|
}` |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<Text style={[{ fontSize: fontSize.sm, fontFamily: "regular" }]}> |
|
|
|
|
{" " + "تومان"} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
{ |
|
|
|
|
fontSize: mobile ? fontSize.xl : fontSize.xl4, |
|
|
|
|
fontFamily: "regular", |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{separate(product?.product?.price * product?.count) || " "} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
</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); |
|
|
|
|