|
|
@ -7,12 +7,11 @@ import { |
|
|
|
TouchableHighlight, |
|
|
|
TouchableHighlight, |
|
|
|
Dimensions, |
|
|
|
Dimensions, |
|
|
|
Appearance, |
|
|
|
Appearance, |
|
|
|
Pressable, |
|
|
|
|
|
|
|
Platform, |
|
|
|
Platform, |
|
|
|
ActivityIndicator, |
|
|
|
|
|
|
|
} from "react-native"; |
|
|
|
} from "react-native"; |
|
|
|
import { useNavigation } from "@react-navigation/native"; |
|
|
|
import { useNavigation } from "@react-navigation/native"; |
|
|
|
import { product, userProduct } from "../../../redux/actions"; |
|
|
|
import { product, userProduct } from "../../../redux/actions"; |
|
|
|
|
|
|
|
import { asyncAwesomeAlert } from "../../../utils/AsyncWrappers"; |
|
|
|
import { connect } from "react-redux"; |
|
|
|
import { connect } from "react-redux"; |
|
|
|
import { Entypo } from "@expo/vector-icons"; |
|
|
|
import { Entypo } from "@expo/vector-icons"; |
|
|
|
import separate from "../../../utils/separate"; |
|
|
|
import separate from "../../../utils/separate"; |
|
|
@ -59,15 +58,17 @@ function Book({ |
|
|
|
}, 500); |
|
|
|
}, 500); |
|
|
|
}, [type]); |
|
|
|
}, [type]); |
|
|
|
|
|
|
|
|
|
|
|
const physicalAvailabileInCart = userProducts?.filter( |
|
|
|
const physicalAvailabileInCart = React.useMemo(() => { |
|
|
|
(product) => product?.productId === book?.product[1]?.id |
|
|
|
return userProducts?.filter( |
|
|
|
)[0]; |
|
|
|
(product) => product?.productId === book?.product[1]?.id |
|
|
|
|
|
|
|
)[0]; |
|
|
|
|
|
|
|
}, [userProducts, book]); |
|
|
|
|
|
|
|
|
|
|
|
const digitalAvailabileInCart = userProducts?.filter( |
|
|
|
const digitalAvailabileInCart = React.useMemo(() => { |
|
|
|
(product) => product?.productId === book?.product[0]?.id |
|
|
|
return userProducts?.filter( |
|
|
|
)[0]; |
|
|
|
(product) => product?.productId === book?.product[0]?.id |
|
|
|
|
|
|
|
)[0]; |
|
|
|
console.log(book); |
|
|
|
}, [userProducts, book]); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<ScrollView style={[tw("flex flex-1 relative")]}> |
|
|
|
<ScrollView style={[tw("flex flex-1 relative")]}> |
|
|
@ -222,11 +223,19 @@ function Book({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
]} |
|
|
|
]} |
|
|
|
onPress={() => |
|
|
|
onPress={() => |
|
|
|
pushToCart({ |
|
|
|
physicalAvailabileInCart |
|
|
|
productId: book?.product[1]?.id, |
|
|
|
? asyncAwesomeAlert( |
|
|
|
userId: userId, |
|
|
|
"نتیجه", |
|
|
|
count: 1, |
|
|
|
"این محصول قبلا به سبد خرید اضافه شده است.", |
|
|
|
}) |
|
|
|
{ |
|
|
|
|
|
|
|
showCancelButton: false, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
: pushToCart({ |
|
|
|
|
|
|
|
productId: book?.product[1]?.id, |
|
|
|
|
|
|
|
userId: userId, |
|
|
|
|
|
|
|
count: 1, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
> |
|
|
|
> |
|
|
|
<> |
|
|
|
<> |
|
|
@ -247,8 +256,6 @@ function Book({ |
|
|
|
style={[ |
|
|
|
style={[ |
|
|
|
tw("py-1 pr-2"), |
|
|
|
tw("py-1 pr-2"), |
|
|
|
{ |
|
|
|
{ |
|
|
|
borderLeftWidth: 1, |
|
|
|
|
|
|
|
borderColor: Colors.theme1[colorScheme].greenCF, |
|
|
|
|
|
|
|
fontFamily: "bold", |
|
|
|
fontFamily: "bold", |
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
fontSize: fontSize.sm, |
|
|
|
fontSize: fontSize.sm, |
|
|
@ -257,95 +264,6 @@ function Book({ |
|
|
|
> |
|
|
|
> |
|
|
|
{separate(book?.product[1]?.price) + " " + "تومان"} |
|
|
|
{separate(book?.product[1]?.price) + " " + "تومان"} |
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
{physicalAvailabileInCart && ( |
|
|
|
|
|
|
|
<View |
|
|
|
|
|
|
|
style={tw( |
|
|
|
|
|
|
|
`flex items-center pl-3 ${ |
|
|
|
|
|
|
|
ios ? "flex-row-reverse" : "flex-row-reverse" |
|
|
|
|
|
|
|
}` |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<Pressable |
|
|
|
|
|
|
|
onPress={() => |
|
|
|
|
|
|
|
pushToCart({ |
|
|
|
|
|
|
|
productId: physicalAvailabileInCart?.productId, |
|
|
|
|
|
|
|
userId: physicalAvailabileInCart.userId, |
|
|
|
|
|
|
|
count: 1, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
style={[ |
|
|
|
|
|
|
|
tw( |
|
|
|
|
|
|
|
`rounded-md py-0 flex flex-row justify-center items-center border ${ |
|
|
|
|
|
|
|
mobile ? "px-1.5" : "px-3" |
|
|
|
|
|
|
|
}` |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
borderColor: Colors.theme1[colorScheme].green79, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
]} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<Text |
|
|
|
|
|
|
|
style={{ |
|
|
|
|
|
|
|
fontSize: mobile ? fontSize.tiny : fontSize.xl4, |
|
|
|
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
|
|
|
fontFamily: "bold", |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
+ |
|
|
|
|
|
|
|
</Text> |
|
|
|
|
|
|
|
</Pressable> |
|
|
|
|
|
|
|
{userProductsLoading ? ( |
|
|
|
|
|
|
|
<ActivityIndicator |
|
|
|
|
|
|
|
style={tw("mx-1.5 my-3")} |
|
|
|
|
|
|
|
size="small" |
|
|
|
|
|
|
|
color={Colors.theme1[colorScheme].greenBA} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
<Text |
|
|
|
|
|
|
|
style={[ |
|
|
|
|
|
|
|
tw("mx-1.5"), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fontSize: fontSize.xl6, |
|
|
|
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
|
|
|
fontFamily: "bold", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
]} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{physicalAvailabileInCart?.count} |
|
|
|
|
|
|
|
</Text> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<Pressable |
|
|
|
|
|
|
|
onPress={() => |
|
|
|
|
|
|
|
pushToCart({ |
|
|
|
|
|
|
|
productId: physicalAvailabileInCart?.productId, |
|
|
|
|
|
|
|
userId: physicalAvailabileInCart?.userId, |
|
|
|
|
|
|
|
count: -1, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
style={[ |
|
|
|
|
|
|
|
tw( |
|
|
|
|
|
|
|
`rounded-md flex flex-row justify-center items-center border ${ |
|
|
|
|
|
|
|
mobile ? "px-2" : "px-3.5" |
|
|
|
|
|
|
|
}` |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
borderColor: Colors.theme1[colorScheme].green79, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
]} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<Text |
|
|
|
|
|
|
|
style={{ |
|
|
|
|
|
|
|
fontSize: mobile ? fontSize.tiny : fontSize.xl4, |
|
|
|
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
|
|
|
fontFamily: "demi", |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
- |
|
|
|
|
|
|
|
</Text> |
|
|
|
|
|
|
|
</Pressable> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</> |
|
|
|
</> |
|
|
@ -362,11 +280,19 @@ function Book({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
]} |
|
|
|
]} |
|
|
|
onPress={() => |
|
|
|
onPress={() => |
|
|
|
pushToCart({ |
|
|
|
digitalAvailabileInCart |
|
|
|
productId: book?.product[0]?.id, |
|
|
|
? asyncAwesomeAlert( |
|
|
|
userId: userId, |
|
|
|
"خطا", |
|
|
|
count: 1, |
|
|
|
"این محصول قبلا به سبد خرید اضافه شده است.", |
|
|
|
}) |
|
|
|
{ |
|
|
|
|
|
|
|
showCancelButton: false, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
: pushToCart({ |
|
|
|
|
|
|
|
productId: book?.product[0]?.id, |
|
|
|
|
|
|
|
userId: userId, |
|
|
|
|
|
|
|
count: 1, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
> |
|
|
|
> |
|
|
|
<> |
|
|
|
<> |
|
|
@ -385,7 +311,7 @@ function Book({ |
|
|
|
style={[ |
|
|
|
style={[ |
|
|
|
tw("py-1 pr-2"), |
|
|
|
tw("py-1 pr-2"), |
|
|
|
{ |
|
|
|
{ |
|
|
|
borderLeftWidth: 1, |
|
|
|
borderRightWidth: 1, |
|
|
|
borderColor: Colors.theme1[colorScheme].greenCF, |
|
|
|
borderColor: Colors.theme1[colorScheme].greenCF, |
|
|
|
fontFamily: "bold", |
|
|
|
fontFamily: "bold", |
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
@ -395,95 +321,6 @@ function Book({ |
|
|
|
> |
|
|
|
> |
|
|
|
{separate(book?.product[0]?.price) + " " + "تومان"} |
|
|
|
{separate(book?.product[0]?.price) + " " + "تومان"} |
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
{digitalAvailabileInCart && ( |
|
|
|
|
|
|
|
<View |
|
|
|
|
|
|
|
style={tw( |
|
|
|
|
|
|
|
`flex items-center pl-3 ${ |
|
|
|
|
|
|
|
ios ? "flex-row-reverse" : "flex-row-reverse" |
|
|
|
|
|
|
|
}` |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<Pressable |
|
|
|
|
|
|
|
onPress={() => |
|
|
|
|
|
|
|
pushToCart({ |
|
|
|
|
|
|
|
productId: digitalAvailabileInCart?.productId, |
|
|
|
|
|
|
|
userId: digitalAvailabileInCart.userId, |
|
|
|
|
|
|
|
count: 1, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
style={[ |
|
|
|
|
|
|
|
tw( |
|
|
|
|
|
|
|
`rounded-md py-0 flex flex-row justify-center items-center border ${ |
|
|
|
|
|
|
|
mobile ? "px-1.5" : "px-3" |
|
|
|
|
|
|
|
}` |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
borderColor: Colors.theme1[colorScheme].green79, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
]} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<Text |
|
|
|
|
|
|
|
style={{ |
|
|
|
|
|
|
|
fontSize: mobile ? fontSize.tiny : fontSize.xl4, |
|
|
|
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
|
|
|
fontFamily: "bold", |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
+ |
|
|
|
|
|
|
|
</Text> |
|
|
|
|
|
|
|
</Pressable> |
|
|
|
|
|
|
|
{userProductsLoading ? ( |
|
|
|
|
|
|
|
<ActivityIndicator |
|
|
|
|
|
|
|
style={tw("mx-1.5 my-3")} |
|
|
|
|
|
|
|
size="small" |
|
|
|
|
|
|
|
color={Colors.theme1[colorScheme].greenBA} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
<Text |
|
|
|
|
|
|
|
style={[ |
|
|
|
|
|
|
|
tw("mx-1.5"), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fontSize: fontSize.xl6, |
|
|
|
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
|
|
|
fontFamily: "bold", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
]} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{digitalAvailabileInCart?.count} |
|
|
|
|
|
|
|
</Text> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<Pressable |
|
|
|
|
|
|
|
onPress={() => |
|
|
|
|
|
|
|
pushToCart({ |
|
|
|
|
|
|
|
productId: digitalAvailabileInCart?.productId, |
|
|
|
|
|
|
|
userId: digitalAvailabileInCart?.userId, |
|
|
|
|
|
|
|
count: -1, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
style={[ |
|
|
|
|
|
|
|
tw( |
|
|
|
|
|
|
|
`rounded-md flex flex-row justify-center items-center border ${ |
|
|
|
|
|
|
|
mobile ? "px-2" : "px-3.5" |
|
|
|
|
|
|
|
}` |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
borderColor: Colors.theme1[colorScheme].green79, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
]} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<Text |
|
|
|
|
|
|
|
style={{ |
|
|
|
|
|
|
|
fontSize: mobile ? fontSize.tiny : fontSize.xl4, |
|
|
|
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
|
|
|
fontFamily: "demi", |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
- |
|
|
|
|
|
|
|
</Text> |
|
|
|
|
|
|
|
</Pressable> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</> |
|
|
|
</> |
|
|
|
</TouchableHighlight> |
|
|
|
</TouchableHighlight> |
|
|
@ -547,8 +384,6 @@ function Book({ |
|
|
|
style={[ |
|
|
|
style={[ |
|
|
|
tw("py-1 pr-2"), |
|
|
|
tw("py-1 pr-2"), |
|
|
|
{ |
|
|
|
{ |
|
|
|
borderLeftWidth: 1, |
|
|
|
|
|
|
|
borderColor: Colors.theme1[colorScheme].greenCF, |
|
|
|
|
|
|
|
fontFamily: "bold", |
|
|
|
fontFamily: "bold", |
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
fontSize: fontSize.sm, |
|
|
|
fontSize: fontSize.sm, |
|
|
@ -630,7 +465,7 @@ function Book({ |
|
|
|
<Entypo name="chevron-small-left" size={20} color="#196EC0" /> |
|
|
|
<Entypo name="chevron-small-left" size={20} color="#196EC0" /> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<Rates rate={book?.rate || 4} /> |
|
|
|
<Rates rate={book?.rate || 4} /> |
|
|
|
<Comments comments={book?.comments} /> |
|
|
|
<Comments comments={book?.comments} productId={book?.product[1]?.id} /> |
|
|
|
</> |
|
|
|
</> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</ScrollView> |
|
|
|
</ScrollView> |
|
|
|