|
|
|
@ -9,6 +9,7 @@ import { |
|
|
|
|
Appearance, |
|
|
|
|
Pressable, |
|
|
|
|
Platform, |
|
|
|
|
ActivityIndicator |
|
|
|
|
} from "react-native"; |
|
|
|
|
import { useNavigation } from "@react-navigation/native"; |
|
|
|
|
import { product, userProduct } from "../../../redux/actions"; |
|
|
|
@ -35,7 +36,15 @@ import Colors from "../../../constants/Colors"; |
|
|
|
|
const { height, width } = Dimensions.get("window"); |
|
|
|
|
const ios = Platform.OS === "ios"; |
|
|
|
|
|
|
|
|
|
function Book({ book, grades, pushToCart, userId, loading, mobile }) { |
|
|
|
|
function Book({ |
|
|
|
|
book, |
|
|
|
|
grades, |
|
|
|
|
pushToCart, |
|
|
|
|
userId, |
|
|
|
|
loading, |
|
|
|
|
mobile, |
|
|
|
|
userProducts, |
|
|
|
|
}) { |
|
|
|
|
const colorScheme = Appearance.getColorScheme(); |
|
|
|
|
const navigation = useNavigation(); |
|
|
|
|
const [type, setType] = useState(1); |
|
|
|
@ -49,6 +58,14 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) { |
|
|
|
|
}, 500); |
|
|
|
|
}, [type]); |
|
|
|
|
|
|
|
|
|
const physicalAvailabileInCart = userProducts?.filter( |
|
|
|
|
(product) => product?.productId === book?.product[1]?.id |
|
|
|
|
)[0]; |
|
|
|
|
|
|
|
|
|
const digitalAvailabileInCart = userProducts?.filter( |
|
|
|
|
(product) => product?.productId === book?.product[0]?.id |
|
|
|
|
)[0]; |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<ScrollView style={[tw("flex flex-col flex-1 relative")]}> |
|
|
|
|
{!mobile && <View style={tw("mt-5")}></View>} |
|
|
|
@ -69,11 +86,13 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) { |
|
|
|
|
)} |
|
|
|
|
{imageSlider && <ImageSlider />} |
|
|
|
|
<View style={tw("flex flex-row-reverse")}> |
|
|
|
|
|
|
|
|
|
<Image |
|
|
|
|
source={{ uri: `https://dnvn.ir/api/v1/file/${book?.fileIds}` }} |
|
|
|
|
style={[tw("rounded-md"), { height : height / 4, width : height / 4 * 3 / 4}]} |
|
|
|
|
/> |
|
|
|
|
<Image |
|
|
|
|
source={{ uri: `https://dnvn.ir/api/v1/file/${book?.fileIds}` }} |
|
|
|
|
style={[ |
|
|
|
|
tw("rounded-md"), |
|
|
|
|
{ height: height / 4, width: ((height / 4) * 3) / 4 }, |
|
|
|
|
]} |
|
|
|
|
/> |
|
|
|
|
|
|
|
|
|
<View |
|
|
|
|
style={[ |
|
|
|
@ -190,7 +209,9 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) { |
|
|
|
|
<View style={tw("flex flex-row-reverse justify-between flex-wrap py-3")}> |
|
|
|
|
<Pressable |
|
|
|
|
style={[ |
|
|
|
|
tw("flex flex-row-reverse w-full justify-between px-2 py-3 mb-4"), |
|
|
|
|
tw( |
|
|
|
|
"flex flex-row-reverse w-full justify-between px-2 py-3 mb-4" |
|
|
|
|
), |
|
|
|
|
{ |
|
|
|
|
borderWidth: 1, |
|
|
|
|
borderColor: Colors.theme1[colorScheme].greenCF, |
|
|
|
@ -215,22 +236,113 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) { |
|
|
|
|
> |
|
|
|
|
خرید نسخه فیزیکی کتاب |
|
|
|
|
</Text> |
|
|
|
|
<View style={tw("flex flex-row-reverse")}> |
|
|
|
|
<View style={tw("w-px h-full bg-green-500")}></View> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
tw("py-1 pr-2"), |
|
|
|
|
{ |
|
|
|
|
borderLeftWidth: 1, |
|
|
|
|
borderColor: Colors.theme1[colorScheme].greenCF, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.sm, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{separate(book?.product[1]?.price) + " " + "تومان"} |
|
|
|
|
</Text> |
|
|
|
|
<View style={tw("flex flex-row-reverse items-center")}> |
|
|
|
|
<View style={tw("w-px h-full bg-green-300")}></View> |
|
|
|
|
<View style={tw("flex")}> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
tw("py-1 pr-2"), |
|
|
|
|
{ |
|
|
|
|
borderLeftWidth: 1, |
|
|
|
|
borderColor: Colors.theme1[colorScheme].greenCF, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.sm, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{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> |
|
|
|
|
{loading ? ( |
|
|
|
|
<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> |
|
|
|
|
</Pressable> |
|
|
|
|
<Pressable |
|
|
|
@ -261,23 +373,111 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) { |
|
|
|
|
> |
|
|
|
|
خرید نسخه دیجیتال کتاب |
|
|
|
|
</Text> |
|
|
|
|
<View style={tw("flex flex-row-reverse")}> |
|
|
|
|
<View style={tw("w-px h-full bg-green-500")}></View> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
tw("py-1 pr-2"), |
|
|
|
|
{ |
|
|
|
|
borderLeftWidth: 1, |
|
|
|
|
borderColor: Colors.theme1[colorScheme].greenCF, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.sm, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{separate(book?.product[0]?.price) + " " + "تومان"} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
<View style={tw("flex")}> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
tw("py-1 pr-2"), |
|
|
|
|
{ |
|
|
|
|
borderLeftWidth: 1, |
|
|
|
|
borderColor: Colors.theme1[colorScheme].greenCF, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
fontSize: fontSize.sm, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{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> |
|
|
|
|
{loading ? ( |
|
|
|
|
<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> |
|
|
|
|
</Pressable> |
|
|
|
|
<Pressable |
|
|
|
|
style={[ |
|
|
|
@ -422,6 +622,7 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({ |
|
|
|
|
userProducts: state.userProduct.list, |
|
|
|
|
userId: state.user.status?.id, |
|
|
|
|
loading: state.userProduct.loading, |
|
|
|
|
mobile: state.publicApi.mobile, |
|
|
|
|