Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

ts improvements

Blue Mouseae49eaf520eb
diff --git a/public/locales/en.json b/public/locales/en.json
index 36906bf57..ff2213ef4 100644
--- a/public/locales/en.json
+++ b/public/locales/en.json
@@ -26,7 +26,8 @@
"invalidToken": "Invalid token",
"transferRequestSent": "Transfer request sent",
"transferProjectReject": "The project transfer request has been cancelled",
- "socialisationGenericError": "Error occurred while linking Swetrix account with a 3rd party service"
+ "socialisationGenericError": "Error occurred while linking Swetrix account with a 3rd party service",
+ "socialisationAuthGenericError": "Error occurred while authenticating with a 3rd party service"
},
"common": {
"features": "Features",
diff --git a/src/components/GoogleAuth.tsx b/src/components/GoogleAuth.tsx
index 6c70bd69e..166c77764 100644
--- a/src/components/GoogleAuth.tsx
+++ b/src/components/GoogleAuth.tsx
@@ -6,8 +6,8 @@ import GoogleGSVG from 'ui/icons/GoogleG'
interface IGoogleAuth {
setIsLoading: (isLoading: boolean) => void,
- authSSO: any, // TODO add types
- callback?: any, // TODO add types
+ authSSO: (dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => void
+ callback?: any,
dontRemember?: boolean,
isMiniButton?: boolean,
}
@@ -19,11 +19,13 @@ const GoogleAuth: React.FC<IGoogleAuth> = ({
const googleLogin = async () => {
setIsLoading(true)
- authSSO(dontRemember, t, callback)
+ authSSO(
+ dontRemember as boolean,
+ t,
+ callback,
+ )
}
- console.log('isMiniButton', isMiniButton)
-
if (isMiniButton) {
<Button
className='border-indigo-100 dark:text-gray-50 dark:border-gray-700 dark:bg-gray-700 dark:hover:bg-gray-600'
diff --git a/src/pages/Auth/Signin/Signin.tsx b/src/pages/Auth/Signin/Signin.tsx
index 2b2fea694..f6af0178d 100644
--- a/src/pages/Auth/Signin/Signin.tsx
+++ b/src/pages/Auth/Signin/Signin.tsx
@@ -22,29 +22,33 @@ import { submit2FA } from 'api'
import { setAccessToken } from 'utils/accessToken'
import { setRefreshToken } from 'utils/refreshToken'
-// TODO: ADD & USE INTERFACE ISignin
-const Signin = ({
- login, loginSuccess, loginFailed, authSSO,
-}: {
+interface ISigninForm {
+ email: string,
+ password: string,
+ dontRemember: boolean,
+}
+
+interface ISignin {
login: (data: {
email: string,
password: string,
dontRemember: boolean
- }, callback: (result: boolean, twoFARequired: boolean) => void) => void,
+ },
+ callback: (result: boolean, twoFARequired: boolean) => void) => void,
loginSuccess: (user: IUser) => void,
loginFailed: (error: string) => void,
- authSSO: any, // TODO add types
-}): JSX.Element => {
+ authSSO: (dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => void
+}
+
+const Signin = ({
+ login, loginSuccess, loginFailed, authSSO,
+}: ISignin): JSX.Element => {
const { t }: {
t: (key: string, optinions?: {
[key: string]: string | number,
}) => string,
} = useTranslation('common')
- const [form, setForm] = useState<{
- email: string,
- password: string,
- dontRemember: boolean,
- }>({
+ const [form, setForm] = useState<ISigninForm>({
email: '',
password: '',
dontRemember: false,
@@ -97,11 +101,7 @@ const Signin = ({
}
}
- const onSubmit = (data: {
- email: string,
- password: string,
- dontRemember: boolean
- }) => {
+ const onSubmit = (data: ISigninForm) => {
if (!isLoading) {
setIsLoading(true)
login(data, loginCallback)
diff --git a/src/pages/Auth/Signup/Signup.tsx b/src/pages/Auth/Signup/Signup.tsx
index 20a914f40..8e42d8c0d 100644
--- a/src/pages/Auth/Signup/Signup.tsx
+++ b/src/pages/Auth/Signup/Signup.tsx
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
import { useTranslation, Trans } from 'react-i18next'
import _size from 'lodash/size'
import _keys from 'lodash/keys'
+import _omit from 'lodash/omit'
import _isEmpty from 'lodash/isEmpty'
import Title from 'components/Title'
@@ -19,33 +20,37 @@ import {
} from 'utils/validator'
import { HAVE_I_BEEN_PWNED_URL, TRIAL_DAYS } from 'redux/constants'
import { trackCustom } from 'utils/analytics'
-import _omit from 'lodash/omit'
-const Signup = ({ signup, authSSO }: {
+interface ISignupForm {
+ email: string,
+ password: string,
+ repeat: string,
+ tos: boolean,
+ dontRemember: boolean,
+ checkIfLeaked: boolean,
+}
+
+interface ISignup {
signup: (data: {
email: string,
password: string,
repeat: string,
dontRemember: boolean,
checkIfLeaked: boolean,
- }, t: (key: string, optinions?: {
- [key: string]: string | number,
- }) => string, callback: (res: any) => void) => void,
- authSSO: any, // TODO add types
-}): JSX.Element => {
+ },
+ t: (key: string, options?: {
+ [key: string]: string | number,
+ }) => string, callback: (res: any) => void) => void,
+ authSSO: (dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => void
+}
+
+const Signup = ({ signup, authSSO }: ISignup): JSX.Element => {
const { t }: {
- t: (key: string, optinions?: {
+ t: (key: string, options?: {
[key: string]: string | number,
}) => string,
} = useTranslation('common')
- const [form, setForm] = useState<{
- email: string,
- password: string,
- repeat: string,
- tos: boolean,
- dontRemember: boolean,
- checkIfLeaked: boolean,
- }>({
+ const [form, setForm] = useState<ISignupForm>({
email: '',
password: '',
repeat: '',
@@ -109,14 +114,7 @@ const Signup = ({ signup, authSSO }: {
}
}
- const onSubmit = (data: {
- email: string,
- password: string,
- repeat: string,
- tos: boolean,
- dontRemember: boolean,
- checkIfLeaked: boolean,
- }) => {
+ const onSubmit = (data: ISignupForm) => {
if (!isLoading) {
setIsLoading(true)
signup(_omit(data, 'tos'), t, signUpCallback)
diff --git a/src/redux/sagas/auth/workers/signin.ts b/src/redux/sagas/auth/workers/signin.ts
index 54670185f..c348560fb 100644
--- a/src/redux/sagas/auth/workers/signin.ts
+++ b/src/redux/sagas/auth/workers/signin.ts
@@ -47,7 +47,9 @@ export default function* singinWorker({ payload: { credentials, callback } }: {
} catch (error) {
// @ts-ignore
const err = _isObject(error) ? error.message : error
- yield put(errorsActions.loginFailed(err || 'apiNotifications.somethingWentWrong'))
+ yield put(errorsActions.loginFailed({
+ message: err || 'apiNotifications.somethingWentWrong',
+ }))
callback(false, false)
} finally {
yield put(authActions.finishLoading())
diff --git a/src/redux/sagas/auth/workers/sso_auth.ts b/src/redux/sagas/auth/workers/sso_auth.ts
index caee8ce53..6d03fcd84 100644
--- a/src/redux/sagas/auth/workers/sso_auth.ts
+++ b/src/redux/sagas/auth/workers/sso_auth.ts
@@ -15,24 +15,28 @@ const AUTH_WINDOW_HEIGHT = 800
const HASH_CHECK_FREQUENCY = 1000 // 1 second
-// TODO: Add types
-export default function* ssoAuth({ payload: { callback, dontRemember } }: any) {
- console.log('ssoAuth worker')
+interface ISSOAuth {
+ payload: {
+ callback: (isSuccess: boolean, is2FA: boolean) => void
+ dontRemember: boolean
+ t: (key: string) => string
+ }
+}
+
+export default function* ssoAuth({ payload: { callback, dontRemember, t } }: ISSOAuth) {
const authWindow = openBrowserWindow('', AUTH_WINDOW_WIDTH, AUTH_WINDOW_HEIGHT)
if (!authWindow) {
- // TODO: Check the issue later
- // @ts-ignore
- yield put(errorsActions.loginFailed('SOMETHING WENT WRONG (THIS MESSAGE SHOULD BE SENT VIA I18N)'))
- // callback(false, false)
+ yield put(errorsActions.loginFailed({
+ message: t('apiNotifications.socialisationAuthGenericError'),
+ }))
+ callback(false, false)
return
}
try {
const { uuid, auth_url: authUrl } = yield call(generateGoogleAuthURL)
- console.log(uuid, authUrl)
-
// Set the URL of the authentification browser window
authWindow.location = authUrl
@@ -74,11 +78,14 @@ export default function* ssoAuth({ payload: { callback, dontRemember } }: any) {
// Authentication is not finished yet
}
if (authWindow.closed) {
- // callback(false, false)
+ callback(false, false)
return
}
}
} catch (reason) {
- // TODO: Display notification. Something went wrong while generating auth URL
+ yield put(errorsActions.loginFailed({
+ message: t('apiNotifications.socialisationAuthGenericError'),
+ }))
+ callback(false, false)
}
}