forked from QuickSwap/interface-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewsletterSignupPanel.tsx
More file actions
65 lines (61 loc) · 1.93 KB
/
Copy pathNewsletterSignupPanel.tsx
File metadata and controls
65 lines (61 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React, { useEffect, useRef, useState } from 'react';
import { Box, Button, CircularProgress } from '@material-ui/core';
import { useTranslation } from 'react-i18next';
import { Close } from '@material-ui/icons';
import { useOnClickOutside } from 'hooks/v3/useOnClickOutside';
import { useSubscribeNewsletter } from 'hooks/useNewsletterSignup';
const NewsletterSignupPanel: React.FC = () => {
const [showPanel, setShowPanel] = useState(false);
const [email, setEmail] = useState('');
const signupPanel = useRef<any>(null);
const hidePanel = () => {
setShowPanel(false);
};
useOnClickOutside(signupPanel, hidePanel);
const { t } = useTranslation();
useEffect(() => {
setTimeout(() => {
setShowPanel(true);
}, 3000);
}, []);
const { mutate, isLoading, data } = useSubscribeNewsletter();
const handleSignup = async () => {
await mutate(email);
};
return showPanel ? (
<div ref={signupPanel} className='staticNewsletterSignUpPanel'>
<p>{t('dragonDispatch')}</p>
<h4>{t('newsletterSignup')}</h4>
<small>{t('newsletterSignupDesc')}</small>
<input
placeholder={t('enterEmail')}
onChange={(e) => setEmail(e.target.value)}
/>
<Button disabled={isLoading} onClick={handleSignup}>
{isLoading && (
<CircularProgress
size='20px'
style={{ color: 'white', marginRight: 5 }}
/>
)}
{t('signup')}
</Button>
{data && (
<Box mt={1} textAlign='center'>
{data.data && (
<span className='text-success'>{t('subscribeSuccess')}</span>
)}
{data.error && (
<span className='text-error'>{t('subscribeError')}</span>
)}
</Box>
)}
<Box className='newsletterSignupClose cursor-pointer' onClick={hidePanel}>
<Close />
</Box>
</div>
) : (
<></>
);
};
export default React.memo(NewsletterSignupPanel);