diff --git a/navigation.js b/navigation.js
index 4c87c36..12feeb6 100644
--- a/navigation.js
+++ b/navigation.js
@@ -5,6 +5,7 @@ import Splash from './src/screens/Splash';
import Home from './src/screens/Home';
import Login from './src/screens/Login';
import Otp from './src/screens/Otp';
+<<<<<<< HEAD
import Product from './src/screens/Product';
import Products from './src/screens/Products';
import ShoppingCart from './src/screens/ShoppingCart';
@@ -16,10 +17,20 @@ const mapStateToProps = state => {
profile: state.profile,
};
};
+=======
+import {connect} from 'react-redux';
+
+const mapStateToProps = state => {
+ return {
+ profile: state.profile
+ }
+}
+>>>>>>> 93c1e23879a6378e3a83f8947b0d8051717854b3
const Stack = createNativeStackNavigator();
function Navigator(props) {
+<<<<<<< HEAD
return (
@@ -69,6 +80,18 @@ function Navigator(props) {
);
+=======
+ return (
+
+
+
+
+
+
+
+
+ );
+>>>>>>> 93c1e23879a6378e3a83f8947b0d8051717854b3
}
export default connect(mapStateToProps)(Navigator);
diff --git a/package-lock.json b/package-lock.json
index 5a79a49..e3ceb65 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -20515,6 +20515,11 @@
"resolved": "https://registry.npmjs.org/react-native-select-dropdown/-/react-native-select-dropdown-1.2.0.tgz",
"integrity": "sha512-qFbldUJFjcruyEmxQThuUtsPYGt7aGYrVtgDfivuJCodjGJEFed2DvcZUd9JJYk1uWe/OfSxWi2KsXYeoB2ZIw=="
},
+ "react-native-swiper-flatlist": {
+ "version": "3.0.15",
+ "resolved": "https://registry.npmjs.org/react-native-swiper-flatlist/-/react-native-swiper-flatlist-3.0.15.tgz",
+ "integrity": "sha512-ajWTGChYE2KuJ/LsHShZG5KnM6ZfytMER3YqeDMqJLtFmxUqq9SFrfsvV7SBChbGtKg82rVx9lzfsAwp9q/qJw=="
+ },
"react-native-vector-icons": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/react-native-vector-icons/-/react-native-vector-icons-8.1.0.tgz",
diff --git a/package.json b/package.json
index 065c367..f14a85e 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,7 @@
"react-native-safe-area-context": "^3.3.2",
"react-native-screens": "^3.8.0",
"react-native-select-dropdown": "^1.2.0",
+ "react-native-swiper-flatlist": "^3.0.15",
"react-native-vector-icons": "^8.1.0",
"react-redux": "^7.2.5",
"redux": "^4.1.1",
diff --git a/src/components/FormButton.js b/src/components/FormButton.js
index 6aa5c17..6d4af07 100644
--- a/src/components/FormButton.js
+++ b/src/components/FormButton.js
@@ -28,4 +28,4 @@ export default function FormButton({text, color, onPress}) {
{text}
);
-}
\ No newline at end of file
+}
diff --git a/src/screens/Home/components/backgroundTile.js b/src/screens/Home/components/backgroundTile.js
index 13d5a38..1459dc8 100644
--- a/src/screens/Home/components/backgroundTile.js
+++ b/src/screens/Home/components/backgroundTile.js
@@ -24,7 +24,10 @@ const backgroundTile = ({ item }) => {
const styles = StyleSheet.create({
container: {
margin: 5,
- borderRadius: 10
+ borderRadius: 10,
+ overflow: 'hidden',
+ alignItems: 'center',
+ justifyContent: 'center',
},
cover: {
minHeight: "100%",
@@ -36,7 +39,7 @@ const styles = StyleSheet.create({
},
title: {
fontSize: 21,
- fontWeight: 600,
+ fontWeight: '600',
marginBottom: 5,
color: "white"
},
diff --git a/src/screens/Home/components/carousel.js b/src/screens/Home/components/carousel.js
index 13325df..42bdfdf 100644
--- a/src/screens/Home/components/carousel.js
+++ b/src/screens/Home/components/carousel.js
@@ -1,27 +1,27 @@
import React from "react";
import { ImageBackground, Dimensions, StyleSheet, View } from "react-native";
-// import { SwiperFlatList } from "react-native-swiper-flatlist";
+import { SwiperFlatList } from "react-native-swiper-flatlist";
const Carousel = ({ list }) => {
return (
- {/* (*/}
- {/* */}
- {/* */}
- {/* */}
- {/* )}*/}
- {/*/>*/}
+ (
+
+
+
+ )}
+ />
);
};
diff --git a/src/screens/Home/components/flexAround.js b/src/screens/Home/components/flexAround.js
index 1ac1e81..8e091bd 100644
--- a/src/screens/Home/components/flexAround.js
+++ b/src/screens/Home/components/flexAround.js
@@ -39,7 +39,7 @@ const styles = StyleSheet.create({
},
title: {
fontSize: 21,
- fontWeight: 600,
+ fontWeight: '600',
marginBottom: 5,
color: "white"
},
diff --git a/src/screens/Home/components/shop.js b/src/screens/Home/components/shop.js
index 9e21efc..ca93321 100644
--- a/src/screens/Home/components/shop.js
+++ b/src/screens/Home/components/shop.js
@@ -45,7 +45,7 @@ const styles = StyleSheet.create({
},
title: {
fontSize: 18,
- fontWeight: 600,
+ fontWeight: '600',
marginBottom: 5,
color: "white"
}
diff --git a/src/screens/Home/index.js b/src/screens/Home/index.js
index 73e83eb..88b8961 100644
--- a/src/screens/Home/index.js
+++ b/src/screens/Home/index.js
@@ -6,7 +6,7 @@ import Identifier from "./components/Identifier";
// Within your render function
function Home() {
return (
-
+
{data?.map((item, i) => (
))}
@@ -16,11 +16,14 @@ function Home() {
// Later on in your styles..
const styles = StyleSheet.create({
+ contentContainerStyle: {
+ paddingBottom: 50
+ },
container: {
width: Dimensions.get("window").width,
backgroundColor: "white",
flexDirection: "column",
- padding: 5
+ padding: 5,
}
});
diff --git a/src/screens/Login/index.js b/src/screens/Login/index.js
index 4350ef9..6b88815 100644
--- a/src/screens/Login/index.js
+++ b/src/screens/Login/index.js
@@ -1,5 +1,5 @@
import React, {useState} from 'react';
-import {View, Text, Image, Button, Dimensions, TextInput, TouchableHighlight} from 'react-native';
+import {View, Text, Image, ActivityIndicator, Dimensions, TextInput, TouchableHighlight} from 'react-native';
import Logo from '../../assets/images/logo.png';
import IranFlag from "./components/IranFlag";
import {digitToEn, digitToPersian} from "../../utils";
@@ -12,6 +12,7 @@ let faNums = ['۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', '۰']
function Login(props) {
const [phone, setPhone] = useState('');
+ const [loading, setLoading] = useState(false)
const onChangePhone = (value) => {
let items = digitToPersian(value).split('');
@@ -28,15 +29,19 @@ function Login(props) {
}
const submit = async () => {
- // if (!checkPhoneNumber()) {
- // return asyncAwesomeAlert('خطا', 'شماره وارد شده اشتباه است', {showCancelButton: false});
- // }
- // let res = await services.getSmsCode({
- // cellphone: '09' + digitToEn(phone)
- // })
- // if (res.ok) {
- props.navigation.navigate('Otp', {phone: phone});
- // }
+ setLoading(true)
+ if (!checkPhoneNumber()) {
+ setLoading(false)
+ return asyncAwesomeAlert('خطا', 'شماره وارد شده اشتباه است', {showCancelButton: false});
+ }
+ let res = await services.getSmsCode({
+ cellphone: '09' + digitToEn(phone)
+ })
+ if (res.ok) {
+ setLoading(false)
+ props.navigation.navigate('Otp', {phone: '09' + digitToEn(phone)});
+ }
+ setLoading(false)
}
return (
@@ -91,12 +96,15 @@ function Login(props) {
color: '#a2a2a2',
fontSize: 18
}}
+ maxLength={9}
underlineColorAndroid={'transparent'}
value={phone}
onChangeText={text => onChangePhone(text)}
/>
- submit()}>
-
- {'ادامه'}
-
+ {loading ?
+
+ :
+
+ {'ادامه'}
+
+ }
);
diff --git a/src/screens/Otp/index.js b/src/screens/Otp/index.js
index bc32e28..ae13eea 100644
--- a/src/screens/Otp/index.js
+++ b/src/screens/Otp/index.js
@@ -1,10 +1,23 @@
import React, {useEffect, useState} from 'react'
-import {View, Text, Image, TextInput, TouchableHighlight, Dimensions, StyleSheet, TouchableOpacity} from 'react-native';
+import {
+ View,
+ Text,
+ Image,
+ TextInput,
+ TouchableHighlight,
+ Dimensions,
+ StyleSheet,
+ TouchableOpacity,
+ ActivityIndicator
+} from 'react-native';
import {connect} from 'react-redux';
import Logo from "../../assets/images/logo.png";
import IranFlag from "../Login/components/IranFlag";
import {digitToEn, digitToPersian} from "../../utils";
import services from "./services";
+import AsyncStorage from "@react-native-community/async-storage";
+import {buildAction} from "../../reducers/DefaultReducer";
+import {PROFILE_RECORD} from "../../actions/actionTypes";
const {width} = Dimensions.get('window')
let ref1;
@@ -13,6 +26,13 @@ let ref3;
let ref4;
let timer = 60;
+
+const mapStateToProps = state => {
+ return {
+ profile: state.profile,
+ }
+}
+
function Otp(props) {
let faNums = ['۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', '۰']
@@ -21,6 +41,7 @@ function Otp(props) {
const [thirdCode, setThirdCode] = useState('');
const [fourthCode, setFourthCode] = useState('');
const [time, setTime] = useState(60);
+ const [loading, setLoading] = useState(false);
const checkValue = (value) => {
return faNums.includes(digitToPersian(value));
@@ -45,6 +66,7 @@ function Otp(props) {
break;
case '4':
setFourthCode(digitToPersian(value))
+ submit();
break;
}
}
@@ -54,13 +76,29 @@ function Otp(props) {
}
const submit = async () => {
+ setLoading(true)
let res = await services.sendOtpCode({
cellphone: props.route.params.phone,
- otp: getEnCode()
+ otp: String(getEnCode()),
+ applicationToken: "1",
+ userToken: "1"
})
if (res.ok) {
- console.log(res)
+ setLoading(false)
+ await AsyncStorage.setItem('accessToken', res.data.accessToken);
+ await AsyncStorage.setItem('refreshToken', res.data.refreshToken);
+ let action = buildAction(PROFILE_RECORD);
+ await props.dispatch(action({
+ accessToken: res.data.accessToken,
+ refreshToken: res.data.refreshToken,
+ ...res.data.profile,
+ }))
+ props.navigation.reset({
+ index: 0,
+ routes: [{name: 'Home'}]
+ })
}
+ setLoading(false)
}
useEffect(() => {
@@ -148,6 +186,7 @@ function Otp(props) {
/>
submit()}>
-
- {'ثبت'}
-
+ {loading ?
+ :
+
+ {'ثبت'}
+
+ }
@@ -174,10 +216,10 @@ function Otp(props) {
marginTop: 20,
}}
onPress={() => {
- if (time !== 0) {
- return
- }
- props.navigation.goBack();
+ props.navigation.reset({
+ index: 0,
+ routes: [{ name: 'Login' }],
+ });
}}>
{'بازگشت به مرحله قبل و اصلاح شماره'}
@@ -193,11 +235,11 @@ const styles = StyleSheet.create({
width: width / 13 * 2,
height: width / 16 * 2,
backgroundColor: '#a2a2a2',
- color: '#333',
+ color: '#000',
fontSize: 22,
borderRadius: 8,
textAlign: 'center'
}
})
-export default Otp;
+export default connect(mapStateToProps)(Otp);
diff --git a/src/screens/Splash/index.js b/src/screens/Splash/index.js
index 7aeb776..8626f08 100644
--- a/src/screens/Splash/index.js
+++ b/src/screens/Splash/index.js
@@ -15,7 +15,7 @@ function Splash({navigation, profile}) {
useEffect(() => {
setTimeout(() => {
- !profile.token ? navigation.reset({
+ !profile.accessToken ? navigation.reset({
index: 0,
// routes: [{ name: 'Login' }],
routes: [{ name: 'QR' }],
@@ -25,7 +25,7 @@ function Splash({navigation, profile}) {
routes: [{ name: 'Home' }],
})
}, 2000)
- }, [])
+ }, [profile])
return (
diff --git a/src/services/api/index.js b/src/services/api/index.js
index ded1550..138586b 100644
--- a/src/services/api/index.js
+++ b/src/services/api/index.js
@@ -51,9 +51,14 @@ export async function fetchApi(
if (['POST', 'PUT'].includes(method)) {
options.body = JSON.stringify(payload);
}
+ console.log('===========================')
+ console.log(await getUrl(endPoint, dev))
+ console.log(options)
+ console.log('===========================')
try {
// console.log('req', await getUrl(endPoint), options)
let res = await fetchRetry(await getUrl(endPoint, dev), options);
+
clearTimeout(timeout);
let statusCode = res.status;
// console.log('RES', { statusCode, url: await getUrl(endPoint) })
@@ -77,9 +82,14 @@ export async function fetchApi(
return data;
}
if (!res.ok) {
- if (data.hasOwnProperty('message')) {
- toastMessage(data.message);
- }
+ // if (data.hasOwnProperty('message')) {
+ // toastMessage(data.message);
+ // }
+ console.log('=====================')
+ console.log(statusCode)
+ console.log(data)
+ console.log(error)
+ console.log('=====================')
if (statusCode === 403) {
console.log('req-401', await getUrl(endPoint), options);
diff --git a/src/services/api/utils.js b/src/services/api/utils.js
index c818ce6..87eb8f5 100644
--- a/src/services/api/utils.js
+++ b/src/services/api/utils.js
@@ -42,9 +42,7 @@ export const unexpectedAlert = async () => {
// ])
}
export const getToken = async () => {
- let user = await AsyncStorage.getItem('UID_USER')
- if (!user) return ''
- let { token } = JSON.parse(user)
+ let token = await AsyncStorage.getItem('accessToken')
if (!token) {
return ''
}
@@ -68,7 +66,7 @@ export const getUrl = async (endpoint, dev) => {
return apiConfig.splash + endpoint
}
let base_urls = await getBaseUrls()
- return base_urls.backend + endpoint
+ return base_urls + endpoint
}
export const isUnexpected = (statusCode) => {
@@ -77,8 +75,8 @@ export const isUnexpected = (statusCode) => {
}
export const renewTokenHandler = async () => {
try {
- let splashData = JSON.parse(await AsyncStorage.getItem('UID_USER'))
- if (!splashData || !splashData.refresh_token) {
+ let refreshToken = JSON.parse(await AsyncStorage.getItem('refreshToken'))
+ if (!refreshToken) {
return {
ok: false,
restart: true
@@ -87,7 +85,7 @@ export const renewTokenHandler = async () => {
const options = {
method: 'POST',
body: JSON.stringify({
- refresh_token: splashData.refresh_token
+ refresh_token: refreshToken
}),
headers: {
Accept: 'application/json;charset=utf-8',
@@ -98,8 +96,8 @@ export const renewTokenHandler = async () => {
let { data } = await res.json()
const statusCode = res.status
if (statusCode == 200) {
- splashData.token = data.token
- await AsyncStorage.setItem('UID_USER', JSON.stringify(splashData))
+ await AsyncStorage.setItem('refreshToken', JSON.stringify(data.refreshToken))
+ await AsyncStorage.setItem('accessToken', JSON.stringify(data.accessToken))
return {
ok: true
}
diff --git a/src/utils/index.js b/src/utils/index.js
index da0241d..19396f9 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -21,3 +21,9 @@ export const digitToEn = (digit) => {
}
return digitArray.join('')
}
+
+export const waitToFinish = async (setLoading, func) => {
+ setLoading(true);
+ await func();
+ setLoading(false)
+}