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