Skip to content

Commit

Permalink
fix: type error in AuthScreen.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
ashifkhn authored and surajmaity1 committed Oct 19, 2024
1 parent 04bd7d1 commit b78928c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
6 changes: 6 additions & 0 deletions src/context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import { loggedInUserType } from './type';

type authContextProviderType = {
loggedInUserData: loggedInUserType | null;
goalsData: loggedInUserType | null;
isLoading: boolean;
setIsLoading: () => void;
setLoggedInUserData: (userData: loggedInUserType | null) => void;
setGoalsData: (userData: loggedInUserType | null) => void;
};
export const AuthContext = React.createContext<authContextProviderType>({
isLoading: false,
loggedInUserData: null,
goalsData: null,
setIsLoading: () => {
return;
},
setLoggedInUserData: () => {
return;
},
setGoalsData: () => {
return;
},
});

type authProviderProps = {
Expand Down
5 changes: 5 additions & 0 deletions src/context/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ export type loggedInUserType = {
name: string;
profileUrl: string;
status: string;
twitter_id?: string;
linkedin_id?: string;
github_id: string;
username: string;
token: string;
};

export interface User {
Expand Down
20 changes: 20 additions & 0 deletions src/react-native-walkthrough-tooltip.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
declare module 'react-native-walkthrough-tooltip' {
import React from 'react';
import { GestureResponderEvent, ViewStyle } from 'react-native';

export interface TooltipProps {
isVisible?: boolean;
content?: React.ReactElement;
placement?: 'top' | 'bottom' | 'left' | 'right' | 'center';
onClose?: (event: GestureResponderEvent) => void;
closeOnContentInteraction?: boolean;
closeOnBackgroundInteraction?: boolean;
backgroundStyle?: ViewStyle;
contentStyle?: ViewStyle;
tooltipStyle?: ViewStyle;
arrowStyle?: ViewStyle;
children?: React.ReactNode;
}

export default function Tooltip(props: TooltipProps): JSX.Element;
}
38 changes: 14 additions & 24 deletions src/screens/AuthScreen/AuthScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@ import { AuthContext } from '../../context/AuthContext';
import { getUserData, goalsAuth, requestCameraPermission } from './Util';
import { storeData } from '../../utils/dataStore';
import AuthApis from '../../constants/apiConstant/AuthApi';
// import { AuthApisStaging } from '../../constants/apiConstant/AuthApi';
import { CameraScreen } from 'react-native-camera-kit';
import { Camera } from 'react-native-camera-kit';
import CustomModal from '../../components/Modal/CustomModal';
import LoadingScreen from '../../components/LoadingScreen';
import Tooltip from 'react-native-walkthrough-tooltip';
import { useSelector } from 'react-redux';
// import Github from '../../constants/images/Image';
import Images from '../../constants/images/Image';
import GithubSvg from '../../../assets/svgs/github_logo.js';
import WebSvg from '../../../assets/svgs/web';

type RootState = {
localFeatureFlag: {
isProdEnvironment: boolean;
};
};
const baseUrl = AuthApis.GITHUB_AUTH_API;
const AuthScreen = () => {
const { isProdEnvironment } = useSelector((store) => store.localFeatureFlag);
const { isProdEnvironment } = useSelector(
(store: RootState) => store.localFeatureFlag,
);
const { setLoggedInUserData, setGoalsData } = useContext(AuthContext);
const [loading, setLoading] = useState(false);
const [cameraActive, setCameraActive] = useState(false);
Expand All @@ -45,7 +50,7 @@ const AuthScreen = () => {
redirectURL: 'https://realdevsquad.com/',
};

function buildUrl(url, params) {
function buildUrl(url: string, params: { [key: string]: string }) {
const queryString = Object.keys(params)
.map((key) => `${key}=${params[key]}`)
.join('&');
Expand All @@ -59,7 +64,7 @@ const AuthScreen = () => {
Platform.OS !== 'android' || requestCameraPermission();

Linking.getInitialURL();
const handleDeepLink = async (event) => {
const handleDeepLink = async (event: { url: string }) => {
const token = event.url.split('token=')[1];
token && updateUserData(token); // store token in redux
};
Expand Down Expand Up @@ -143,8 +148,6 @@ const AuthScreen = () => {
const qrCodeLogin = async () => {
const deviceId = await DeviceInfo.getUniqueId();

// const url = `${AuthApis.QR_AUTH_API}?device_id=${deviceId}`

const url = isProdEnvironment
? `${AuthApis.QR_AUTH_API}?device_id=${deviceId}`
: `${AuthApis.QR_AUTH_API_STAGING}?device_id=${deviceId}`;
Expand Down Expand Up @@ -220,7 +223,8 @@ const AuthScreen = () => {
console.log(err, 'Error QR login');
Toast.show({
type: 'error',
text1: err,
text1:
(err as Error).message || 'Something went wrong, please try again',
position: 'bottom',
bottomOffset: 80,
});
Expand Down Expand Up @@ -274,23 +278,9 @@ const AuthScreen = () => {
</Text>
</View>
</TouchableOpacity>

{/* <TouchableOpacity
onPress={() => {
isProdEnvironment
? dispatch({ type: 'DEV' })
: dispatch({ type: 'PROD' });
}}
>
<View style={AuthViewStyle.signInTxtView}>
<Text style={AuthViewStyle.signInText}>
{isProdEnvironment ? 'Switch to DEV' : 'Switch to Prod'}
</Text>
</View>
</TouchableOpacity> */}
</View>
{cameraActive && (
<CameraScreen
<Camera
style={StyleSheet.absoluteFill}
showFrame={true}
scanBarcode={true}
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
"typeRoots": [
"./node_modules/@types",
"./types"
], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
Expand Down

0 comments on commit b78928c

Please sign in to comment.