-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ux): enhance error messages guidance
- Loading branch information
Showing
8 changed files
with
63 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
import type { RootState } from 'store'; | ||
import { createSelector } from '@reduxjs/toolkit'; | ||
import { selectSettings } from './settings'; | ||
|
||
export const selectApp = (state: RootState) => state.app; | ||
|
||
export const selectIsSetupRequired = createSelector( | ||
selectApp, | ||
selectSettings, | ||
(app, settings) => app.loaded && !settings.apiKey, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { MouseEvent } from 'react'; | ||
import { Alert, AlertProps } from '../Alert'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { Link } from '@mui/material'; | ||
|
||
enum Error { | ||
MISSING_API_KEY = 'The request is missing a valid API key.', | ||
INVALID_API_KEY = 'API key not valid. Please pass a valid API key.', | ||
} | ||
|
||
interface ErrorAlertProps extends AlertProps {} | ||
|
||
export function ErrorAlert(props: ErrorAlertProps) { | ||
const { error, ...rest } = props; | ||
const history = useHistory(); | ||
|
||
const handleGoToSettings = (event: MouseEvent) => { | ||
event.preventDefault(); | ||
history.push('/settings'); | ||
}; | ||
|
||
const renderError = () => { | ||
const errorMessage = error?.data?.error.message || error?.error; | ||
switch (errorMessage) { | ||
case Error.MISSING_API_KEY: | ||
case Error.INVALID_API_KEY: | ||
return ( | ||
<> | ||
{errorMessage}{' '} | ||
<Link | ||
href="#" | ||
color="secondary" | ||
rel="noopener" | ||
onClick={handleGoToSettings} | ||
> | ||
Go to settings. | ||
</Link> | ||
</> | ||
); | ||
default: | ||
return errorMessage; | ||
} | ||
}; | ||
|
||
return <Alert {...rest}>{renderError()}</Alert>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters