From 26959d98826b5a067d136ada46f0ac62d39b67ef Mon Sep 17 00:00:00 2001 From: Reza_ashrafi Date: Sun, 13 Mar 2022 22:42:58 +0330 Subject: [PATCH] reza added some change on alert and product page --- src/components/AlertModal.js | 10 +- src/redux/reducers/user.js | 2 +- src/redux/reducers/userFactor.js | 4 + src/redux/reducers/userProduct.js | 5 + src/screens/Home/components/Blogs.js | 196 ++++++++--------- src/screens/Home/components/Videos.js | 109 +++++----- src/screens/Home/index.js | 9 +- src/screens/Product/components/Book.js | 281 +++++++++++++++++++++---- 8 files changed, 408 insertions(+), 208 deletions(-) diff --git a/src/components/AlertModal.js b/src/components/AlertModal.js index fac4a33..4e27962 100644 --- a/src/components/AlertModal.js +++ b/src/components/AlertModal.js @@ -79,7 +79,9 @@ const AlertModal = props => { progressColor="red" showProgress={alert.showProgress} title={alert.title} + titleStyle={{ fontFamily : 'bold' }} message={alert.message} + messageStyle={{textAlign : 'right', fontFamily : 'regular'}} closeOnTouchOutside={alert.closeOnTouchOutside} closeOnHardwareBackPress={alert.closeOnHardwareBackPress} showCancelButton={alert.showCancelButton} @@ -91,14 +93,16 @@ const AlertModal = props => { onConfirmPressed={(onConfirmPressed)} contentStyle={{ width: ReactNative.Dimensions.get('window').width / 1.5, - + }} + cancelButtonStyle={{ + fontFamily : 'regular', }} confirmButtonStyle={ { width: ReactNative.Dimensions.get('window').width / 4, alignItems: 'center', - justifyContent: 'center' - + justifyContent: 'center', + fontFamily : 'regular' } } useNativeDriver={true} diff --git a/src/redux/reducers/user.js b/src/redux/reducers/user.js index 76ef600..cb426a1 100644 --- a/src/redux/reducers/user.js +++ b/src/redux/reducers/user.js @@ -62,7 +62,7 @@ const user = (state = initialState, action) => { case "loading": return { ...state, loading: true }; case "error": - asyncAwesomeAlert("خظا", data.message, { + asyncAwesomeAlert("خطا", data.message, { showCancelButton: false, }); return { ...state, loading: false, error: data.message }; diff --git a/src/redux/reducers/userFactor.js b/src/redux/reducers/userFactor.js index 8598ee5..ffcdac1 100644 --- a/src/redux/reducers/userFactor.js +++ b/src/redux/reducers/userFactor.js @@ -1,4 +1,5 @@ import {useNavigation} from '@react-navigation/native'; +import {asyncAwesomeAlert} from '../../utils/AsyncWrappers'; const initialState = { loading: false, @@ -52,6 +53,9 @@ export default function userFactor(state = initialState, action) { case "userFactor/loading": return { ...state, loading: true }; case "userFactor/error": + asyncAwesomeAlert("خطا", data.message, { + showCancelButton: false, + }); // toast.error(data.message); return { ...state, loading: false, error: data.message }; default: diff --git a/src/redux/reducers/userProduct.js b/src/redux/reducers/userProduct.js index 7524513..4dab0bf 100644 --- a/src/redux/reducers/userProduct.js +++ b/src/redux/reducers/userProduct.js @@ -1,3 +1,5 @@ +import {asyncAwesomeAlert} from '../../utils/AsyncWrappers'; + const initialState = { loading: false, error: null, @@ -41,6 +43,9 @@ export default function userFactor(state = initialState, action) { return { ...state, loading: true }; case "userProduct/error": // toast.error(data.message); + asyncAwesomeAlert("خطا", data.message, { + showCancelButton: false, + }); return { ...state, loading: false, error: data.message }; default: return state; diff --git a/src/screens/Home/components/Blogs.js b/src/screens/Home/components/Blogs.js index d9f17b1..72797e7 100644 --- a/src/screens/Home/components/Blogs.js +++ b/src/screens/Home/components/Blogs.js @@ -28,129 +28,113 @@ const { width } = Dimensions.get("window"); const ios = Platform.OS === "ios"; function Blogs({ blogs, mobile }) { + return ( + + +
+ + } + keyExtractor={(item) => item.id} + /> + + ); +} + +const Blog = ({ blog, mobile }) => { const colorScheme = Appearance.getColorScheme(); - const Blog = ({ blog }) => { - return ( - navigation.navigate('Product')} + > + + navigation.navigate('Product')} > - - - - {blog.title} - - - + {blog.title} + + + + - - حامد دژبانی نسب - - - - - ۳۰ دقیقه - - - - - - - + + + حامد دژبانی نسب + + + + + ۳۰ دقیقه + - - ); - }; - return ( - - -
- } - keyExtractor={(item) => item.id} - /> - + ); -} +}; const mapStateToProps = (state) => ({ // features: state.publicApi.home?.features, diff --git a/src/screens/Home/components/Videos.js b/src/screens/Home/components/Videos.js index 0e899b6..91a34bf 100644 --- a/src/screens/Home/components/Videos.js +++ b/src/screens/Home/components/Videos.js @@ -22,58 +22,6 @@ import fontSize from "../../../constants/fontSize"; const ios = Platform.OS === "ios"; function Videos({ videos, grades, mobile }) { - const colorScheme = Appearance.getColorScheme(); - const Video = ({ video }) => { - const navigation = useNavigation(); - return ( - navigation.navigate("Video", { id: video.id })} - > - - - {"دوره ویدئویی" + " " + video.name} - - - {"پایه" + " " + grades[video.gradeId]} - - - - - - ); - }; return ( @@ -96,6 +46,59 @@ function Videos({ videos, grades, mobile }) { ); } +const Video = ({ video, mobile, grades }) => { + const navigation = useNavigation(); + const colorScheme = Appearance.getColorScheme(); + return ( + navigation.navigate("Video", { id: video.id })} + > + + + {"دوره ویدئویی" + " " + video.name} + + + {"پایه" + " " + grades[video.gradeId]} + + + + + + ); +}; + const mapStateToProps = (state) => ({ grades: state.publicApi.grades, mobile: state.publicApi.mobile, diff --git a/src/screens/Home/index.js b/src/screens/Home/index.js index 9d27ec7..1126169 100644 --- a/src/screens/Home/index.js +++ b/src/screens/Home/index.js @@ -57,20 +57,19 @@ const Home = ({ back: false, }} /> - {!mobile && } - {userProducts?.length > 0 && } +
- {books?.length > 0 && } - {books?.length > 0 && } - {blogs?.length > 0 && } + + + ); diff --git a/src/screens/Product/components/Book.js b/src/screens/Product/components/Book.js index 38d9651..d4df2c4 100644 --- a/src/screens/Product/components/Book.js +++ b/src/screens/Product/components/Book.js @@ -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 ( {!mobile && } @@ -69,11 +86,13 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) { )} {imageSlider && } - - + خرید نسخه فیزیکی کتاب - - - - {separate(book?.product[1]?.price) + " " + "تومان"} - + + + + + {separate(book?.product[1]?.price) + " " + "تومان"} + + {physicalAvailabileInCart && ( + + + 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, + }, + ]} + > + + + + + + {loading ? ( + + ) : ( + + {physicalAvailabileInCart?.count} + + )} + + + 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, + }, + ]} + > + + - + + + + )} + خرید نسخه دیجیتال کتاب - - - - {separate(book?.product[0]?.price) + " " + "تومان"} - - + + + {separate(book?.product[0]?.price) + " " + "تومان"} + + {digitalAvailabileInCart && ( + + + 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, + }, + ]} + > + + + + + + {loading ? ( + + ) : ( + + {digitalAvailabileInCart?.count} + + )} + + + 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, + }, + ]} + > + + - + + + + )} + ({ + userProducts: state.userProduct.list, userId: state.user.status?.id, loading: state.userProduct.loading, mobile: state.publicApi.mobile,