reza added some change on alert and product page

master
Reza_ashrafi 3 years ago
parent 00fc4e93ed
commit 26959d9882
  1. 10
      src/components/AlertModal.js
  2. 2
      src/redux/reducers/user.js
  3. 4
      src/redux/reducers/userFactor.js
  4. 5
      src/redux/reducers/userProduct.js
  5. 72
      src/screens/Home/components/Blogs.js
  6. 51
      src/screens/Home/components/Videos.js
  7. 9
      src/screens/Home/index.js
  8. 217
      src/screens/Product/components/Book.js

@ -79,7 +79,9 @@ const AlertModal = props => {
progressColor="red" progressColor="red"
showProgress={alert.showProgress} showProgress={alert.showProgress}
title={alert.title} title={alert.title}
titleStyle={{ fontFamily : 'bold' }}
message={alert.message} message={alert.message}
messageStyle={{textAlign : 'right', fontFamily : 'regular'}}
closeOnTouchOutside={alert.closeOnTouchOutside} closeOnTouchOutside={alert.closeOnTouchOutside}
closeOnHardwareBackPress={alert.closeOnHardwareBackPress} closeOnHardwareBackPress={alert.closeOnHardwareBackPress}
showCancelButton={alert.showCancelButton} showCancelButton={alert.showCancelButton}
@ -91,14 +93,16 @@ const AlertModal = props => {
onConfirmPressed={(onConfirmPressed)} onConfirmPressed={(onConfirmPressed)}
contentStyle={{ contentStyle={{
width: ReactNative.Dimensions.get('window').width / 1.5, width: ReactNative.Dimensions.get('window').width / 1.5,
}}
cancelButtonStyle={{
fontFamily : 'regular',
}} }}
confirmButtonStyle={ confirmButtonStyle={
{ {
width: ReactNative.Dimensions.get('window').width / 4, width: ReactNative.Dimensions.get('window').width / 4,
alignItems: 'center', alignItems: 'center',
justifyContent: 'center' justifyContent: 'center',
fontFamily : 'regular'
} }
} }
useNativeDriver={true} useNativeDriver={true}

@ -62,7 +62,7 @@ const user = (state = initialState, action) => {
case "loading": case "loading":
return { ...state, loading: true }; return { ...state, loading: true };
case "error": case "error":
asyncAwesomeAlert(ظا", data.message, { asyncAwesomeAlert(طا", data.message, {
showCancelButton: false, showCancelButton: false,
}); });
return { ...state, loading: false, error: data.message }; return { ...state, loading: false, error: data.message };

@ -1,4 +1,5 @@
import {useNavigation} from '@react-navigation/native'; import {useNavigation} from '@react-navigation/native';
import {asyncAwesomeAlert} from '../../utils/AsyncWrappers';
const initialState = { const initialState = {
loading: false, loading: false,
@ -52,6 +53,9 @@ export default function userFactor(state = initialState, action) {
case "userFactor/loading": case "userFactor/loading":
return { ...state, loading: true }; return { ...state, loading: true };
case "userFactor/error": case "userFactor/error":
asyncAwesomeAlert("خطا", data.message, {
showCancelButton: false,
});
// toast.error(data.message); // toast.error(data.message);
return { ...state, loading: false, error: data.message }; return { ...state, loading: false, error: data.message };
default: default:

@ -1,3 +1,5 @@
import {asyncAwesomeAlert} from '../../utils/AsyncWrappers';
const initialState = { const initialState = {
loading: false, loading: false,
error: null, error: null,
@ -41,6 +43,9 @@ export default function userFactor(state = initialState, action) {
return { ...state, loading: true }; return { ...state, loading: true };
case "userProduct/error": case "userProduct/error":
// toast.error(data.message); // toast.error(data.message);
asyncAwesomeAlert("خطا", data.message, {
showCancelButton: false,
});
return { ...state, loading: false, error: data.message }; return { ...state, loading: false, error: data.message };
default: default:
return state; return state;

@ -28,8 +28,26 @@ const { width } = Dimensions.get("window");
const ios = Platform.OS === "ios"; const ios = Platform.OS === "ios";
function Blogs({ blogs, mobile }) { function Blogs({ blogs, mobile }) {
return (
<View style={[tw("flex flex-col pr-3 mb-5")]}>
<View style={tw("w-full pl-3")}>
<Header title={"خواندنیها"} route={"Blogs"} />
</View>
<FlatList
showsHorizontalScrollIndicator={false}
horizontal={true}
inverted={true}
style={[tw("flex flex-row mt-3 pb-7")]}
data={blogs}
renderItem={({ item }) => <Blog blog={item} mobile={mobile} />}
keyExtractor={(item) => item.id}
/>
</View>
);
}
const Blog = ({ blog, mobile }) => {
const colorScheme = Appearance.getColorScheme(); const colorScheme = Appearance.getColorScheme();
const Blog = ({ blog }) => {
return ( return (
<Pressable <Pressable
style={[ style={[
@ -45,7 +63,7 @@ function Blogs({ blogs, mobile }) {
tw("rounded-md"), tw("rounded-md"),
{ {
flex: 1, flex: 1,
height: mobile ? 180 : width / 2.2 * 9 / 16, height: mobile ? 180 : ((width / 2.2) * 9) / 16,
}, },
]} ]}
/> />
@ -59,13 +77,13 @@ function Blogs({ blogs, mobile }) {
shadowOpacity: 0.8, shadowOpacity: 0.8,
shadowRadius: 2, shadowRadius: 2,
elevation: 5, elevation: 5,
minHeight: 70, height: 85,
}, },
]} ]}
> >
<Text <Text
style={[ style={[
tw("mb-2"), tw("mb-1"),
{ {
color: Colors.theme1[colorScheme].gray20, color: Colors.theme1[colorScheme].gray20,
fontFamily: "regular", fontFamily: "regular",
@ -78,10 +96,14 @@ function Blogs({ blogs, mobile }) {
</Text> </Text>
<View style={[tw("flex flex-row-reverse justify-between")]}> <View style={[tw("flex flex-row-reverse justify-between")]}>
<View style={tw("flex-row-reverse items-center")}> <View style={tw("flex-row-reverse items-center")}>
<View style={{ height: 30 }}>
<Image <Image
resizeMode="contain"
source={userImage} source={userImage}
style={[tw("rounded-full ml-1"), { width: 16, height: 16 }]} style={[tw("rounded-full ml-1"), { width: 20, flex: 1 }]}
/> />
</View>
<Text <Text
style={[ style={[
{ {
@ -107,50 +129,12 @@ function Blogs({ blogs, mobile }) {
> >
۳۰ دقیقه ۳۰ دقیقه
</Text> </Text>
<Svg
xmlns="http://www.w3.org/2000/svg"
width={12.051}
height={12.051}
// {...props}
>
<G
fill="none"
stroke="#818181"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={0.5}
data-name="vuesax/linear/message"
>
<Path d="M4.268 9.54h-.251c-2.013 0-3.013-.502-3.013-3.013v-2.51a2.663 2.663 0 0 1 3.013-3.013h4.017a2.663 2.663 0 0 1 3.013 3.013v2.51A2.663 2.663 0 0 1 8.034 9.54h-.252a.509.509 0 0 0-.4.2l-.753 1a.713.713 0 0 1-1.205 0l-.753-1a.568.568 0 0 0-.403-.2Z" />
<Path
data-name="Vector"
d="M8.032 5.523h0M6.024 5.523h0M4.015 5.523h0"
/>
</G>
</Svg>
</View> </View>
</View> </View>
</View> </View>
</Pressable> </Pressable>
); );
}; };
return (
<View style={[tw("flex flex-col pr-3 mb-5")]}>
<View style={tw("w-full pl-3")}>
<Header title={"خواندنیها"} route={"Blogs"} />
</View>
<FlatList
showsHorizontalScrollIndicator={false}
horizontal={true}
inverted={true}
style={[tw("flex flex-row mt-3 pb-7")]}
data={blogs}
renderItem={({ item }) => <Blog blog={item} />}
keyExtractor={(item) => item.id}
/>
</View>
);
}
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
// features: state.publicApi.home?.features, // features: state.publicApi.home?.features,

@ -22,9 +22,33 @@ import fontSize from "../../../constants/fontSize";
const ios = Platform.OS === "ios"; const ios = Platform.OS === "ios";
function Videos({ videos, grades, mobile }) { function Videos({ videos, grades, mobile }) {
const colorScheme = Appearance.getColorScheme(); return (
const Video = ({ video }) => { <View style={[tw("w-full px-2 mb-5")]}>
<View
style={[
tw("w-full flex flex-col rounded-md pt-2 px-2 overflow-hidden"),
]}
>
<Header title="دورههای ویدئویی شما" route={"VOD"} />
<FlatList
showsHorizontalScrollIndicator={false}
style={[tw("py-3")]}
horizontal={true}
inverted={true}
data={videos}
renderItem={({ item }) => (
<Video video={item} grades={grades} mobile={mobile} />
)}
keyExtractor={(item) => item.id}
/>
</View>
</View>
);
}
const Video = ({ video, mobile, grades }) => {
const navigation = useNavigation(); const navigation = useNavigation();
const colorScheme = Appearance.getColorScheme();
return ( return (
<Pressable <Pressable
style={[ style={[
@ -73,28 +97,7 @@ function Videos({ videos, grades, mobile }) {
</View> </View>
</Pressable> </Pressable>
); );
}; };
return (
<View style={[tw("w-full px-2 mb-5")]}>
<View
style={[
tw("w-full flex flex-col rounded-md pt-2 px-2 overflow-hidden"),
]}
>
<Header title="دورههای ویدئویی شما" route={"VOD"} />
<FlatList
showsHorizontalScrollIndicator={false}
style={[tw("py-3")]}
horizontal={true}
inverted={true}
data={videos}
renderItem={({ item }) => <Video video={item} />}
keyExtractor={(item) => item.id}
/>
</View>
</View>
);
}
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
grades: state.publicApi.grades, grades: state.publicApi.grades,

@ -57,20 +57,19 @@ const Home = ({
back: false, back: false,
}} }}
/> />
<Drawer setBoxPosition={setBoxPosition} position={position} /> <Drawer setBoxPosition={setBoxPosition} position={position} />
<ScrollView <ScrollView
contentContainerStyle={styles.contentContainerStyle} contentContainerStyle={styles.contentContainerStyle}
style={[styles.container]} style={[styles.container]}
> >
{!mobile && <View style={tw("mt-5")}></View>} {!mobile && <View style={tw("mt-5")}></View>}
{userProducts?.length > 0 && <MyBooks books={userProducts} />} <MyBooks books={userProducts} />
<View style={tw("px-4 w-full")}> <View style={tw("px-4 w-full")}>
<Header title={"فروشگاه"} route={"Products"} /> <Header title={"فروشگاه"} route={"Products"} />
</View> </View>
{books?.length > 0 && <Scroll books={books} />} <Scroll books={books} />
{books?.length > 0 && <Videos videos={books} />} <Videos videos={books} />
{blogs?.length > 0 && <Blogs blogs={blogs} />} <Blogs blogs={blogs} />
</ScrollView> </ScrollView>
</SafeAreaView> </SafeAreaView>
); );

@ -9,6 +9,7 @@ import {
Appearance, Appearance,
Pressable, 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";
@ -35,7 +36,15 @@ import Colors from "../../../constants/Colors";
const { height, width } = Dimensions.get("window"); const { height, width } = Dimensions.get("window");
const ios = Platform.OS === "ios"; 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 colorScheme = Appearance.getColorScheme();
const navigation = useNavigation(); const navigation = useNavigation();
const [type, setType] = useState(1); const [type, setType] = useState(1);
@ -49,6 +58,14 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) {
}, 500); }, 500);
}, [type]); }, [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 ( return (
<ScrollView style={[tw("flex flex-col flex-1 relative")]}> <ScrollView style={[tw("flex flex-col flex-1 relative")]}>
{!mobile && <View style={tw("mt-5")}></View>} {!mobile && <View style={tw("mt-5")}></View>}
@ -69,10 +86,12 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) {
)} )}
{imageSlider && <ImageSlider />} {imageSlider && <ImageSlider />}
<View style={tw("flex flex-row-reverse")}> <View style={tw("flex flex-row-reverse")}>
<Image <Image
source={{ uri: `https://dnvn.ir/api/v1/file/${book?.fileIds}` }} source={{ uri: `https://dnvn.ir/api/v1/file/${book?.fileIds}` }}
style={[tw("rounded-md"), { height : height / 4, width : height / 4 * 3 / 4}]} style={[
tw("rounded-md"),
{ height: height / 4, width: ((height / 4) * 3) / 4 },
]}
/> />
<View <View
@ -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")}> <View style={tw("flex flex-row-reverse justify-between flex-wrap py-3")}>
<Pressable <Pressable
style={[ 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, borderWidth: 1,
borderColor: Colors.theme1[colorScheme].greenCF, borderColor: Colors.theme1[colorScheme].greenCF,
@ -215,8 +236,9 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) {
> >
خرید نسخه فیزیکی کتاب خرید نسخه فیزیکی کتاب
</Text> </Text>
<View style={tw("flex flex-row-reverse")}> <View style={tw("flex flex-row-reverse items-center")}>
<View style={tw("w-px h-full bg-green-500")}></View> <View style={tw("w-px h-full bg-green-300")}></View>
<View style={tw("flex")}>
<Text <Text
style={[ style={[
tw("py-1 pr-2"), tw("py-1 pr-2"),
@ -231,6 +253,96 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) {
> >
{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>
{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> </View>
</Pressable> </Pressable>
<Pressable <Pressable
@ -261,8 +373,7 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) {
> >
خرید نسخه دیجیتال کتاب خرید نسخه دیجیتال کتاب
</Text> </Text>
<View style={tw("flex flex-row-reverse")}> <View style={tw("flex")}>
<View style={tw("w-px h-full bg-green-500")}></View>
<Text <Text
style={[ style={[
tw("py-1 pr-2"), tw("py-1 pr-2"),
@ -277,6 +388,95 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) {
> >
{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>
{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> </View>
</Pressable> </Pressable>
<Pressable <Pressable
@ -422,6 +622,7 @@ function Book({ book, grades, pushToCart, userId, loading, mobile }) {
} }
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
userProducts: state.userProduct.list,
userId: state.user.status?.id, userId: state.user.status?.id,
loading: state.userProduct.loading, loading: state.userProduct.loading,
mobile: state.publicApi.mobile, mobile: state.publicApi.mobile,

Loading…
Cancel
Save