NotAvailableForGuest.tsx 892 B

1234567891011121314151617181920212223242526272829303132333435
  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. if (!isGuestUser) {
  14. return children;
  15. }
  16. const id = `grw-not-available-for-guest-${Math.random().toString(32).substring(2)}`;
  17. return (
  18. <>
  19. <div id={id}>
  20. <Disable disabled={isDisabled}>
  21. { children }
  22. </Disable>
  23. </div>
  24. <UncontrolledTooltip placement="top" target={id}>{t('Not available for guest')}</UncontrolledTooltip>
  25. </>
  26. );
  27. };