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