fixed delivery from

master
Reza_ashrafi 3 years ago
parent bba4e1cb39
commit f629f48a40
  1. 2
      app.json
  2. 4
      src/redux/actions/transport.js
  3. 6
      src/redux/actions/userAddress.js
  4. 1
      src/redux/actions/userFactor.js
  5. 1
      src/redux/reducers/transport.js
  6. 14
      src/redux/reducers/userAddress.js
  7. 4
      src/redux/reducers/userFactor.js
  8. 84
      src/screens/DeliveryForm/Address/index.js
  9. 2
      src/screens/DeliveryForm/TransportDate/index.js
  10. 30
      src/screens/DeliveryForm/TransportMethod/index.js
  11. 47
      src/screens/DeliveryForm/index.js
  12. 1
      src/screens/Home/components/MyBooks.js
  13. 85
      src/screens/Profile/components/ProfileAddress/index.js
  14. 13
      src/screens/Splash/index.js

@ -6,7 +6,7 @@
"orientation": "portrait", "orientation": "portrait",
"userInterfaceStyle": "automatic", "userInterfaceStyle": "automatic",
"icon": "./assets/appLogo.png", "icon": "./assets/appLogo.png",
"scheme": "danovin", "scheme": "dnvn",
"splash": { "splash": {
"image": "", "image": "",
"resizeMode": "contain", "resizeMode": "contain",

@ -9,8 +9,8 @@ const transport = {
set: set:
(data = {}, data2 = {}, data3 = {}) => (data = {}, data2 = {}, data3 = {}) =>
async (dispatch) => { async (dispatch) => {
await proxy.post("transport/setTransport", data, { dispatch }); await proxy.post("transport/setTransportAndInfo", data, { dispatch });
await proxy.get("userFactor/info", data2, { dispatch }); // await proxy.get("userFactor/info", data2);
}, },
}; };

@ -15,19 +15,17 @@ const userAddress = {
(data = {}, data2 = {}) => (data = {}, data2 = {}) =>
async (dispatch) => { async (dispatch) => {
await proxy.put("userAddress/update", data); await proxy.put("userAddress/update", data);
await proxy.get("userAddress/list", data2, { dispatch });
}, },
add: add:
(data = {}, data2 = {}, data3 = {}) => (data = {}, data2 = {}, data3 = {}) =>
async (dispatch) => { async (dispatch) => {
await proxy.post("userAddress/add", data, { dispatch }); await proxy.post("userAddress/add", data, { dispatch });
await proxy.get("userAddress/list", data2, { dispatch });
}, },
del: del:
(data = {}, data2 = {}) => (data = {}, data2 = {}) =>
async (dispatch) => { async (dispatch) => {
await proxy.delete("userAddress/delete", data); console.log(data);
await proxy.get("userAddress/list", data2, { dispatch }); await proxy.delete("userAddress/delete2", data);
}, },
}; };

@ -42,7 +42,6 @@ const userFactor = {
(data = {}, data2 = {}) => (data = {}, data2 = {}) =>
async (dispatch) => { async (dispatch) => {
await proxy.put("userFactor/update", data, { dispatch }); await proxy.put("userFactor/update", data, { dispatch });
await proxy.get("userFactor/info", data2, { dispatch });
}, },
deleteUserOffCode: deleteUserOffCode:
(data = {}, data2 = {}) => (data = {}, data2 = {}) =>

@ -13,6 +13,7 @@ export default function transport(state = initialState, action) {
list: data, list: data,
error: null, error: null,
}; };
case "transport/info": case "transport/info":
return { ...state, loading: false, error: null}; return { ...state, loading: false, error: null};
case "transport/loading": case "transport/loading":

