-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from alaa-m1/develop
Develop
- Loading branch information
Showing
23 changed files
with
383 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GOOGLE_CLIENT_ID=677045750668-2q9sf1tslrep7843hb1gl95lv9oa3g4h.apps.googleusercontent.com | ||
GOOGLE_CLIENT_ID2=677045750668-09gkkjn4bp9phf77ckjpr3btc91219on.apps.googleusercontent.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<resources> | ||
<string name="app_name">EcommerceReactNative</string> | ||
<string name="server_client_id">677045750668-2q9sf1tslrep7843hb1gl95lv9oa3g4h.apps.googleusercontent.com</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
import {GestureResponderEvent, View} from 'react-native'; | ||
import {Header, SignIn} from './components'; | ||
import {GestureResponderEvent, StyleSheet, View} from 'react-native'; | ||
import {Header, SignIn, SignUp} from './components'; | ||
import { sharedStyles } from '~/shared'; | ||
|
||
const AuthPage = () => { | ||
const handleNavBackPress = (event: GestureResponderEvent) => { | ||
console.log('111111'); | ||
}; | ||
return ( | ||
<View> | ||
<View style={styles.container}> | ||
<Header title="Sign In" onNavBackPress={handleNavBackPress} /> | ||
<SignIn /> | ||
<SignIn style={styles.page} /> | ||
</View> | ||
); | ||
}; | ||
|
||
export default AuthPage; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
justifyContent: 'center', | ||
height: '100%', | ||
}, | ||
page: sharedStyles.page, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,56 @@ | ||
import {GestureResponderEvent, View} from 'react-native'; | ||
import {EButton, ETextField} from '~/shared'; | ||
import {useEffect, useState} from 'react'; | ||
import { | ||
GestureResponderEvent, | ||
StyleProp, | ||
StyleSheet, | ||
View, | ||
ViewStyle, | ||
} from 'react-native'; | ||
import {EButton, ESeparate, ETextField, useAlert} from '~/shared'; | ||
import {Checkbox} from 'react-native-paper'; | ||
import {useGoogleSignin} from '../hooks'; | ||
import _ from 'lodash'; | ||
|
||
type SignInProps = { | ||
style: StyleProp<ViewStyle>; | ||
}; | ||
export const SignIn = (props: SignInProps) => { | ||
const {googleSignIn, error, useInfo} = useGoogleSignin(); | ||
|
||
const {showAlert} = useAlert({ | ||
title: 'title 11', | ||
msg: useInfo?.user.name || '', | ||
onDismiss: () => console.log('onDismiss'), | ||
cancelBtn: {}, | ||
}); | ||
|
||
useEffect(() => { | ||
if (!_.isEmpty(useInfo?.user.name)) showAlert(); | ||
}, [useInfo?.user.name]); | ||
|
||
export const SignIn = () => { | ||
const handleOnSignIn = (event: GestureResponderEvent) => { | ||
console.log('SignIn'); | ||
}; | ||
|
||
return ( | ||
<View> | ||
<View {...props}> | ||
<ETextField label="Email:" placeholder="[email protected]" /> | ||
<ETextField | ||
label="Password:" | ||
placeholder="*********" | ||
isPassword | ||
/> | ||
<ETextField label="Password:" placeholder="*********" isPassword /> | ||
<EButton variant="contained" label="Sign In" onPress={handleOnSignIn} /> | ||
<ESeparate label="Or continue with" /> | ||
<EButton | ||
variant="outlined" | ||
// label="Google" | ||
onPress={(event: GestureResponderEvent) => googleSignIn()} | ||
viewStyle={styles.googleBtn} | ||
iconProps={{name: 'google', color: '#4285F4', size: 35}} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
googleBtn: { | ||
width: '50%', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import {useEffect, useState} from 'react'; | ||
import { | ||
GestureResponderEvent, | ||
StyleProp, | ||
StyleSheet, | ||
View, | ||
ViewStyle, | ||
} from 'react-native'; | ||
import {EButton, ESeparate, ETextField, useAlert} from '~/shared'; | ||
import {Checkbox} from 'react-native-paper'; | ||
import {useGoogleSignin} from '../hooks'; | ||
import _ from 'lodash'; | ||
|
||
type SignUpProps = { | ||
style: StyleProp<ViewStyle>; | ||
}; | ||
export const SignUp = (props: SignUpProps) => { | ||
const [checked, setChecked] = useState< | ||
'checked' | 'unchecked' | 'indeterminate' | ||
>('checked'); | ||
|
||
const {googleSignIn, error, useInfo} = useGoogleSignin(); | ||
|
||
const {showAlert} = useAlert({ | ||
title: 'title 11', | ||
msg: useInfo?.user.name || '', | ||
onDismiss: () => console.log('onDismiss'), | ||
cancelBtn: {}, | ||
}); | ||
useEffect(() => { | ||
if (!_.isEmpty(useInfo?.user.name)) showAlert(); | ||
}, [useInfo?.user.name]); | ||
|
||
const handleOnSignUp = (event: GestureResponderEvent) => { | ||
console.log('SignUp'); | ||
}; | ||
|
||
return ( | ||
<View {...props}> | ||
<ETextField label="Name:" placeholder="User name" /> | ||
<ETextField label="Email:" placeholder="[email protected]" /> | ||
<ETextField label="Password:" placeholder="*********" isPassword /> | ||
<Checkbox.Item | ||
label="Accept terms & conditions" | ||
status={checked} | ||
position="leading" | ||
labelVariant="headlineSmall" | ||
onPress={() => { | ||
if (checked === 'checked') { | ||
setChecked('unchecked'); | ||
} else setChecked('checked'); | ||
}} | ||
/> | ||
<EButton variant="contained" label="Sign Up" onPress={handleOnSignUp} /> | ||
<ESeparate label="Or continue with" /> | ||
<EButton | ||
variant="outlined" | ||
// label="Google" | ||
onPress={(event: GestureResponderEvent) => googleSignIn()} | ||
viewStyle={styles.googleBtn} | ||
iconProps={{name: 'google', color: '#4285F4', size: 35}} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
googleBtn: { | ||
width: '50%', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./Header"; | ||
export * from "./SignIn"; | ||
export * from "./SignIn"; | ||
export * from "./SignUp"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./useGoogleSignIn"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
GoogleSignin, | ||
User, | ||
statusCodes, | ||
} from '@react-native-google-signin/google-signin'; | ||
import { GOOGLE_CLIENT_ID2 } from "@env"; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export const useGoogleSignin = () => { | ||
const [error, setError] = useState<{ key: string, value: string }>({ key: "", value: "" }); | ||
const [useInfo, setUserInfo] = useState<User>(); | ||
|
||
useEffect(() => { | ||
GoogleSignin.configure({ | ||
scopes: ['https://www.googleapis.com/auth/drive.readonly'], // what API you want to access on behalf of the user, default is email and profile | ||
webClientId: GOOGLE_CLIENT_ID2, // client ID of type WEB for your server (needed to verify user ID and offline access) | ||
offlineAccess: true, // if you want to access Google API on behalf of the user FROM YOUR SERVER | ||
forceCodeForRefreshToken: true, // [Android] related to `serverAuthCode`, read the docs link below *. | ||
}); | ||
|
||
}, []); | ||
|
||
const googleSignIn = async () => { | ||
try { | ||
await GoogleSignin.hasPlayServices(); | ||
const user = await GoogleSignin.signIn(); | ||
console.log('userInfo=', user); | ||
setUserInfo(user) | ||
} catch (error: any) { | ||
if (error.code === statusCodes.SIGN_IN_CANCELLED) { | ||
setError({ key: statusCodes.SIGN_IN_CANCELLED, value: "user cancelled the login flow" }) | ||
} else if (error.code === statusCodes.IN_PROGRESS) { | ||
// | ||
setError({ key: statusCodes.IN_PROGRESS, value: "operation (e.g. sign in) is in progress already" }) | ||
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) { | ||
setError({ key: statusCodes.PLAY_SERVICES_NOT_AVAILABLE, value: "play services not available or outdated" }) | ||
} else { | ||
// some other error happened | ||
setError({ key: "other", value: "some other error happened" }) | ||
} | ||
} | ||
}; | ||
return { googleSignIn, error, useInfo } | ||
} |
Oops, something went wrong.