NotAvailableForReadOnlyUser.tsx 1.5 KB

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