PageGrantAlert.tsx 1.2 KB

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