|
1 |
| -import React from 'react' |
| 1 | +import React, { useEffect, useRef, useState } from 'react' |
2 | 2 |
|
3 | 3 | import tick_svg from '../assets/SVG/tick.svg'
|
4 | 4 | import email_svg from '../assets/SVG/email.svg'
|
5 | 5 | import fingerprint_svg from '../assets/SVG/fingerprint.svg'
|
6 | 6 | import clock_svg from '../assets/SVG/clock.svg'
|
| 7 | +import { Link, useNavigate } from 'react-router-dom' |
| 8 | +import { ROUTE_URL } from '../others/Globals' |
7 | 9 |
|
8 | 10 | const ReceiptPage: React.FC = () => {
|
| 11 | + const [m_navigateFlag, setNavigateFlag] = useState<boolean>(false) |
| 12 | + const [m_timeLeft, setTimeLeft] = useState<number>(12) |
| 13 | + const m_timerHandle = useRef<NodeJS.Timeout>() |
| 14 | + const m_navTo = useNavigate() |
| 15 | + |
| 16 | + const tryDecrementTimer = () => { |
| 17 | + if (m_timerHandle && m_timerHandle.current) { |
| 18 | + clearTimeout(m_timerHandle.current) |
| 19 | + } |
| 20 | + setTimeLeft(timeLeft => { |
| 21 | + const timeNext = timeLeft - 1 |
| 22 | + if (timeNext <= 0) { |
| 23 | + setNavigateFlag(true) |
| 24 | + } |
| 25 | + m_timerHandle.current = setTimeout(() => tryDecrementTimer(), 1000) |
| 26 | + return timeNext |
| 27 | + }) |
| 28 | + } |
| 29 | + |
| 30 | + useEffect(() => { |
| 31 | + if (m_navigateFlag) { |
| 32 | + m_navTo(ROUTE_URL.HOME) |
| 33 | + } |
| 34 | + }, [m_navigateFlag]) |
| 35 | + |
| 36 | + useEffect(() => { |
| 37 | + if (m_timerHandle && m_timerHandle.current) { |
| 38 | + clearTimeout(m_timerHandle.current) |
| 39 | + } |
| 40 | + tryDecrementTimer() |
| 41 | + return () => clearTimeout(m_timerHandle.current) |
| 42 | + }, []) |
| 43 | + |
9 | 44 | return (
|
10 | 45 | <main className='h-screen w-screen bg-primary-800 flex justify-center items-center'>
|
11 | 46 |
|
@@ -45,10 +80,18 @@ const ReceiptPage: React.FC = () => {
|
45 | 80 | <p className='font-medium text-lg text-text-50'>Be sure to arrive on time to collect your pet</p>
|
46 | 81 | </div>
|
47 | 82 |
|
48 |
| - <div className='flex justify-start items-center mb-margin-s'> |
| 83 | + <div className='flex justify-start items-center mb-margin-2xl'> |
49 | 84 | <img className='w-10 h-10 mr-margin-s' src={fingerprint_svg} />
|
50 | 85 | <p className='font-medium text-lg text-text-50'>Be sure to bring your Pickup ID</p>
|
51 | 86 | </div>
|
| 87 | + |
| 88 | + <span> |
| 89 | + <i> |
| 90 | + You will be automatically re-directed to the |
| 91 | + <Link to={ROUTE_URL.HOME} className='underline'> home page </Link> |
| 92 | + in {m_timeLeft} seconds |
| 93 | + </i> |
| 94 | + </span> |
52 | 95 | </div>
|
53 | 96 | </div>
|
54 | 97 | </main>
|
|
0 commit comments