From 381b4882db0f247a88f91aeca02b30639e86a131 Mon Sep 17 00:00:00 2001 From: Ashif Khan <54736284+ashifkhn@users.noreply.github.com> Date: Mon, 2 Sep 2024 23:42:45 +0530 Subject: [PATCH] fix: type error in AuthScreen.tsx --- src/context/AuthContext.tsx | 6 ++++ src/context/type.ts | 5 +++ src/react-native-walkthrough-tooltip.d.ts | 20 ++++++++++++ src/screens/AuthScreen/AuthScreen.tsx | 40 +++++++++-------------- tsconfig.json | 5 ++- 5 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 src/react-native-walkthrough-tooltip.d.ts diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx index e9cdf092..0c17c777 100644 --- a/src/context/AuthContext.tsx +++ b/src/context/AuthContext.tsx @@ -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({ isLoading: false, loggedInUserData: null, + goalsData: null, setIsLoading: () => { return; }, setLoggedInUserData: () => { return; }, + setGoalsData: () => { + return; + }, }); type authProviderProps = { diff --git a/src/context/type.ts b/src/context/type.ts index 222f8e86..d6ec28c3 100644 --- a/src/context/type.ts +++ b/src/context/type.ts @@ -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 { diff --git a/src/react-native-walkthrough-tooltip.d.ts b/src/react-native-walkthrough-tooltip.d.ts new file mode 100644 index 00000000..3812f8eb --- /dev/null +++ b/src/react-native-walkthrough-tooltip.d.ts @@ -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; +} diff --git a/src/screens/AuthScreen/AuthScreen.tsx b/src/screens/AuthScreen/AuthScreen.tsx index 2528fd75..76c8138b 100644 --- a/src/screens/AuthScreen/AuthScreen.tsx +++ b/src/screens/AuthScreen/AuthScreen.tsx @@ -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); @@ -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('&'); @@ -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 }; @@ -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}`; @@ -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, }); @@ -274,30 +278,16 @@ const AuthScreen = () => { - - {/* { - isProdEnvironment - ? dispatch({ type: 'DEV' }) - : dispatch({ type: 'PROD' }); - }} - > - - - {isProdEnvironment ? 'Switch to DEV' : 'Switch to Prod'} - - - */} {cameraActive && ( - )} diff --git a/tsconfig.json b/tsconfig.json index 38cc138a..0f11f3cd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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'. */,