Advertisement
cindex1a

checkout.js

Feb 22nd, 2021
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from "react";
  2. import Header from "parts/Header";
  3. import Fade from "react-reveal/Fade";
  4. import Button from "elements/Button";
  5. import Stepper, {
  6.   Numbering,
  7.   Meta,
  8.   MainContent,
  9.   Controller,
  10. } from "elements/Stepper";
  11.  
  12. import BookingInformation from "parts/Checkout/BookingInformation.js";
  13. import Payment from "parts/Checkout/Payment.js";
  14. import Completed from "parts/Checkout/Completed.js";
  15.  
  16. import ItemDetails from "json/itemDetails.json";
  17. import { isThisSecond } from "date-fns";
  18.  
  19. export default class Checkout extends Component {
  20.   state = {
  21.     data: {
  22.       firstName: "",
  23.       lastName: "",
  24.       email: "",
  25.       phone: "",
  26.       proofPayment: "",
  27.       bankName: "",
  28.       bangHolder: "",
  29.     },
  30.   };
  31.  
  32.   onChange = (event) => {
  33.     this.setState({
  34.       data: {
  35.         ...this.state.data,
  36.         [event.target.name]: event.target.value,
  37.       },
  38.     });
  39.   };
  40.  
  41.   componentDidMount() {
  42.     window.scroll(0, 0);
  43.   }
  44.   render() {
  45.     const { data } = this.state;
  46.     const checkout = {
  47.       duration: 3,
  48.     };
  49.  
  50.     const steps = {
  51.       bookingInformation: {
  52.         title: "Booking Information",
  53.         description: "Please fill up the blank fields below ",
  54.         content: (
  55.           <BookingInformation
  56.             data={data}
  57.             checkout={checkout}
  58.             ItemDetails={ItemDetails}
  59.             onChange={this.onChange}
  60.           />
  61.         ),
  62.       },
  63.       payment: {
  64.         title: "payment",
  65.         description: "Kindly follow the instruction below",
  66.         content: (
  67.           <Payment
  68.             data={data}
  69.             ItemDetails={ItemDetails}
  70.             checkout={checkout}
  71.             onChange={this.onChange}
  72.           />
  73.         ),
  74.       },
  75.       completed: {
  76.         title: "Yeay! Completed",
  77.         description: null,
  78.         content: <Completed />,
  79.       },
  80.     };
  81.     return (
  82.       <>
  83.         <Header isCentered />
  84.         <Stepper steps={steps}>
  85.           {(prevStep, nextStep, CurrentStep, steps) => (
  86.             <>
  87.               <Numbering
  88.                 data={steps}
  89.                 current={CurrentStep}
  90.                 style={{ marginBottom: 50 }}
  91.               />
  92.  
  93.               <Meta data={steps} current={CurrentStep} />
  94.               <MainContent data={steps} current={CurrentStep} />
  95.               {CurrentStep === "bookingInformation" && (
  96.                 <Controller>
  97.                   {data.firstName !== "" &&
  98.                     data.lastName !== "" &&
  99.                     data.email !== "" &&
  100.                     data.phone !== "" && (
  101.                       <Fade>
  102.                         <Button
  103.                           className="btn mb-3"
  104.                           type="button"
  105.                           isBlock
  106.                           isPrimary
  107.                           hasShadow
  108.                           onClick={nextStep}
  109.                         >
  110.                           Continue To Book{" "}
  111.                         </Button>
  112.                       </Fade>
  113.                     )}
  114.                   <Button
  115.                     className="btn"
  116.                     type="link"
  117.                     isBlock
  118.                     isLight
  119.                     href={`/properties/${ItemDetails._id}`}
  120.                   >
  121.                     cancel
  122.                   </Button>
  123.                 </Controller>
  124.               )}
  125.               {CurrentStep === "payment" && (
  126.                 <Controller>
  127.                   {data.proofPayment !== "" &&
  128.                     data.bankName !== "" &&
  129.                     data.bankHolder !== "" && (
  130.                       <Fade>
  131.                         <Button
  132.                           className="btn mb-3"
  133.                           type="button"
  134.                           isBlock
  135.                           isPrimary
  136.                           hasShadow
  137.                           onClick={nextStep}
  138.                         >
  139.                           Continue To Book
  140.                         </Button>
  141.                       </Fade>
  142.                     )}
  143.                   <Button
  144.                     className="btn"
  145.                     type="button"
  146.                     isBlock
  147.                     isLight
  148.                     onClick={prevStep}
  149.                   >
  150.                     Cancel
  151.                   </Button>
  152.                 </Controller>
  153.               )}
  154.  
  155.               {CurrentStep === "completed" && (
  156.                 <Controller>
  157.                   <Button
  158.                     className="btn"
  159.                     type="link"
  160.                     isBlock
  161.                     isPrimary
  162.                     hasShadow
  163.                     href=""
  164.                   ></Button>
  165.                 </Controller>
  166.               )}
  167.             </>
  168.           )}
  169.         </Stepper>
  170.       </>
  171.     );
  172.   }
  173. }
  174.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement