PageGrantAlert.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React from 'react';
  2. import { isPopulated } from '@growi/core';
  3. import { useTranslation } from 'react-i18next';
  4. import { useSWRxCurrentPage } from '~/stores/page';
  5. export const PageGrantAlert = (): JSX.Element => {
  6. const { t } = useTranslation();
  7. const { data: pageData } = useSWRxCurrentPage();
  8. if (pageData == null || pageData.grant == null || pageData.grant === 1) {
  9. return <></>;
  10. }
  11. const renderAlertContent = () => {
  12. const getGrantLabel = () => {
  13. if (pageData.grant === 2) {
  14. return (
  15. <>
  16. <i className="icon-fw icon-link"></i><strong>{t('Anyone with the link')}</strong>
  17. </>
  18. );
  19. }
  20. if (pageData.grant === 4) {
  21. return (
  22. <>
  23. <i className="icon-fw icon-lock"></i><strong>{t('Only me')}</strong>
  24. </>
  25. );
  26. }
  27. if (pageData.grant === 5) {
  28. return (
  29. <>
  30. <i className="icon-fw icon-organization"></i>
  31. <strong>{
  32. isPopulated(pageData.grantedGroups[0].item) && pageData.grantedGroups[0].item.name
  33. }
  34. </strong>
  35. </>
  36. );
  37. }
  38. };
  39. return (
  40. <>
  41. {getGrantLabel()} ({t('Browsing of this page is restricted')})
  42. </>
  43. );
  44. };
  45. return (
  46. <p className="alert alert-primary py-3 px-4">
  47. {renderAlertContent()}
  48. </p>
  49. );
  50. };