import React from 'react'; import { useTranslation } from 'next-i18next'; import PropTypes from 'prop-types'; const ApiErrorMessage = (props) => { const { t } = useTranslation(); const { errorCode, errorMessage, targetPath, } = props; function reload() { window.location.reload(); } function renderMessageByErrorCode() { switch (errorCode) { case 'already_exists': return ( <> cancel{ t('page_api_error.already_exists') } {targetPath} login ); case 'notfound_or_forbidden': return ( cancel{ t('page_api_error.notfound_or_forbidden') } ); case 'user_not_admin': return ( cancel{ t('page_api_error.user_not_admin') } ); case 'complete_deletion_not_allowed_for_user': return ( cancel{ t('page_api_error.complete_deletion_not_allowed_for_user') } ); case 'outdated': return ( <> lightbulb { t('page_api_error.outdated') } { t('Load latest') } ); case 'invalid_path': return ( cancel Invalid path ); case 'single_deletion_empty_pages': return ( cancel{ t('page_api_error.single_deletion_empty_pages') } ); default: return ( cancel Unknown error occured ); } } if (errorCode != null) { return ( {renderMessageByErrorCode()} ); } if (errorMessage != null) { return ( {errorMessage} ); } // render null if no error has occurred return null; }; ApiErrorMessage.propTypes = { errorCode: PropTypes.string, errorMessage: PropTypes.string, targetPath: PropTypes.string, }; export default ApiErrorMessage;