invite.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Text } from 'app/design/typography'
  2. import { View, Row } from 'app/design/view'
  3. import { NeoButton, Input, Modal } from 'app/design/controls';
  4. import { fetcher } from 'app/lib/fetcher';
  5. import { useState } from 'react';
  6. import { setClipboard } from 'app/lib/util'
  7. import { APP_URL } from 'app/config';
  8. import { BlockWrapper } from 'app/components/block-wrapper'
  9. import { useTranslation } from 'react-i18next'
  10. export default function ElementInvite({ data, blockWrapperProps }) {
  11. const { t } = useTranslation();
  12. const [showModal, setShowModal] = useState(false);
  13. const handleClick = async () => {
  14. const sResponse = await fetcher('/api.php?r=' + data.request_url);
  15. setShowModal(sResponse.data.link)
  16. }
  17. const handleCopy = async () => {
  18. setClipboard(APP_URL + showModal);
  19. }
  20. return (
  21. <BlockWrapper {...blockWrapperProps}>
  22. <Modal id={'file-preview'} title={t('Invitation link')} onVisible={!!showModal} onClose={() => { setShowModal(null) }}>
  23. <Row className='gap-x-4'>
  24. <Input value={APP_URL + showModal} />
  25. <NeoButton style="borderless" borderShape="circle" image="Clipboard" accessibilityLabel={t('Copy link')} onPress={() => handleCopy()} />
  26. </Row>
  27. </Modal>
  28. <View className="p-4">
  29. <Text className="text-card-foreground text-center">{t('You can invite your friends to join. You have {{count}} invites to share.', { count: data.remain })}</Text>
  30. <View className='mx-auto pt-4'>
  31. <NeoButton borderShape="capsule" label={"Get invite link"} onPress={() => handleClick()} />
  32. </View>
  33. </View>
  34. </BlockWrapper>
  35. );
  36. }