|
| 1 | +import { useState } from 'react'; |
| 2 | +import { Modal } from './components/modal'; |
| 3 | +import { Button } from '../../../shared/components/Button/Button.component'; |
| 4 | + |
| 5 | +// 👨🏻💻 1A - have a look at the current implementation of the modal and then go to components/modal.tsx |
| 6 | + |
1 | 7 | export const Exercise = () => { |
2 | | - return null; |
| 8 | + const [isVisible, setIsVisible] = useState(false); |
| 9 | + const [isComplete, setIsComplete] = useState(false); |
| 10 | + |
| 11 | + const onClose = () => { |
| 12 | + setIsVisible(false); |
| 13 | + }; |
| 14 | + |
| 15 | + const onOpen = () => { |
| 16 | + setIsVisible(true); |
| 17 | + }; |
| 18 | + |
| 19 | + const onCheckout = () => { |
| 20 | + setIsComplete(true); |
| 21 | + }; |
| 22 | + |
| 23 | + return ( |
| 24 | + // 🧪 We have z-index 10 on the section and then z-9998 on a div that's purposely there. Our Modal has a z-20 which means: |
| 25 | + // section z-10 |
| 26 | + // modal z-20 (but this means z-20 within the z-10) think of it as a sub layer. |
| 27 | + // the bug is 9998 and a css hack for the pay now is 9999 |
| 28 | + <section className="z-10 relative h-screen"> |
| 29 | + <div className="z-[9998] absolute top-0 left-0 right-0 bottom-0" /> |
| 30 | + {isComplete && ( |
| 31 | + <> |
| 32 | + <h1 className="text-xl font-semibold"> |
| 33 | + Payment Successful |
| 34 | + </h1> |
| 35 | + <p className="text-md mb-2">Well done you did it!</p> |
| 36 | + </> |
| 37 | + )} |
| 38 | + |
| 39 | + {!isComplete && ( |
| 40 | + <> |
| 41 | + <h1 className="text-xl font-semibold">Payment Page</h1> |
| 42 | + |
| 43 | + <p className="text-md mb-2"> |
| 44 | + Please see your selected options from the previous steps |
| 45 | + before continuing. |
| 46 | + </p> |
| 47 | + |
| 48 | + <section className="my-6"> |
| 49 | + <h2 className="text-lg font-semibold mb-2"> |
| 50 | + Delivery Details |
| 51 | + </h2> |
| 52 | + <address className="border border-grey-300 rounded-md p-3 mb-2 block"> |
| 53 | + <p>12 john doe street, Manchester, M12 3RT</p> |
| 54 | + </address> |
| 55 | + </section> |
| 56 | + |
| 57 | + <section className="z-[9999] relative"> |
| 58 | + <h2 className="text-lg font-semibold mb-2"> |
| 59 | + Make Payment |
| 60 | + </h2> |
| 61 | + <Button onClick={onOpen}>Pay now</Button> |
| 62 | + </section> |
| 63 | + </> |
| 64 | + )} |
| 65 | + {isVisible && !isComplete && ( |
| 66 | + <Modal |
| 67 | + id="modal" |
| 68 | + onClose={onClose} |
| 69 | + isVisible={isVisible} |
| 70 | + title="Some fancy payment form..." |
| 71 | + > |
| 72 | + <Button onClick={onCheckout}>Pay now</Button> |
| 73 | + </Modal> |
| 74 | + )} |
| 75 | + </section> |
| 76 | + ); |
3 | 77 | }; |
0 commit comments