Sebas prompt for api key (#171)

* chore: prompt users when they dont have api key set up

* bump extension version
This commit is contained in:
Juan Sebastian velez Posada
2023-02-15 10:50:21 -05:00
committed by GitHub
parent e57bdbbfc4
commit ffd2a48b29
4 changed files with 24 additions and 5 deletions

View File

@@ -1,11 +1,17 @@
import React from 'react';
import React, { MouseEventHandler, CSSProperties } from 'react';
import classNames from 'classnames';
import { SuccessOrFailType } from '../config/config';
interface AlertProps {
onClick?: MouseEventHandler<HTMLDivElement>;
style?: CSSProperties;
text: string;
type: SuccessOrFailType;
}
export default function Alert({ type, text }: AlertProps): JSX.Element {
return <div className={classNames('alert', `alert-${type}`)}>{text}</div>;
export default function Alert({ onClick, style, type, text }: AlertProps): JSX.Element {
return (
<div className={classNames('alert', `alert-${type}`)} onClick={onClick} style={style}>
{text}
</div>
);
}

View File

@@ -2,6 +2,9 @@ import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { ApiKeyReducer, ReduxSelector } from '../types/store';
import { fetchUserData } from '../utils/user';
import apiKeyInvalid from '../utils/apiKey';
import config from '../config/config';
import Alert from './Alert';
import NavBar from './NavBar';
import MainList from './MainList';
@@ -18,9 +21,19 @@ export default function WakaTime(): JSX.Element {
void fetchUserData(apiKeyFromRedux, dispatch);
}, []);
const isApiKeyValid = apiKeyInvalid(apiKeyFromRedux) === '';
return (
<div>
<NavBar />
{!isApiKeyValid && (
<Alert
type={config.alert.failure.type}
text={'Please update your api key'}
onClick={() => browser.runtime.openOptionsPage()}
style={{ cursor: 'pointer' }}
/>
)}
<div className="container">
<div className="row">
<div className="col-md-12">

View File

@@ -26,5 +26,5 @@
"page": "options.html"
},
"permissions": ["alarms", "tabs", "storage", "idle"],
"version": "3.0.0"
"version": "3.0.1"
}

View File

@@ -39,5 +39,5 @@
"storage",
"idle"
],
"version": "3.0.0"
"version": "3.0.1"
}