import { AlertTitle, Box } from '@mui/material';
import { HttpError } from '../../client/HttpError';
import { DocsInContext } from './DocsInContext';
import { OpenExtension } from './OpenExtension';
import { DocsAPIKeys } from './DocsAPIKeys';
import { CredentialHint } from './CredentialHint';
type CredentialContext = {
credentialBlocksSubmit: boolean | undefined;
accountHolds: (scopes: string[]) => boolean | undefined;
viaExtension: boolean;
};
export function getErrorContent(
{ code, params, message }: HttpError,
apiUrl: string,
credential: CredentialContext
) {
switch (code) {
case 'operation_not_permitted': {
const missing = params ?? [];
return (
<>
Operation not permitted
{missing.length > 0 && (
<>
{'Missing scopes: ' + missing.join(', ')}
{credential.accountHolds(missing) && (
)}
>
)}
>
);
}
case 'invalid_project_api_key':
return (
<>
Invalid API key
Check it in the code or in the chrome plugin.
>
);
case 'unauthenticated':
case 'invalid_jwt_token':
case 'expired_jwt_token':
case 'general_jwt_error':
case 'invalid_oauth_token':
case 'oauth_token_expired':
case 'extension_session_missing':
return (
<>
You're not signed in
Sign in again in the Tolgee plugin to keep editing.
>
);
case 'extension_request_too_large':
return (
<>
Image is too large to upload
This image is too large for the Tolgee plugin to send. Pick a smaller
one.
>
);
case 'api_url_not_specified':
return (
<>
Oops... I miss the API url
Add it in the code or via the chrome plugin.
>
);
case 'api_url_not_valid':
return (
<>
API url is not correct ({apiUrl})
Check it in the code or in the chrome plugin.
>
);
case 'suggestion_needs_existing_key':
return (
<>
This string has no key in Tolgee yet
Suggestions need an existing key. Ask someone who can create keys to
add it first.
>
);
case 'api_key_not_specified':
return (
<>
Sign in to make changes
To edit strings here, sign in with the Tolgee browser extension or add
an API key to the Tolgee configuration.
>
);
case 'extension_editing_off':
return (
<>
In-context editing is switched off
You switched editing off for this page in the Tolgee plugin. Turn it
on to edit here.
>
);
case 'project_id_not_specified':
return (
<>
Oops... I miss the project id
An OAuth token or PAT carries no project, so projectId must be set in
the Tolgee configuration.
>
);
case 'project_not_found':
return (
<>
Project not found
The configured project doesn't exist on this server, or your account
can't access it. Check the projectId in the Tolgee configuration, or
ask for access.
>
);
case 'permissions_not_sufficient_to_edit': {
const limit = credential.credentialBlocksSubmit;
return (
<>
Sorry, you don't have permissions to make changes
{limit === true ? (
) : limit === false ? (
'Ask a project admin for more permissions.'
) : (
<>
Update your API key or ask admin for more permissions{' '}
>
)}
>
);
}
case 'operation_not_permitted_in_read_only_mode':
return (
<>
Read-only mode
This branch is protected or your access is read-only.
>
);
case 'duplicate_suggestion':
return <>This suggestion already exists.>;
case 'suggestions_disabled':
return (
<>
Suggestions are disabled
This project doesn't accept suggestions any more. Reopen the dialog to
see what you can still do.
>
);
case 'branch_not_found':
return (
<>
Branch not found
Check the branch name or switch to an existing branch.
>
);
case 'fetch_error':
return `Failed to fetch (${apiUrl})`;
default:
return message;
}
}