-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDailyLimitModal.tsx
125 lines (118 loc) · 4.58 KB
/
DailyLimitModal.tsx
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import clsx from 'clsx';
import { api } from '@/hooks';
import { Localize } from '@deriv-com/translations';
import { Button, Loader, Modal, Text, useDevice } from '@deriv-com/ui';
import './DailyLimitModal.scss';
type TDailyLimitModalProps = {
currency: string;
isModalOpen: boolean;
onRequestClose: () => void;
};
const DailyLimitModal = ({ currency, isModalOpen, onRequestClose }: TDailyLimitModalProps) => {
const { data, error, isPending: isLoading, isSuccess, mutate } = api.advertiser.useUpdate();
const { mutate: updateNotification } = api.notification.useUpdate();
const { daily_buy_limit: dailyBuyLimit, daily_sell_limit: dailySellLimit } = data ?? {};
const { isDesktop } = useDevice();
const textSize = isDesktop ? 'sm' : 'md';
const headerTextSize = isDesktop ? 'md' : 'lg';
const modalContent = {
default: {
body: (
<Localize i18n_default_text='You won’t be able to change your buy and sell limits again after this. Do you want to continue?' />
),
footer: (
<>
<Button
className='border-2'
color='black'
onClick={onRequestClose}
size='lg'
textSize={textSize}
variant='outlined'
>
<Localize i18n_default_text='No' />
</Button>
<Button
onClick={() => {
mutate({ upgrade_limits: 1 });
//TODO: Remove this once implemented in BE
updateNotification({ ids: [], notifications_update_status: 'remove' });
}}
size='lg'
textSize={textSize}
>
<Localize i18n_default_text='Yes, continue' />
</Button>
</>
),
header: <Localize i18n_default_text='Are you sure?' />,
},
error: {
body: (
<Localize i18n_default_text='Sorry, we’re unable to increase your limits right now. Please try again in a few minutes.' />
),
footer: (
<Button onClick={onRequestClose} size='lg' textSize={textSize}>
<Localize i18n_default_text='Ok' />
</Button>
),
header: <Localize i18n_default_text='An internal error occurred' />,
},
loading: {
body: <Loader isFullScreen={false} />,
footer: null,
header: null,
},
success: {
body: (
<Localize
i18n_default_text='Your daily limits have been increased to {{dailyBuyLimit}} {{currency}} (buy) and {{dailySellLimit}} {{currency}} (sell).'
values={{ currency, dailyBuyLimit, dailySellLimit }}
/>
),
footer: (
<Button onClick={onRequestClose} size='lg' textSize={textSize}>
<Localize i18n_default_text='Ok' />
</Button>
),
header: <Localize i18n_default_text='Success!' />,
},
};
const getModalContent = () => {
if (isLoading) {
return modalContent.loading;
} else if (isSuccess) {
return modalContent.success;
} else if (error) {
return modalContent.error;
}
return modalContent.default;
};
return (
<Modal
ariaHideApp={false}
className='daily-limit-modal'
isOpen={isModalOpen}
onRequestClose={onRequestClose}
shouldCloseOnOverlayClick={false}
testId='dt_daily_limit_modal'
>
{!isLoading && (
<Modal.Header hideBorder hideCloseIcon>
<Text color='prominent' size={headerTextSize} weight='bold'>
{getModalContent().header}
</Text>
</Modal.Header>
)}
<Modal.Body className={clsx('py-[0.8rem] px-[2.4rem]', { 'mx-auto py-[2.4rem]': isLoading })}>
<Text size={textSize}>{getModalContent().body}</Text>
</Modal.Body>
{!isLoading && (
<Modal.Footer className='gap-[0.8rem] px-[1.6rem]' hideBorder>
{getModalContent().footer}
</Modal.Footer>
)}
</Modal>
);
};
export default DailyLimitModal;