-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve in context errors (#3344)
- Loading branch information
Showing
31 changed files
with
3,864 additions
and
3,671 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
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,97 @@ | ||
import { Alert, AlertTitle } from '@mui/material'; | ||
import { HttpError } from '../client/HttpError'; | ||
import { useDialogContext } from './dialogContext'; | ||
import { NewTabLink } from './Link'; | ||
|
||
type Props = { | ||
error: HttpError | Error; | ||
severity?: 'error' | 'info'; | ||
}; | ||
|
||
export const ErrorAlert = ({ error, severity = 'error' }: Props) => { | ||
const apiUrl = useDialogContext((c) => c.uiProps.apiUrl); | ||
|
||
return ( | ||
<Alert sx={{ mt: 2 }} severity={severity}> | ||
{error instanceof HttpError | ||
? getErrorContent(error, apiUrl) | ||
: error.message} | ||
</Alert> | ||
); | ||
}; | ||
|
||
function DocsInContext() { | ||
return ( | ||
<NewTabLink href="https://tolgee.io/js-sdk/in-context"> | ||
Learn more in Docs | ||
</NewTabLink> | ||
); | ||
} | ||
|
||
function DocsAPIKeys() { | ||
return ( | ||
<NewTabLink href="https://tolgee.io/platform/account_settings/api_keys_and_pat_tokens"> | ||
Learn more in Docs | ||
</NewTabLink> | ||
); | ||
} | ||
|
||
function getErrorContent({ code, params, message }: HttpError, apiUrl: string) { | ||
switch (code) { | ||
case 'operation_not_permitted': | ||
return ( | ||
<> | ||
<AlertTitle>Operation not permitted</AlertTitle> | ||
{Boolean(params?.length) && 'Missing scopes: ' + params?.join(', ')} | ||
</> | ||
); | ||
|
||
case 'invalid_project_api_key': | ||
return ( | ||
<> | ||
<AlertTitle>Invalid API key</AlertTitle> | ||
Check it in the code or in the chrome plugin. <DocsInContext /> | ||
</> | ||
); | ||
|
||
case 'api_url_not_specified': | ||
return ( | ||
<> | ||
<AlertTitle>Oops... I miss the API url</AlertTitle> | ||
Add it in the code or via the chrome plugin. <DocsInContext /> | ||
</> | ||
); | ||
|
||
case 'api_url_not_valid': | ||
return ( | ||
<> | ||
<AlertTitle>API url is not correct ({apiUrl})</AlertTitle> | ||
Check it in the code or in the chrome plugin. <DocsInContext /> | ||
</> | ||
); | ||
|
||
case 'api_key_not_specified': | ||
return ( | ||
<> | ||
<AlertTitle>Oops... I miss the API key</AlertTitle> | ||
Add it in the code or via the chrome plugin. <DocsInContext /> | ||
</> | ||
); | ||
|
||
case 'permissions_not_sufficient_to_edit': | ||
return ( | ||
<> | ||
<AlertTitle> | ||
Sorry, you don't have permissions to make changes | ||
</AlertTitle> | ||
Update your API key or ask admin for more permissions <DocsAPIKeys /> | ||
</> | ||
); | ||
|
||
case 'fetch_error': | ||
return `Failed to fetch (${apiUrl})`; | ||
|
||
default: | ||
return message; | ||
} | ||
} |
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,26 @@ | ||
import { OpenInNew } from '@mui/icons-material'; | ||
import { styled } from '@mui/material'; | ||
|
||
type Props = { | ||
href: string; | ||
children: React.ReactNode; | ||
}; | ||
|
||
const StyledLink = styled('a')``; | ||
|
||
const StyledIcon = styled(OpenInNew)` | ||
width: 17px; | ||
height: 17px; | ||
position: relative; | ||
top: 3px; | ||
margin-left: 1px; | ||
`; | ||
|
||
export const NewTabLink = ({ href, children }: Props) => { | ||
return ( | ||
<StyledLink href={href} target="_blank" rel="noreferrer noopener"> | ||
{children} | ||
<StyledIcon /> | ||
</StyledLink> | ||
); | ||
}; |
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
Oops, something went wrong.