diff --git a/App.js b/App.js index 8959043..4d7e38b 100644 --- a/App.js +++ b/App.js @@ -1,5 +1,5 @@ -import React from 'react'; -import { NativeRouter, Route } from 'react-router-native'; +import React, { useState } from 'react'; +import { NativeRouter, Route, useHistory } from 'react-router-native'; import HomeScreen from './screens/Home'; import Login from './screens/signIn'; import SignUp from './screens/SignUp'; @@ -7,19 +7,81 @@ import SearchScreen from './screens/Search'; import FavoritesScreen from './screens/Favorites'; import OrdersScreen from './screens/Orders'; import ProfileScreen from './screens/Profile'; -// import BottomTabBar from './components/BottomTabBar'; +import WelcomePage from './screens/Welcome'; +import BottomTabBar from './components/BottomTabBar'; + +const App = () => { + const [clientData, setClientData] = useState(); -export default function App() { return ( - - - - - - - - {/* */} + } + /> + } + /> + } + /> + ( + <> + + + + )} + /> + ( + <> + + + + )} + /> + ( + <> + + + + )} + /> + ( + <> + + + + )} + /> + ( + <> + + + + )} + /> ); -} +}; + +export default App; diff --git a/Utils/fetchData.js b/Utils/fetchData.js index 1940688..d1c6b6d 100644 --- a/Utils/fetchData.js +++ b/Utils/fetchData.js @@ -10,7 +10,19 @@ const fetchData = async (route, body, method) => { or product api: https://food-app-delivery.herokuapp.com/api/v1/ */ - return axios.get(api.concat(route)).then(({ data }) => data).catch(() => 'Error get data'); + return axios + .get( + api.concat(route), + body + ? { + params: { + token: body, + }, + } + : {} + ) + .then(({ data }) => data) + .catch(() => 'Error get data'); default: return axios[method](api.concat(route), body).then(({ data }) => data); diff --git a/Utils/secureStorage.js b/Utils/secureStorage.js index f1303d7..9773e0c 100644 --- a/Utils/secureStorage.js +++ b/Utils/secureStorage.js @@ -6,6 +6,9 @@ export default { }, getStoreSecure: async () => { const data = await SecureStore.getItemAsync('token'); - return data; + return JSON.parse(data); + }, + deleteStoreSecure: async () => { + await SecureStore.deleteItemAsync('token'); }, }; diff --git a/components/BottomTabBar/index.js b/components/BottomTabBar/index.js index 8b1be65..98d9fa1 100644 --- a/components/BottomTabBar/index.js +++ b/components/BottomTabBar/index.js @@ -2,9 +2,7 @@ import React, { useState, useRef } from 'react'; import { useHistory } from 'react-router-native'; -import { - SafeAreaView, TouchableOpacity, View, -} from 'react-native'; +import { SafeAreaView, TouchableOpacity, View } from 'react-native'; import { Transitioning, Transition } from 'react-native-reanimated'; import Profile from './icons/Profile'; import Search from './icons/Search'; @@ -13,14 +11,14 @@ import Favorites from './icons/Favorites'; import Orders from './icons/Orders'; import styles from './style'; -const TabBar = () => { - const [active, setActive] = useState(0); +const TabBar = ({ tab }) => { + const [active, setActive] = useState(tab); const history = useHistory(); const transition = ; const ref = useRef(); const tabs = [ - { icon: , route: '/' }, + { icon: , route: '/home' }, { icon: , route: '/search' }, { icon: , route: '/favorites' }, { icon: , route: '/orders' }, @@ -34,10 +32,13 @@ const TabBar = () => { // https://docs.expo.io/versions/latest/sdk/reanimated/ ref={ref} style={styles.centerAll} - transition={transition}> + transition={transition} + > {tabs.map(({ icon, route }, index) => ( - { setActive(index); history.push(route); diff --git a/package-lock.json b/package-lock.json index d53f13e..b357e33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4529,19 +4529,6 @@ } } }, - "history": { - "version": "4.10.1", - "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz", - "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==", - "requires": { - "@babel/runtime": "^7.1.2", - "loose-envify": "^1.2.0", - "resolve-pathname": "^3.0.0", - "tiny-invariant": "^1.0.2", - "tiny-warning": "^1.0.0", - "value-equal": "^1.0.1" - } - }, "hoist-non-react-statics": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", diff --git a/screens/Home/index.js b/screens/Home/index.js index a0d700b..89d5e00 100644 --- a/screens/Home/index.js +++ b/screens/Home/index.js @@ -2,7 +2,7 @@ import React from 'react'; import { Text, View } from 'react-native'; import styles from './style'; -const Home = () => ( +const Home = ({ clientData }) => ( Home diff --git a/screens/Profile/index.js b/screens/Profile/index.js index 955c340..8781974 100644 --- a/screens/Profile/index.js +++ b/screens/Profile/index.js @@ -2,10 +2,10 @@ import React from 'react'; import { Text, View } from 'react-native'; import styles from './style'; -const Profile = () => ( - - Profile - +const Profile = ({ clientData }) => ( + + {clientData.name} + ); export default Profile; diff --git a/screens/SignUp/index.js b/screens/SignUp/index.js index 62f03eb..3fda394 100644 --- a/screens/SignUp/index.js +++ b/screens/SignUp/index.js @@ -1,6 +1,13 @@ /* eslint-disable camelcase */ import React, { useState } from 'react'; -import { Text, Image, ImageBackground, View, ToastAndroid } from 'react-native'; +import { + Text, + Image, + ImageBackground, + ActivityIndicator, + View, + ToastAndroid, +} from 'react-native'; import { useHistory } from 'react-router-native'; import TextInput from '../../components/TextInput'; @@ -13,25 +20,30 @@ import logo from '../../assets/logo.png'; import Picker from '../../components/Picker'; import styles from './style'; -const SignUpPage = () => { +const SignUpPage = ({ setClientData }) => { const [name, setName] = useState(); const [mobile_number, setMobileNumber] = useState(); const [password, setPassword] = useState(); const [location, setLocation] = useState(); const [address, setAddress] = useState(); + const [loading, setLoading] = useState(0); + const history = useHistory(); const signUp = async () => { // api post request try { - const { role } = await API( + setLoading(true); + const { CLIENT_TOKEN, client_Data } = await API( 'auth/client/signup', { name, password, mobile_number, location, address }, 'post' ); - storage.storeSecure(role); + setClientData(client_Data); + storage.storeSecure(CLIENT_TOKEN); history.push('home'); } catch (err) { + setLoading(false); ToastAndroid.show( ' حصل خطأ أثناء إنشاء الحساب يرجى التأكد من جميع بياناتك و المحاولة مرة أخرى', ToastAndroid.LONG, @@ -46,54 +58,67 @@ const SignUpPage = () => { إنشاء حساب جديد - setName(value)} - placeholder='الإسم' - icon - /> - setMobileNumber(value)} - placeholder='رقم الهاتف' - maxLength={10} - keyboardType={'phone-pad'} - icon={{ icon: 'mobile' }} - /> - setPassword(value)} - placeholder='كلمة المرور' - icon={{ icon: 'key' }} - /> - setLocation(value)} /> + {loading ? ( + + ) : ( + <> + setName(value)} + placeholder='الإسم' + icon + /> + setMobileNumber(value)} + placeholder='رقم الهاتف' + maxLength={10} + keyboardType={'phone-pad'} + icon={{ icon: 'mobile' }} + /> + setPassword(value)} + placeholder='كلمة المرور' + icon={{ icon: 'key' }} + /> + setLocation(value)} + /> - setAddress(value)} - placeholder='العنوان' - icon={{ icon: 'home' }} - /> + setAddress(value)} + placeholder='العنوان' + icon={{ icon: 'home' }} + /> - -