Skip to content

Commit

Permalink
refactored the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
shreya-mishra committed Sep 27, 2023
1 parent 9250371 commit a4bc258
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 62 deletions.
1 change: 1 addition & 0 deletions src/constants/apiConstant/AuthApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const AuthApis = {
USER_DETAIL: 'https://api.realdevsquad.com/users/userId/',
QR_AUTH_API: 'https://api.realdevsquad.com/auth/qr-code-auth',
GITHUB_AUTH_API: 'https://api.realdevsquad.com/auth/github/login',
};
Expand Down
71 changes: 9 additions & 62 deletions src/screens/AuthScreen/AuthScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import AuthApis from '../../constants/apiConstant/AuthApi';
import { CameraScreen } from 'react-native-camera-kit';
import CustomModal from '../../components/Modal/CustomModal';
import Tooltip from 'react-native-walkthrough-tooltip';
import LoadingScreen from '../../components/LoadingScreen';

const baseUrl = AuthApis.GITHUB_AUTH_API;

Expand All @@ -30,8 +31,6 @@ const AuthScreen = () => {
const [cameraActive, setCameraActive] = useState(false);
const [scannedUserId, setScannedUserID] = useState('');
const [modalVisible, setModalVisible] = useState(false);
const [addressbarURL, setAdressbarURL] = useState<String>('');
const [key, setKey] = useState(1);
const [toolTip, setToolTip] = useState(false);

const queryParams = {
Expand Down Expand Up @@ -81,6 +80,7 @@ const AuthScreen = () => {

const updateUserData = async (token: string) => {
try {
setLoading(true);
const res = await getUserData(token);
await storeData('userData', JSON.stringify(res));
setLoggedInUserData({
Expand All @@ -89,6 +89,7 @@ const AuthScreen = () => {
profileUrl: res?.profileUrl,
status: res?.status,
});
setLoading(false);
} catch (err) {
setLoggedInUserData(null);
}
Expand All @@ -103,7 +104,7 @@ const AuthScreen = () => {
const userInfoJson = await userInfo.json();
if (userInfoJson.data.token) {
const userDetailsInfo = await fetch(
`https://api.realdevsquad.com/users/userId/${scannedUserId}`,
`${AuthApis.USER_DETAIL}${scannedUserId}`,
);
const userDetailsInfoJson = await userDetailsInfo.json();
await storeData('userData', JSON.stringify(userDetailsInfoJson.user));
Expand Down Expand Up @@ -189,64 +190,6 @@ const AuthScreen = () => {
/* eslint-disable */
}, [scannedUserId]);


if (githubView) {
return (
<SafeAreaView style={{ flex: 1 }}>
<ScrollView contentContainerStyle={AuthViewStyle.container}>
<View style={AuthViewStyle.addressBarStyle}>
{loading ? (
<ActivityIndicator
style={{ marginLeft: 5 }}
size={25}
color="#fff"
/>
) : (
<TouchableOpacity onPress={() => setGithubView(false)}>
<Text style={AuthViewStyle.addressBarCancel}>Cancel</Text>
</TouchableOpacity>
)}
<Text style={AuthViewStyle.addressBarLink}>{addressbarURL}</Text>
{loading ? null : (
<TouchableOpacity onPress={() => setKey(key + 1)}>
<Image
source={Images.refreshIcon}
style={AuthViewStyle.addressBarIcon}
/>
</TouchableOpacity>
)}
</View>
<WebView
key={key}
onNavigationStateChange={({ url }) => {
if (url === urls.REDIRECT_URL) {
setAdressbarURL(url);
updateUserData(url);
} else if (url.indexOf('?') > 0) {
let uri = url.substring(0, url.indexOf('?'));
setAdressbarURL(uri);
updateUserData(uri);
} else {
setAdressbarURL(url);
updateUserData(url);
}
}}
style={AuthViewStyle.webViewStyles}
source={{
uri: urls.GITHUB_AUTH,
}}
onLoadStart={() => {
setLoading(true);
}}
onLoadEnd={() => {
setLoading(false);
}}
/>
</ScrollView>
</SafeAreaView>
);
}
t //TODO: fix layout change on otp input
return (
<ScrollView contentContainerStyle={AuthViewStyle.container}>
<View style={[AuthViewStyle.imageContainer]}>
Expand Down Expand Up @@ -320,6 +263,8 @@ t //TODO: fix layout change on otp input
qrCodeLogin={qrCodeLogin}
/>
)}

{loading && <LoadingScreen />}
</ScrollView>
);
};
Expand All @@ -331,14 +276,16 @@ const styles = StyleSheet.create({
fontWeight: 'bold',
},
toolButton: {
fontSize: 20,
fontSize: 16,
backgroundColor: '#483d8b',
color: '#fff',
marginBottom: 15,
borderRadius: 20,
height: 50,
padding: 10,
textAlignVertical: 'center',
textAlign: 'center',
margin: 8,
},
});
export default AuthScreen;

0 comments on commit a4bc258

Please sign in to comment.