NotFoundAlert.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { UncontrolledTooltip } from 'reactstrap';
  4. import { EditorMode, useEditorMode } from '~/stores/ui';
  5. type Props = {
  6. isGuestUserMode?: boolean,
  7. }
  8. const NotFoundAlert = (props: Props): JSX.Element => {
  9. const { t } = useTranslation();
  10. const { isGuestUserMode } = props;
  11. const { data: editorMode, mutate: mutateEditorMode } = useEditorMode();
  12. const isEditorMode = editorMode !== EditorMode.View;
  13. const clickHandler = useCallback(() => {
  14. // check guest user,
  15. // disabled of button cannot be used for using tooltip.
  16. if (isGuestUserMode) {
  17. return;
  18. }
  19. mutateEditorMode(EditorMode.Editor);
  20. }, [isGuestUserMode, mutateEditorMode]);
  21. if (isEditorMode) {
  22. return <></>;
  23. }
  24. return (
  25. <div className="border border-info p-3">
  26. <div
  27. className="col-md-12 p-0"
  28. >
  29. <h2 className="text-info lead">
  30. <i className="icon-info pr-2 font-weight-bold" aria-hidden="true"></i>
  31. {t('not_found_page.page_not_exist_alert')}
  32. </h2>
  33. <div id="create-page-btn-wrapper-for-tooltip" className="d-inline-block">
  34. <button
  35. type="button"
  36. className={`pl-3 pr-3 btn bg-info text-white ${isGuestUserMode ? 'disabled' : ''}`}
  37. onClick={clickHandler}
  38. >
  39. <i className="icon-note icon-fw" />
  40. {t('not_found_page.Create Page')}
  41. </button>
  42. </div>
  43. {isGuestUserMode && (
  44. <UncontrolledTooltip placement="bottom" target="create-page-btn-wrapper-for-tooltip" fade={false}>
  45. {t('Not available for guest')}
  46. </UncontrolledTooltip>
  47. )}
  48. </div>
  49. </div>
  50. );
  51. };
  52. export default NotFoundAlert;