Blame view

components/vendor/BusinessDetails.js 21.9 KB
1
import { Formik } from "formik";
jay committed
2
import { Fragment, useEffect, useRef, useState } from "react";
3 4
import { Button, Form } from "react-bootstrap";
import * as Yup from "yup";
Jyotsna committed
5 6
import { FaArrowRight, FaTimes } from "react-icons/fa";
import Image from "next/image";
jay committed
7 8
import { getSession } from "next-auth/react";
import "react-bootstrap-typeahead/css/Typeahead.css";
jaymehta committed
9 10
import { useDispatch, useSelector } from "react-redux";
import { getLoggedInVendor, updateVendorBusinessDetails } from "../../redux/actions/vendorActions";
jaymehta committed
11 12
import { loadUser, updateUserApprovalStatus } from "../../redux/actions/userActions";
import { useRouter } from "next/router";
13 14

const BusinessDetails = () => {
jay committed
15
  const [session, setSession] = useState(null);
jaymehta committed
16
  const dispatch = useDispatch();
.  
jaymehta committed
17
  const router = useRouter();
jaymehta committed
18 19
  const { loggedInVendor } = useSelector(state => state.loggedInVendor);
  const { vendorDetails } = useSelector(state => state.vendorDetails);
jaymehta committed
20
  const { loadedUser, error } = useSelector(state => state.loadedUser);
jay committed
21 22
  //   const [pincodeData, setPinCodeData] = useState()
  //   const ref = useRef(null);
jaymehta committed
23
  console.log("vendorDetails", vendorDetails);
jaymehta committed
24 25
  const [disableFields, setdisableFields] = useState();
  useEffect(() => {
jaymehta committed
26 27 28
    console.log("user", loadedUser);
    if (loadedUser) {
      if (loadedUser.approved == "approved" || loadedUser.approved == "rejected") {
jaymehta committed
29
        setdisableFields(false);
jaymehta committed
30
      } else if (loadedUser.approved == "pending") {
jaymehta committed
31 32 33
        setdisableFields(true);
      }
    }
jaymehta committed
34
  }, [loadedUser]);
jaymehta committed
35
  // console.log("userStatus", userStatus);
jay committed
36 37 38 39 40
  useEffect(() => {
    const fetchSession = async () => {
      setSession(await getSession());
    };
    fetchSession();
jaymehta committed
41
    // dispatch(getLoggedInVendor());
jay committed
42
  }, []);
jaymehta committed
43
  // console.log("session", loggedInVendor);
jay committed
44 45
  const businessDetailsValidationSchema = Yup.object().shape({
    panNumber: Yup.string().required("Pan Number is Required"),
jaymehta committed
46
    panFile: Yup.mixed(),
jay committed
47
    gstNumber: Yup.string().required("GST Number is Required"),
jaymehta committed
48
    gstCertificateFile: Yup.mixed(),
jay committed
49
    businessName: Yup.string().required("Business Name is Required"),
jaymehta committed
50
    brandLogoFile: Yup.mixed(),
jay committed
51 52 53 54 55 56 57 58 59 60 61 62 63
    pincode: Yup.string().required("Pincode is Required"),
    country: Yup.string().required("Country is Required"),
    state: Yup.string().required("State is Required"),
    city: Yup.string().required("City is Required"),
    addressLine1: Yup.string().required("Address Line 1 is Required"),
    addressLine2: Yup.string().required("Address Line 2 is Required")
  });

  //   const handleSearch = async pin => {
  //     let pincodeDataSet = await pincodeSearchByFilter(pin);
  //     console.log("pincodeData", pincodeDataSet.data.data);
  //     setPinCodeData(pincodeDataSet.data.data)
  //   };
jaymehta committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

  let vendorData;

  if (vendorDetails) {
    vendorData = {
      panNumber: vendorDetails.attributes.pan,
      panFile: vendorDetails.attributes.panImage,
      gstNumber: vendorDetails.attributes.gst,
      gstCertificateFile: vendorDetails.attributes.gstImage,
      businessName: vendorDetails.attributes.businessName,
      brandLogoFile: vendorDetails.attributes.logo,
      pincode: vendorDetails.attributes.pincode,
      country: vendorDetails.attributes.country,
      state: vendorDetails.attributes.state,
      city: vendorDetails.attributes.city,
      addressLine1: vendorDetails.attributes.addressLine1,
      addressLine2: vendorDetails.attributes.addressLine2
    };
  }
jaymehta committed
83 84

  const ApprovalStatus = () => {
jaymehta committed
85 86
    if (loadedUser) {
      switch (loadedUser.approved) {
jaymehta committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
        case "approved":
          return <></>;

        case "rejected":
          return (
            <>
              <div class="alert alert-danger" role="alert">
                Your profile has been rejected! Please contact the admin for more details!
              </div>
            </>
          );

        case "pending":
          return (
            <>
              <div class="alert alert-primary" role="alert">
                Your profile is under consideration, please wait till admin gives approval
              </div>
            </>
          );

        case "none":
          return <></>;

        default:
          break;
      }
    }
  };
jaymehta committed
116
  // vendorDetails && console.log("vendorData", vendorData, vendorDetails.length > 0);
jay committed
117 118
  return (
    <Fragment>
jaymehta committed
119
      {loadedUser && (
jaymehta committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        <div className="container p-5">
          <div className="row">
            <div className="col-12 col-lg-8">
              <div className="content-div business-details">
                <h2>Tell us about your business</h2>
                <p>Please have the following ready before you begin</p>
                <p>
                  <FaArrowRight /> Your bank account details for receiving payments from ZanGO
                </p>
                <p className="mb-4">
                  <FaArrowRight /> Tax (GST/PAN) details of your business.
                </p>
                <hr />
                <div className="form-container mt-4">
                  <ApprovalStatus />
                  <Formik
                    enableReinitialize
                    initialValues={{
                      panNumber: vendorData?.panNumber ? vendorData?.panNumber : "",
                      panFile: vendorData?.panImage ? vendorData?.panImage : "",
                      gstNumber: vendorData?.gstNumber ? vendorData?.gstNumber : "",
                      gstCertificateFile: vendorData?.gstImage ? vendorData?.gstImage : "",
                      businessName: vendorData?.businessName ? vendorData?.businessName : "",
                      brandLogoFile: vendorData?.logo ? vendorData?.logo : "",
                      pincode: vendorData?.pincode ? vendorData?.pincode : "",
                      country: vendorData?.country ? vendorData?.country : "",
                      state: vendorData?.state ? vendorData?.state : "",
                      city: vendorData?.city ? vendorData?.city : "",
                      addressLine1: vendorData?.addressLine1 ? vendorData?.addressLine1 : "",
                      addressLine2: vendorData?.addressLine2 ? vendorData?.addressLine2 : ""
                    }}
                    validationSchema={businessDetailsValidationSchema}
                    // enableReinitialize={true}
                    onSubmit={async values => {
                      console.log("business details values", values);
                      const businessDetails = {
                        pan: values.panNumber,
                        gst: values.gstNumber,
                        businessName: values.businessName,
                        state: values.state,
                        city: values.city,
                        pincode: values.pincode,
                        country: values.country,
                        addressLine1: values.addressLine1,
                        addressLine2: values.addressLine2
                      };
                      // await dispatch(updateVendorBusinessDetails({businessDetails, }))
jay committed
167

jaymehta committed
168
                      const response = await dispatch(getLoggedInVendor());
jaymehta committed
169

jaymehta committed
170
                      console.log("loggedInVendorReducer", response);
jaymehta committed
171

jaymehta committed
172 173 174
                      const updateBusinessDetails = await dispatch(updateVendorBusinessDetails({ businessDetails, vendorId: response.id }));
                      await updateUserApprovalStatus({ status: "pending" });
                      await dispatch(loadUser());
.  
jaymehta committed
175
                      router.push("/vendor/dashboard");
jaymehta committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
                      // console.log("updateBusinessDetails", updateBusinessDetails);
                    }}
                  >
                    {({ values, errors, touched, handleChange, handleBlur, handleSubmit, setFieldValue }) => (
                      <Form
                        onSubmit={e => {
                          e.preventDefault();
                          handleSubmit();
                        }}
                      >
                        <h4>Vendor Business Information</h4>
                        <div className="mt-3">
                          <p className="textH">Business documents</p>
                          <div className="row">
                            <div className="col-12 col-lg-5">
                              <div className="input-group">
                                <label>Enter Business PAN No.</label>
                                <input type="text" name="panNumber" onChange={handleChange} onBlur={handleBlur} value={values.panNumber} disabled={disableFields} />
                                {errors.panNumber && touched.panNumber && <span className="form-error">{errors.panNumber}</span>}
jay committed
195
                              </div>
jaymehta committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
                            </div>
                            <div className="col-12 offset-lg-1 col-lg-5">
                              <div className="input-group">
                                <label>Upload PAN</label>
                                <div className="custom-file">
                                  <input
                                    disabled={disableFields}
                                    type="file"
                                    className="custom-file-input"
                                    id="panFile"
                                    name="panFile"
                                    onChange={event => {
                                      if (event) {
                                        const file = event.currentTarget.files[0];
                                        setFieldValue("panFile", file);
                                      }
                                    }}
                                    onBlur={handleBlur}
                                    // value={values.panFile}
                                    onClick={event => {
                                      const { target = {} } = event || {};
                                      target.value = "";
218
                                    }}
jay committed
219
                                  />
jaymehta committed
220 221 222
                                  <label className="custom-file-label" htmlFor="panFile">
                                    Upload
                                  </label>
jay committed
223
                                </div>
jaymehta committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237
                                <p className="textS">Upload in .PNG or .JPG/JPEG format</p>
                                {errors.panFile && touched.panFile && <span className="form-error">{errors.panFile}</span>}
                                {values.panFile && (
                                  <div className="d-flex align-items-center justify-content-between p-1" style={{ width: "100%" }}>
                                    <p className="textS m-0">{values.panFile.name}</p>
                                    <FaTimes
                                      style={{ cursor: "pointer" }}
                                      onClick={() => {
                                        setFieldValue("panFile", "");
                                      }}
                                    />
                                  </div>
                                )}
                              </div>
jay committed
238 239
                            </div>
                          </div>
jaymehta committed
240 241 242 243 244 245 246
                          <div className="row">
                            <div className="col-12 col-lg-5">
                              <div className="input-group">
                                <label>GST Number</label>
                                <input disabled={disableFields} type="text" name="gstNumber" onChange={handleChange} onBlur={handleBlur} value={values.gstNumber} />
                                {errors.gstNumber && touched.gstNumber && <span className="form-error">{errors.gstNumber}</span>}
                              </div>
jay committed
247
                            </div>
jaymehta committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
                            <div className="col-12 offset-lg-1 col-lg-5">
                              <div className="input-group">
                                <label>GST Certificate</label>
                                <div className="custom-file">
                                  <input
                                    disabled={disableFields}
                                    type="file"
                                    className="custom-file-input"
                                    id="gstCertificateFile"
                                    name="gstCertificateFile"
                                    onChange={handleChange}
                                    onBlur={handleBlur}
                                    value={values.gstCertificateFile}
                                  />
                                  <label className="custom-file-label" htmlFor="gstCertificateFile">
                                    Upload
                                  </label>
                                </div>
                                <p className="textS">Upload in .PNG or .JPG/JPEG format</p>
                                {errors.gstCertificateFile && touched.gstCertificateFile && <span className="form-error">{errors.gstCertificateFile}</span>}
jay committed
268 269 270
                              </div>
                            </div>
                          </div>
jaymehta committed
271 272 273 274 275 276 277
                          <div className="row">
                            <div className="col-12 col-lg-5">
                              <div className="input-group">
                                <label>Business Name</label>
                                <input disabled={disableFields} type="text" name="businessName" onChange={handleChange} onBlur={handleBlur} value={values.businessName} />
                                {errors.businessName && touched.businessName && <span className="form-error">{errors.businessName}</span>}
                              </div>
jay committed
278
                            </div>
jaymehta committed
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
                            <div className="col-12 offset-lg-1 col-lg-5">
                              <div className="input-group">
                                <label>Brand Logo</label>
                                <div className="custom-file">
                                  <input
                                    disabled={disableFields}
                                    type="file"
                                    className="custom-file-input"
                                    id="brandLogoFile"
                                    name="brandLogoFile"
                                    onChange={handleChange}
                                    onBlur={handleBlur}
                                    value={values.brandLogoFile}
                                  />
                                  <label className="custom-file-label" htmlFor="brandLogoFile">
                                    Upload
                                  </label>
                                </div>
                                <p className="textS">Upload in .PNG or .JPG/JPEG format</p>
                                {errors.brandLogoFile && touched.brandLogoFile && <span className="form-error">{errors.brandLogoFile}</span>}
jay committed
299
                              </div>
300
                            </div>
jay committed
301
                          </div>
302
                        </div>
jaymehta committed
303 304 305 306 307 308 309 310
                        <hr />
                        <div className="mt-4">
                          <p className="textH">Business Address</p>
                          <div className="row">
                            <div className="col-12 col-lg-5">
                              <div className="input-group">
                                <label>Pincode</label>
                                {/* <AsyncTypeahead
jay committed
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
                                onSearch={handleSearch}
                                minLength={3}
                                value={values.pincode}
                                id="basic-behaviors-example"
                                labelKey="name"
                                options={pincodeData && pincodeData.length>0 && pincodeData.map(item=>{
                                    return {name: item.attributes.name, id: item.id}
                                })}
                                placeholder="Choose a state..."
                                ref={ref}
                                onBlur={() => {
                                  console.log(ref.current);
                                  if (!ref.current.state.selected.length > 0) {
                                    ref.current?.clear();
                                  }
                                }}
                                onChange={(e) => {
                                  console.log("input change", e);
                                }}
                              /> */}
jaymehta committed
331 332 333
                                <input disabled={disableFields} type="text" name="pincode" onChange={handleChange} onBlur={handleBlur} value={values.pincode} />
                                {errors.pincode && touched.pincode && <span className="form-error">{errors.pincode}</span>}
                              </div>
jay committed
334
                            </div>
jaymehta committed
335 336 337 338 339 340
                            <div className="col-12 offset-lg-1 col-lg-5">
                              <div className="input-group">
                                <label>Country</label>
                                <input disabled={disableFields} type="text" name="country" onChange={handleChange} onBlur={handleBlur} value={values.country} />
                                {errors.country && touched.country && <span className="form-error">{errors.country}</span>}
                              </div>
jay committed
341 342
                            </div>
                          </div>
jaymehta committed
343 344 345 346 347 348 349 350 351 352 353 354 355 356
                          <div className="row">
                            <div className="col-12 col-lg-5">
                              <div className="input-group">
                                <label>State</label>
                                <input disabled={disableFields} type="text" name="state" onChange={handleChange} onBlur={handleBlur} value={values.state} />
                                {errors.state && touched.state && <span className="form-error">{errors.state}</span>}
                              </div>
                            </div>
                            <div className="col-12 offset-lg-1 col-lg-5">
                              <div className="input-group">
                                <label>City</label>
                                <input disabled={disableFields} type="text" name="city" onChange={handleChange} onBlur={handleBlur} value={values.city} />
                                {errors.city && touched.city && <span className="form-error">{errors.city}</span>}
                              </div>
jay committed
357 358
                            </div>
                          </div>
jaymehta committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372
                          <div className="row">
                            <div className="col-12 col-lg-5">
                              <div className="input-group">
                                <label>Address Line 1</label>
                                <input disabled={disableFields} type="text" name="addressLine1" onChange={handleChange} onBlur={handleBlur} value={values.addressLine1} />
                                {errors.addressLine1 && touched.addressLine1 && <span className="form-error">{errors.addressLine1}</span>}
                              </div>
                            </div>
                            <div className="col-12 offset-lg-1 col-lg-5">
                              <div className="input-group">
                                <label>Address Line 2</label>
                                <input disabled={disableFields} type="text" name="addressLine2" onChange={handleChange} onBlur={handleBlur} value={values.addressLine2} />
                                {errors.addressLine2 && touched.addressLine2 && <span className="form-error">{errors.addressLine2}</span>}
                              </div>
jay committed
373 374
                            </div>
                          </div>
375
                        </div>
jaymehta committed
376
                        <div className="row mt-3 mb-1">
jay committed
377 378
                          <div className="col-12 col-lg-5">
                            <div className="input-group">
jaymehta committed
379 380 381
                              <Button disabled={disableFields} type="submit" className="btn btn-primary btn-submit">
                                Send for Approval
                              </Button>
jay committed
382 383
                            </div>
                          </div>
.  
jaymehta committed
384 385 386 387 388 389 390 391 392
                          <div className="col-12 col-lg-5">
                            <div className="input-group">
                              <Button disabled={false} onClick={()=> {
                                router.push("/vendor/dashboard")
                              }} className="btn btn-primary btn-submit">
                                Go to dashboard
                              </Button>
                            </div>
                          </div>
jay committed
393
                        </div>
jaymehta committed
394 395 396 397
                      </Form>
                    )}
                  </Formik>
                </div>
jay committed
398 399
              </div>
            </div>
jaymehta committed
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
            <div className="col-12 col-lg-4">
              <div className="content-div help-center">
                <h2>Help Center</h2>
                <ul className="helplist">
                  <li>
                    <Image alt="" src="/images/vendor/question.svg" width="22" height="22" />
                    <p>Lorem Ipsum Dolor Sit?</p>
                  </li>
                  <li>
                    <Image alt="" src="/images/vendor/question.svg" width="22" height="22" />
                    <p>Lorem Ipsum Dolor Sit?</p>
                  </li>
                  <li>
                    <Image alt="" src="/images/vendor/question.svg" width="22" height="22" />
                    <p>Lorem Ipsum Dolor Sit?</p>
                  </li>
                  <li>
                    <Image alt="" src="/images/vendor/question.svg" width="22" height="22" />
                    <p>Lorem Ipsum Dolor Sit?</p>
                  </li>
                  <li>
                    <Image alt="" src="/images/vendor/call.svg" width="32" height="32" />
                    <p>+1 (407) 8798 789</p>
                  </li>
                </ul>
              </div>
426
            </div>
jay committed
427 428
          </div>
        </div>
jaymehta committed
429
      )}
jay committed
430 431 432
    </Fragment>
  );
};
433

jay committed
434
export default BusinessDetails;