diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-07-08 15:00:29 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-07-08 15:00:29 +0700 |
| commit | aedf523be9b0faf9cdd7a2231912a074fccdb262 (patch) | |
| tree | d0bdcae03e98cc62c5a4fd84fc42bdf0ececc3ea /src-migrate/modules | |
| parent | 367bf6f382392774680abcf4a5ca4b4d03915650 (diff) | |
<iman> update salin voucher
Diffstat (limited to 'src-migrate/modules')
| -rw-r--r-- | src-migrate/modules/promo/components/Voucher.tsx | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/src-migrate/modules/promo/components/Voucher.tsx b/src-migrate/modules/promo/components/Voucher.tsx index 397134e8..c978dc7b 100644 --- a/src-migrate/modules/promo/components/Voucher.tsx +++ b/src-migrate/modules/promo/components/Voucher.tsx @@ -7,7 +7,6 @@ import Image from 'next/image' import { useToast } from '@chakra-ui/react' import useDevice from '@/core/hooks/useDevice'; - const Voucher = () => { const { isMobile } = useDevice(); const toast = useToast(); @@ -26,18 +25,50 @@ const Voucher = () => { slidesPerView: isMobile ? 1.2 : 3, spaceBetween: 16 } + const vouchers = useMemo(() => voucherQuery.data || [], [voucherQuery.data]); const copyText = (text: string) => { - navigator.clipboard.writeText(text) - toast({ - title: 'Salin ke papan klip', - description: 'Kode voucher berhasil disalin', - status: 'success', - duration: 3000, - isClosable: true, - position: 'bottom', - }) + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(text) + .then(() => { + toast({ + title: 'Salin ke papan klip', + description: 'Kode voucher berhasil disalin', + status: 'success', + duration: 3000, + isClosable: true, + position: 'bottom', + }) + }) + .catch(() => { + fallbackCopyTextToClipboard(text); + }); + } else { + fallbackCopyTextToClipboard(text); + } + } + + const fallbackCopyTextToClipboard = (text: string) => { + const textArea = document.createElement("textarea"); + textArea.value = text; + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + try { + document.execCommand('copy'); + toast({ + title: 'Salin ke papan klip', + description: 'Kode voucher berhasil disalin', + status: 'success', + duration: 3000, + isClosable: true, + position: 'bottom', + }) + } catch (err) { + console.error('Fallback: Oops, unable to copy', err); + } + document.body.removeChild(textArea); } return ( @@ -78,9 +109,8 @@ const Voucher = () => { </Swiper> </div> )} - </> ) } -export default Voucher
\ No newline at end of file +export default Voucher |
