GiftCard.js 14.3 KB
import Image from "next/image";
import React, { useEffect, useState } from "react";
import { Formik, Form, Field, ErrorMessage } from "formik";
import * as Yup from "yup";

const validationSchema = Yup.object().shape({
  customAmt: Yup.string().required("Full name is required"),
  code: Yup.string().required("Please Enter 4-Digit Code"),
  email: Yup.string().email("Invalid email").required("Email is required"),
  receiverEmail: Yup.string().email("Invalid email").required("Email is required"),
  message: Yup.string().required("Message is required")
});

let formik1;

const GiftCard = () => {
  const [isStep1, setIsStep1] = useState(true);
  const [amount, setAmount] = useState(0);

  const [isStep2, setIsStep2] = useState(false);
  const [isResult, setIsResult] = useState(false);
  const [showTooltip1, setShowTooltip1] = useState(false); // State for first tooltip
  const [showTooltip2, setShowTooltip2] = useState(false); // State for second tooltip
  const tooltipText1 = "Enter your Email Id. We'll send you a 4-digit code to verify";
  const tooltipText2 = "Enter your Receiver’s Email Id whom you wish to send gift card.";
  const handleclose = () => {
    setIsResult(false);
    setIsStep1(true);
  };

  return (
    <section className="gift-card-session">
      <div className="container">
        <div className="row justify-content-center">
          <div className="col-md-10">
            {!isResult && (
              <div className="row">
                <div className="col-md-5">
                  <div className="gift-card-lt">
                    <div className="gift-box">
                      <img src="/images/zango-logo.svg" alt="Gift Card" />
                    </div>
                    <h3>Amount: ${amount}</h3>
                  </div>
                </div>
                <div className="col-md-7">
                  {isStep1 && (
                    <div className="gift-card-rt">
                      <div className="back-btn">
                        <a href="">
                          <span className="image-container">
                            <Image layout="fill" alt="" className="image img-fluid" src="/images/icons/arrow-left-02.svg" />
                          </span>
                        </a>
                      </div>
                      <Formik
                        initialValues={{
                          customAmt: "",
                          email: "",
                          receiverEmail: "",
                          message: ""
                        }}
                        enableReinitialize={true}
                        // validationSchema={validationSchema}
                        onSubmit={(values, { setSubmitting }) => {
                          // Handle form submission here
                          console.log(values);
                          setSubmitting(false);
                          setIsStep2(true);
                          setIsStep1(false);
                        }}
                      >
                        {({ isSubmitting, values, handleChange, handleBlur, touched, errors }) => (
                          <Form action="" className="form-01">
                            <div className="title">Buy a gift card</div>
                            <div className="cl-gry">Please select an amount</div>
                            <div className="gift-card-amt">
                              <ul>
                                <li>
                                  <input name="amt" id="amt-250" type="radio" value="" data-gtm-Form-interact-field-id="1" onChange={e => setAmount(250)} />
                                  <label for="amt-250">$250</label>
                                </li>
                                <li>
                                  <input name="amt" id="amt-500" type="radio" value="" data-gtm-form-interact-field-id="1" onChange={e => setAmount(500)} />
                                  <label for="amt-500">$500</label>
                                </li>
                                <li>
                                  <input name="amt" id="amt-750" type="radio" value="" data-gtm-form-interact-field-id="1" onChange={e => setAmount(750)} />
                                  <label for="amt-750">
                                    <span>Most Popular</span>
                                    <br /> $750
                                  </label>
                                </li>
                                <li>
                                  <input name="amt" id="amt-1000" type="radio" value="" data-gtm-form-interact-field-id="1" onChange={e => setAmount(1000)} />
                                  <label for="amt-1000"> $1000</label>
                                </li>
                                <li>
                                  <input name="amt" id="amt-1500" type="radio" value="" data-gtm-form-interact-field-id="1" onChange={e => setAmount(1500)}  />
                                  <label for="amt-1500"> $1500</label>
                                </li>
                                <li>
                                  <input name="amt" id="amt-custom" type="radio" value="" data-gtm-form-interact-field-id="1" onChange={e => setAmount(null)}  />
                                  <label for="amt-custom"> $ Custom</label>
                                </li>
                              </ul>
                            </div>
                            <div className="row">
                            {amount == null && (
                              <div className="col-md-12 mb-4">
                                <label htmlFor="">Custom Amount</label>
                                <Field
                                  className="form-control"
                                  type="text"
                                  name="customAmt"
                                  placeholder="Enter your amount"
                                  onChange={handleChange}
                                  onBlur={handleBlur}
                                  value={values.customAmt}
                                />
                                {touched.customAmt && errors.customAmt && <div className="text-danger">{errors.customAmt}</div>}
                              </div>
                            )
                            }
                             
                              <div className="col-md-12 mb-4">
                                <label htmlFor="">Email Id</label>
                                <Field
                                  className="form-control"
                                  type="email"
                                  name="email"
                                  placeholder="yourname@example.com"
                                  onChange={handleChange}
                                  onBlur={handleBlur}
                                  value={values.email}
                                />
                                {touched.email && errors.email && <div className="text-danger">{errors.email}</div>}
                                <div className="tooltip-wrapper">
                                  <a className="tooltip-btn" onMouseEnter={() => setShowTooltip1(true)} onMouseLeave={() => setShowTooltip1(false)}>
                                    <span className="image-container">
                                      <Image layout="fill" alt="" className="image img-fluid" src="/images/icons/info.svg" />
                                    </span>
                                  </a>

                                  {/* Tooltip */}
                                  {showTooltip1 && <div className="tooltips">{tooltipText1}</div>}
                                </div>
                              </div>

                              <div className="col-md-12 mb-4">
                                <label htmlFor="">Receivers Email Id</label>
                                <Field
                                  className="form-control"
                                  type="receiverEmail"
                                  name="receiverEmail"
                                  placeholder="yourname@example.com"
                                  onChange={handleChange}
                                  onBlur={handleBlur}
                                  value={values.receiverEmail}
                                />
                                {touched.receiverEmail && errors.receiverEmail && <div className="text-danger">{errors.receiverEmail}</div>}
                                <div className="tooltip-wrapper">
                                  <a className="tooltip-btn" onMouseEnter={() => setShowTooltip2(true)} onMouseLeave={() => setShowTooltip2(false)}>
                                    <span className="image-container">
                                      <Image layout="fill" alt="" className="image img-fluid" src="/images/icons/info.svg" />
                                    </span>
                                  </a>

                                  {/* Tooltip */}
                                  {showTooltip2 && <div className="tooltips">{tooltipText2}</div>}
                                </div>
                              </div>

                              <div className="col-md-12 mb-4">
                                <Field
                                  className="form-control"
                                  as="textarea"
                                  rows={7}
                                  name="message"
                                  placeholder="Type your message..."
                                  onChange={handleChange}
                                  onBlur={handleBlur}
                                  value={values.message}
                                />
                                {touched.message && errors.message && <div className="text-danger">{errors.message}</div>}
                              </div>
                              <div className="col-md-12 mb-3">
                                <button className="btn btn-primary w-100" type="submit" disabled={isSubmitting}>
                                  Continue
                                </button>
                              </div>
                              <div className="col-12">
                                <p>
                                  By continuing you agree to our <a href="">Terms</a> and <a href="">Privacy Policy</a>
                                </p>
                              </div>
                            </div>
                          </Form>
                        )}
                      </Formik>
                    </div>
                  )}

                  {isStep2 && (
                    <div className="gift-card-rt">
                      <div className="back-btn">
                        <a href="">
                          <span className="image-container">
                            <Image layout="fill" alt="" className="image img-fluid" src="/images/icons/arrow-left-02.svg" />
                          </span>
                        </a>
                      </div>
                      <Formik
                        initialValues={{
                          code: ""
                        }}
                        // validationSchema={validationSchema}
                        onSubmit={(values, { setSubmitting }) => {
                          // Handle form submission here
                          console.log(values);
                          setSubmitting(false);
                          setIsStep2(false);
                          setIsStep1(false);
                          setIsResult(true);
                        }}
                      >
                        {({ isSubmitting, values, handleChange, handleBlur, touched, errors }) => (
                          <Form action="" className="form-01">
                            <div className="title">We emailed you a 4-digit code</div>
                            <div className="cl-gry">Please enter it below to create or login into your account:</div>

                            <div className="row mt-4">
                              <div className="col-md-12 mb-4">
                                <label htmlFor="">Enter 4-Digit Code</label>
                                <Field
                                  className="form-control"
                                  type="text"
                                  name="code"
                                  placeholder="Enter the code we emailed you"
                                  onChange={handleChange}
                                  onBlur={handleBlur}
                                  value={values.code}
                                />
                                {touched.code && errors.code && <div className="text-danger">{errors.code}</div>}
                                <div className="link-a">
                                  <a href="">Resend Code</a>
                                </div>
                              </div>
                            </div>
                            <div className="row">
                              <div className="col-md-12 mb-3">
                                <button className="btn btn-primary w-100" type="submit" disabled={isSubmitting}>
                                  Confirm
                                </button>
                              </div>
                            </div>
                          </Form>
                        )}
                      </Formik>
                    </div>
                  )}
                </div>
              </div>
            )}

            {isResult && (
              <div className="row">
                <div className="col-12">
                  <div className="result-box">
                    <p>
                      Sorry, unable to process the Gift Card now.
                      <br /> This feature will be available shortly.
                    </p>
                    <div>
                      <button className="btn btn-primary" type="button" onClick={handleclose}>
                        Browse Experiences
                      </button>
                    </div>
                  </div>
                </div>
              </div>
            )}
          </div>
        </div>
      </div>
    </section>
  );
};

export default GiftCard;