NotFoundAlert.tsx 2.1 KB

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