NotAvailableForReadOnlyUser.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import type React from 'react';
  2. import type { JSX } from 'react';
  3. import { useAtomValue } from 'jotai';
  4. import { useTranslation } from 'next-i18next';
  5. import { useIsReadOnlyUser } from '~/states/context';
  6. import { isRomUserAllowedToCommentAtom } from '~/states/server-configurations';
  7. import { NotAvailable } from './NotAvailable';
  8. // eslint-disable-next-line react/prop-types
  9. export const NotAvailableForReadOnlyUser: React.FC<{
  10. children: JSX.Element;
  11. }> = ({ children }) => {
  12. const { t } = useTranslation();
  13. const isReadOnlyUser = useIsReadOnlyUser();
  14. const isDisabled = !!isReadOnlyUser;
  15. const title = t('Not available for read only user');
  16. return (
  17. <NotAvailable
  18. isDisabled={isDisabled}
  19. title={title}
  20. classNamePrefix="grw-not-available-for-read-only-user"
  21. >
  22. {children}
  23. </NotAvailable>
  24. );
  25. };
  26. NotAvailableForReadOnlyUser.displayName = 'NotAvailableForReadOnlyUser';
  27. // eslint-disable-next-line react/prop-types
  28. export const NotAvailableIfReadOnlyUserNotAllowedToComment: React.FC<{
  29. children: JSX.Element;
  30. }> = ({ children }) => {
  31. const { t } = useTranslation();
  32. const isReadOnlyUser = useIsReadOnlyUser();
  33. const isRomUserAllowedToComment = useAtomValue(isRomUserAllowedToCommentAtom);
  34. const isDisabled = !!isReadOnlyUser && !isRomUserAllowedToComment;
  35. const title = t('page_comment.comment_management_is_not_allowed');
  36. return (
  37. <NotAvailable
  38. isDisabled={isDisabled}
  39. title={title}
  40. classNamePrefix="grw-not-available-for-read-only-user"
  41. >
  42. {children}
  43. </NotAvailable>
  44. );
  45. };
  46. NotAvailableIfReadOnlyUserNotAllowedToComment.displayName =
  47. 'NotAvailableIfReadOnlyUserNotAllowedToComment';