NotAvailableForGuest.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import { Disable } from 'react-disable';
  4. import { UncontrolledTooltip } from 'reactstrap';
  5. import { useIsGuestUser } from '~/stores/context';
  6. type NotAvailableForGuestProps = {
  7. children: JSX.Element
  8. }
  9. export const NotAvailableForGuest = ({ children }: NotAvailableForGuestProps): JSX.Element => {
  10. const { t } = useTranslation();
  11. const { data: isGuestUser } = useIsGuestUser();
  12. const isDisabled = !!isGuestUser;
  13. const id = children.props.id || `grw-not-available-for-guest-${Math.random().toString(32).substring(2)}`;
  14. // clone and add className
  15. const clonedChild = React.cloneElement(children, {
  16. id,
  17. className: `${children.props.className} grw-not-available-for-guest`,
  18. });
  19. return (
  20. <>
  21. <div id={id}>
  22. <Disable disabled={isDisabled}>
  23. { clonedChild }
  24. </Disable>
  25. </div>
  26. <UncontrolledTooltip placement="top" target={id}>{t('Not available for guest')}</UncontrolledTooltip>
  27. </>
  28. );
  29. };