Skip to content

Commit a59e750

Browse files
Added timeout functionality for the receipt page
1 parent cab874f commit a59e750

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

src/pages/CheckoutPage.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ interface CheckoutInputFieldProps {
88

99
const CheckoutInput: React.FC<CheckoutInputFieldProps> = props => {
1010
return (
11-
<>
12-
<label className='flex flex-col items-start'>
13-
<span className='mb-text-xxs'>{props.labelText}</span>
14-
<input
15-
type={props.inputType} placeholder={props.placeholderText || ""}
16-
className='
11+
<label className='flex flex-col items-start'>
12+
<span className='mb-text-xxs'>{props.labelText}</span>
13+
<input
14+
type={props.inputType} placeholder={props.placeholderText || ""}
15+
className='
1716
w-full h-10 px-4 focus:outline-none
1817
border-gray-300 border-[1px] rounded-lg bg-transparent
1918
' />
20-
</label>
21-
</>
19+
</label>
2220
)
2321
}
2422

@@ -49,7 +47,7 @@ const CheckoutPage: React.FC = () => {
4947
</div>
5048

5149
{/* ---- CONTACT INFORMATION ---- */}
52-
<div className='bg-white rounded-lg shadow-xl p-8 flex flex-col gap-6 mb-margin-l w-full'>
50+
<div className='bg-white rounded-lg shadow-xl p-8 flex flex-col gap-6 mb-margin-xl w-full'>
5351
<h2 className='text-2xl font-semibold'>Contact Info</h2>
5452
<CheckoutInput labelText='Email' inputType='text' />
5553
<CheckoutInput labelText='Contact No' inputType='text' />

src/pages/ReceiptPage.tsx

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
1-
import React from 'react'
1+
import React, { useEffect, useRef, useState } from 'react'
22

33
import tick_svg from '../assets/SVG/tick.svg'
44
import email_svg from '../assets/SVG/email.svg'
55
import fingerprint_svg from '../assets/SVG/fingerprint.svg'
66
import clock_svg from '../assets/SVG/clock.svg'
7+
import { Link, useNavigate } from 'react-router-dom'
8+
import { ROUTE_URL } from '../others/Globals'
79

810
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+
944
return (
1045
<main className='h-screen w-screen bg-primary-800 flex justify-center items-center'>
1146

@@ -45,10 +80,18 @@ const ReceiptPage: React.FC = () => {
4580
<p className='font-medium text-lg text-text-50'>Be sure to arrive on time to collect your pet</p>
4681
</div>
4782

48-
<div className='flex justify-start items-center mb-margin-s'>
83+
<div className='flex justify-start items-center mb-margin-2xl'>
4984
<img className='w-10 h-10 mr-margin-s' src={fingerprint_svg} />
5085
<p className='font-medium text-lg text-text-50'>Be sure to bring your Pickup ID</p>
5186
</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>
5295
</div>
5396
</div>
5497
</main>

0 commit comments

Comments
 (0)