@ -1,8 +1,9 @@
import { asyncAwesomeAlert } from "../../utils/AsyncWrappers";
const initialState = { const initialState = {
loading: false, loading: false,
error: null, error: null,
list: [], list: [],
info : null, info: null,
}; };
export default function userAddress(state = initialState, action) { export default function userAddress(state = initialState, action) {
let { type, data } = action; let { type, data } = action;
@ -17,14 +18,17 @@ export default function userAddress(state = initialState, action) {
case "userAddress/info": case "userAddress/info":
return { ...state, loading: false, info: data, error: null }; return { ...state, loading: false, info: data, error: null };
case "userAddress/update": case "userAddress/update":
return { ...state, loading: false, error: null }; return { ...state, loading: false, list: data, error: null };
case "userAddress/add": case "userAddress/add":
return { ...state, loading: false, error: null}; return { ...state, loading: false, list: data.list, error: null };
case "userAddress/delete": case "userAddress/delete2":
return { ...state, loading: false, error: null }; return { ...state, loading: false, list: data, error: null };
case "userAddress/loading": case "userAddress/loading":
return { ...state, loading: true }; return { ...state, loading: true };
case "userAddress/error": case "userAddress/error":
asyncAwesomeAlert("خطا", data.message, {
confirmText: "باشه",
});
return { ...state, loading: false, error: data.message }; return { ...state, loading: false, error: data.message };
default: default:
return state; return state;

@ -16,6 +16,8 @@ export default function userFactor(state = initialState, action) {
let { type, data } = action; let { type, data } = action;
switch (type) { switch (type) {
//dnvn //dnvn
case "transport/setTransportAndInfo":
return {...state, false : null, error: null, info : data.factorInfo }
case "userFactor/list": case "userFactor/list":
const checkEmpty = data.filter( const checkEmpty = data.filter(
(item) => item.condition === 2 && item.product.productType === (1 || 3) (item) => item.condition === 2 && item.product.productType === (1 || 3)
@ -46,7 +48,7 @@ export default function userFactor(state = initialState, action) {
case "userFactor/myList": case "userFactor/myList":
return { ...state, loading: false, list: data, error: null }; return { ...state, loading: false, list: data, error: null };
case "userFactor/update": case "userFactor/update":
return { ...state, loading: false, error: null }; return { ...state, loading: false, info: data.factorInfo, error: null };
case "userFactor/deleteUserOffCode": case "userFactor/deleteUserOffCode":
return { ...state, loading: false, error: null }; return { ...state, loading: false, error: null };
case "userFactor/paymentVOD": case "userFactor/paymentVOD":

@ -8,6 +8,7 @@ import {
} from "react-native"; } from "react-native";
import React from "react"; import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { Ionicons, Entypo } from "@expo/vector-icons";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
import { userFactor } from "../../../redux/actions"; import { userFactor } from "../../../redux/actions";
@ -28,61 +29,74 @@ const Address = ({
theme, theme,
}) => { }) => {
const navigation = useNavigation(); const navigation = useNavigation();
const [selectedItem, setSelectedItem] = React.useState(null);
const light = React.useMemo(() => {
return theme === "light";
}, [theme]);
React.useEffect(() => {
if (!loading) {
setSelectedItem(null);
}
}, [loading]);
const Location = ({ address, active }) => { const Location = ({ address, active }) => {
return ( return (
<Pressable <Pressable
style={[ style={[
{ {
backgroundColor: backgroundColor: active
userAddressId === address?.id ? light
? Colors.theme1.greenCF + "15" ? Colors.theme1.greenCF + "15"
: Colors.theme1.grayE3 + "44", : Colors.theme1.dark
: light
? Colors.theme1.grayE3 + "44"
: Colors.theme1.dark,
borderWidth: 1.5, borderWidth: 1.5,
borderColor: borderColor: active ? Colors.theme1.greenCF : Colors.theme1.grayE3,
userAddressId === address?.id
? Colors.theme1.greenCF
: Colors.theme1.grayE3,
}, },
tw( tw(
`flex flex-row-reverse items-center w-full px-3 rounded-sm mt-2 ${ `flex flex-row-reverse items-center w-full px-3 rounded-sm mt-2 ${
mobile ? "py-2" : "py-4" mobile ? "py-3.5" : "py-4"
}` }`
), ),
]} ]}
onPress={() => onPress={() => {
userAddressId === address?.id setSelectedItem(address.id);
? {} active ? {} : update({ userAddressId: address.id, userId });
: update({ userAddressId: address.id, userId }) }}
}
> >
{loading ? ( {selectedItem === address.id && loading ? (
userAddressId !== address?.id ? ( <ActivityIndicator size="small" color={Colors.theme1.greenC8} />
<ActivityIndicator size="small" color={Colors.theme1.greenC8} /> ) : active ? (
) : ( <Entypo
<View name="check"
style={[ size={20}
tw("w-5 h-5 rounded-full"), color={Colors.theme1.greenCF}
{ />
backgroundColor: active ? Colors.theme1.greenCF : "white", ) : (
borderWidth: userAddressId === address?.id ? 4 : 1, <Entypo
borderColor: name="circle"
userAddressId === address?.id size={20}
? Colors.theme1.black color={theme === "light" ? Colors.theme1.grayE3 : Colors.theme1.white}
: Colors.theme1.gray20 + "33", />
}, )}
]}
></View>
)
) : null}
<View style={tw(`flex flex-1 ${mobile ? "mr-2" : "mr-5"}`)}> <View style={tw(`flex flex-1 ${mobile ? "mr-2" : "mr-5"}`)}>
<Text <Text
style={[ style={[
{ {
fontFamily: "regular", fontFamily: "regular",
fontSize: mobile ? fontSize.sm : fontSize.lg, fontSize: mobile ? fontSize.tiny : fontSize.lg,
lineHeight: 22, lineHeight: 22,
textAlign: ios ? "right" : "auto", textAlign: ios ? "right" : "auto",
color: active
? light
? Colors.theme1.gray20
: Colors.theme1.greenCF
: light
? Colors.theme1.gray20
: Colors.theme1.white,
}, },
]} ]}
> >
@ -93,10 +107,6 @@ const Address = ({
); );
}; };
const light = React.useMemo(() => {
return theme === "light";
}, [theme]);
return ( return (
<View style={tw("w-full mt-2")}> <View style={tw("w-full mt-2")}>
<View style={tw("p-0 m-0 flex ")}> <View style={tw("p-0 m-0 flex ")}>

@ -73,7 +73,7 @@ const TransportDate = ({ transportDate, mobile, theme }) => {
}, []); }, []);
return ( return (
<View style={tw(`w-full ${mobile ? "mt-4" : "mt-4"}`)}> <View style={tw(`w-full`)}>
<Text <Text
style={{ style={{
fontSize: mobile ? fontSize.base : fontSize.xl2, fontSize: mobile ? fontSize.base : fontSize.xl2,

@ -31,10 +31,18 @@ const TransportMethod = ({
getList(); getList();
}, []); }, []);
const [selectedItem, setSelectedItem] = React.useState(null);
const light = React.useMemo(() => { const light = React.useMemo(() => {
return theme === "light"; return theme === "light";
}, [theme]); }, [theme]);
React.useEffect(() => {
if (!loading) {
setSelectedItem(null);
}
}, [loading]);
const Method = useCallback( const Method = useCallback(
({ method, active }) => { ({ method, active }) => {
return ( return (
@ -46,26 +54,29 @@ const TransportMethod = ({
}` }`
), ),
{ {
backgroundColor: light ? active backgroundColor: light
? Colors.theme1.greenCF + "15" ? active
: Colors.theme1.grayE3 + "44" : null, ? Colors.theme1.greenCF + "15"
: Colors.theme1.grayE3 + "44"
: null,
borderWidth: 1.5, borderWidth: 1.5,
borderColor: active borderColor: active
? Colors.theme1.greenCF ? Colors.theme1.greenCF
: Colors.theme1.grayE3, : Colors.theme1.grayE3,
}, },
]} ]}
onPress={() => onPress={() => {
setSelectedItem(method.id);
!active !active
? setTransport( ? setTransport(
{ factorId: factorInfo?.id, transportId: method?.id }, { factorId: factorInfo?.id, transportId: method?.id },
{ userId }, { userId },
{} {}
) )
: {} : {};
} }}
> >
{loading && !active ? ( {loading && selectedItem === method.id ? (
<ActivityIndicator <ActivityIndicator
size="small" size="small"
color={ color={
@ -127,6 +138,7 @@ const TransportMethod = ({
}, },
[factorInfo, loading] [factorInfo, loading]
); );
return ( return (
<View style={tw(`w-full ${mobile ? "mt-4" : "mt-4"}`)}> <View style={tw(`w-full ${mobile ? "mt-4" : "mt-4"}`)}>
<Text <Text
@ -140,11 +152,11 @@ const TransportMethod = ({
لطفا یک روش ارسال انتخاب کنید. لطفا یک روش ارسال انتخاب کنید.
</Text> </Text>
<View style={tw("p-0 m-0 flex w-full")}> <View style={tw("p-0 m-0 flex w-full")}>
{list?.map((method, index) => ( {factorInfo?.transports?.map((method, index) => (
<Method <Method
method={method} method={method}
active={factorInfo.transportId === method?.id}
key={index} key={index}
active={factorInfo?.transportId === method?.id}
/> />
))} ))}
</View> </View>

@ -5,6 +5,7 @@ import {
StyleSheet, StyleSheet,
StatusBar, StatusBar,
Platform, Platform,
Dimensions,
} from "react-native"; } from "react-native";
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
@ -23,6 +24,8 @@ import CustomPressable from "../../components/Pressable";
import tw from "tailwind-rn"; import tw from "tailwind-rn";
import Colors from "../../constants/Colors"; import Colors from "../../constants/Colors";
const { height } = Dimensions.get("window");
const DeliveryForm = ({ const DeliveryForm = ({
list, list,
form, form,
@ -50,6 +53,8 @@ const DeliveryForm = ({
style={{ style={{
paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0, paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0,
position: "relative", position: "relative",
paddingHorizontal: 16,
flex: 1,
}} }}
> >
<Navbar <Navbar
@ -64,6 +69,7 @@ const DeliveryForm = ({
}} }}
/> />
<ScrollView <ScrollView
showsVerticalScrollIndicator={false}
contentContainerStyle={styles.contentContainerStyle} contentContainerStyle={styles.contentContainerStyle}
style={styles.container} style={styles.container}
> >
@ -74,26 +80,30 @@ const DeliveryForm = ({
<View style={tw("w-full flex flex-row mt-5")}> <View style={tw("w-full flex flex-row mt-5")}>
<TransportMethod /> <TransportMethod />
</View> </View>
<View style={tw("w-full flex flex-row mt-5 mb-5")}> {factorInfo.transportId === 2 ? (
<TransportDate transportDate={form.transportDate} /> <View style={tw("w-full flex flex-row mt-5 mb-5")}>
</View> <TransportDate transportDate={form.transportDate} />
<CustomPressable </View>
title={"پرداخت"} ) : null}
backgroundColor={Colors.theme1.greenCF}
color={"white"}
border={{ color: "#196EC0", width: 0 }}
width={"100%"}
onPress={() =>
factorInfo.transportId && factorInfo.userAddressId
? payFactor({ userId })
: asyncAwesomeAlert("خطا", "آدرس یا نحوه ارسال را وارد کنید", {
showCancelButton: false,
confirmText: "باشه",
})
}
/>
</View> </View>
</ScrollView> </ScrollView>
<View style={tw("w-full pt-4")}>
<CustomPressable
title={"پرداخت"}
backgroundColor={Colors.theme1.greenCF}
color={"white"}
border={{ color: "#196EC0", width: 0 }}
width={"100%"}
onPress={() =>
factorInfo.transportId && factorInfo.userAddressId
? payFactor({ userId })
: asyncAwesomeAlert("خطا", "آدرس یا نحوه ارسال را وارد کنید", {
showCancelButton: false,
confirmText: "باشه",
})
}
/>
</View>
</SafeAreaView> </SafeAreaView>
); );
}; };
@ -104,7 +114,6 @@ const styles = StyleSheet.create({
}, },
container: { container: {
paddingVertical: 5, paddingVertical: 5,
paddingHorizontal: 16,
}, },
}); });

@ -20,7 +20,6 @@ import fontSize from "../../../constants/fontSize";
const ios = Platform.OS === "ios"; const ios = Platform.OS === "ios";
function MyBooks({ books, grades, theme }) { function MyBooks({ books, grades, theme }) {
console.log(books);
return books?.filter((book) => book.condition >= 2).length ? ( return books?.filter((book) => book.condition >= 2).length ? (
<View style={[tw("flex w-full mb-5")]}> <View style={[tw("flex w-full mb-5")]}>
<View <View

@ -29,6 +29,7 @@ import Colors from "../../../../constants/Colors";
import fontSize from "../../../../constants/fontSize"; import fontSize from "../../../../constants/fontSize";
const ios = Platform.OS === "ios"; const ios = Platform.OS === "ios";
const { height, width } = Dimensions.get("window");
const ProfileAddress = ({ const ProfileAddress = ({
addresses, addresses,
@ -43,7 +44,7 @@ const ProfileAddress = ({
deleteItem, deleteItem,
}) => { }) => {
const navigation = useNavigation(); const navigation = useNavigation();
const [height, setHeight] = React.useState(Dimensions.get("window").height); const [height, setHeight] = React.useState(height);
const Location = ({ address, active }) => { const Location = ({ address, active }) => {
return ( return (
<Pressable <Pressable
@ -51,8 +52,12 @@ const ProfileAddress = ({
{ {
backgroundColor: backgroundColor:
userAddressId === address?.id userAddressId === address?.id
? Colors.theme1.greenCF + "0a" ? theme === "light"
: Colors.theme1.grayE3 + "44", ? Colors.theme1.greenCF + "0a"
: Colors.theme1.dark
: theme === "light"
? Colors.theme1.grayE3 + "44"
: Colors.theme1.dark,
borderWidth: 2, borderWidth: 2,
borderColor: borderColor:
userAddressId === address?.id userAddressId === address?.id
@ -60,7 +65,7 @@ const ProfileAddress = ({
: Colors.theme1.grayE3, : Colors.theme1.grayE3,
}, },
tw( tw(
`flex flex-row-reverse items-center w-full px-3 py-2 rounded-md mt-2` `flex flex-row-reverse items-center w-full px-3 py-2 rounded-md mb-4`
), ),
]} ]}
onPress={() => onPress={() =>
@ -79,7 +84,12 @@ const ProfileAddress = ({
style={{ style={{
fontSize: fontSize.base, fontSize: fontSize.base,
fontFamily: "bold", fontFamily: "bold",
color: Colors.theme1.gray20, color:
theme === "light"
? Colors.theme1.gray20
: active
? Colors.theme1.greenCF
: Colors.theme1.white,
}} }}
> >
آدرس انتخابی شما آدرس انتخابی شما
@ -88,7 +98,12 @@ const ProfileAddress = ({
style={{ style={{
fontSize: fontSize.xs, fontSize: fontSize.xs,
fontFamily: "regular", fontFamily: "regular",
color: Colors.theme1.gray20, color:
theme === "light"
? Colors.theme1.gray20
: active
? Colors.theme1.greenCF
: Colors.theme1.white,
marginRight: 10, marginRight: 10,
}} }}
> >
@ -100,7 +115,13 @@ const ProfileAddress = ({
<Ionicons <Ionicons
name="ios-pencil-sharp" name="ios-pencil-sharp"
size={20} size={20}
color={theme === "light" ? "#52796F" : Colors.theme1.white} color={
theme === "light"
? "#52796F"
: active
? Colors.theme1.greenCF
: Colors.theme1.white
}
/> />
</Pressable> </Pressable>
<Pressable <Pressable
@ -116,7 +137,13 @@ const ProfileAddress = ({
<Ionicons <Ionicons
name="trash-bin" name="trash-bin"
size={20} size={20}
color={theme === "light" ? "#52796F" : Colors.theme1.white} color={
theme === "light"
? "#52796F"
: active
? Colors.theme1.greenCF
: Colors.theme1.white
}
/> />
</Pressable> </Pressable>
</View> </View>
@ -131,6 +158,12 @@ const ProfileAddress = ({
fontSize: mobile ? fontSize.sm : fontSize.lg, fontSize: mobile ? fontSize.sm : fontSize.lg,
lineHeight: 22, lineHeight: 22,
textAlign: ios ? "right" : "auto", textAlign: ios ? "right" : "auto",
color:
theme === "light"
? Colors.theme1.gray20
: active
? Colors.theme1.greenCF
: Colors.theme1.white,
}, },
]} ]}
> >
@ -144,6 +177,12 @@ const ProfileAddress = ({
fontSize: mobile ? fontSize.sm : fontSize.lg, fontSize: mobile ? fontSize.sm : fontSize.lg,
lineHeight: 22, lineHeight: 22,
textAlign: ios ? "right" : "auto", textAlign: ios ? "right" : "auto",
color:
theme === "light"
? Colors.theme1.gray20
: active
? Colors.theme1.greenCF
: Colors.theme1.white,
}, },
]} ]}
> >
@ -157,6 +196,12 @@ const ProfileAddress = ({
fontSize: mobile ? fontSize.sm : fontSize.lg, fontSize: mobile ? fontSize.sm : fontSize.lg,
lineHeight: 22, lineHeight: 22,
textAlign: ios ? "right" : "auto", textAlign: ios ? "right" : "auto",
color:
theme === "light"
? Colors.theme1.gray20
: active
? Colors.theme1.greenCF
: Colors.theme1.white,
}, },
]} ]}
> >
@ -170,6 +215,12 @@ const ProfileAddress = ({
fontSize: mobile ? fontSize.sm : fontSize.lg, fontSize: mobile ? fontSize.sm : fontSize.lg,
lineHeight: 22, lineHeight: 22,
textAlign: ios ? "right" : "auto", textAlign: ios ? "right" : "auto",
color:
theme === "light"
? Colors.theme1.gray20
: active
? Colors.theme1.greenCF
: Colors.theme1.white,
}, },
]} ]}
> >
@ -182,7 +233,13 @@ const ProfileAddress = ({
<Ionicons <Ionicons
name="ios-pencil-sharp" name="ios-pencil-sharp"
size={20} size={20}
color={theme === "light" ? "#52796F" : Colors.theme1.white} color={
theme === "light"
? "#52796F"
: active
? Colors.theme1.greenCF
: Colors.theme1.white
}
/> />
</Pressable> </Pressable>
<Pressable <Pressable
@ -198,7 +255,13 @@ const ProfileAddress = ({
<Ionicons <Ionicons
name="trash-bin" name="trash-bin"
size={20} size={20}
color={theme === "light" ? "#52796F" : Colors.theme1.white} color={
theme === "light"
? "#52796F"
: active
? Colors.theme1.greenCF
: Colors.theme1.white
}
/> />
</Pressable> </Pressable>
</View> </View>
@ -328,7 +391,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(ProfileAddress);
const styles = StyleSheet.create({ const styles = StyleSheet.create({
contentContainerStyle: { contentContainerStyle: {
paddingBottom: 100, paddingBottom: height,
position: "relative", position: "relative",
}, },
container: { container: {

@ -37,12 +37,13 @@ function Splash({
); );
}, [theme]); }, [theme]);
useEffect(async () => { const getTheme = async () => {
// console.log(isLogin);
// set theme
const theme = await AsyncStorage.getItem("theme"); const theme = await AsyncStorage.getItem("theme");
setIsDark(theme); setIsDark(theme);
};
useEffect(() => {
getTheme();
if (isLogin !== null) { if (isLogin !== null) {
if (isLogin === false) { if (isLogin === false) {
setOut(true); setOut(true);
@ -57,13 +58,11 @@ function Splash({
} else { } else {
setOut(true); setOut(true);
navigation.navigate("Root"); navigation.navigate("Root");
} }
} }
}else{ } else {
} }
}, [isLogin]); }, [isLogin, books, userProducts, blogs]);
if (isFocused && out) { if (isFocused && out) {
setOut(false); setOut(false);

Loading…
Cancel
Save