Blame view

components/admin/VendorDetails.js 7.47 KB
jaymehta committed
1
import React, { Fragment, useEffect, useState } from "react";
Jyotsna committed
2 3 4 5 6
import { Button, Table } from "react-bootstrap";
import { FaAngleLeft, FaArrowLeft } from "react-icons/fa";
import ActivityDetailsModal from "./ActivityDetailsModal";
import Image from "next/image";
import RejectModal from "./RejectModal";
jaymehta committed
7 8 9 10 11 12 13
import ActivityListingRBAC from "../vendor/ActivityListingRBAC";
import { useDispatch, useSelector } from "react-redux";
import { getActivitiesByVendor, getActivitiesForAdmin } from "../../redux/actions/activityAction";
import { Tag } from "antd";
import { updateApprovalStatusAdmin } from "../../redux/actions/userActions";
import { getAllVendors } from "../../redux/actions/vendorActions";
import { toast } from "react-toastify";
Jyotsna committed
14

jaymehta committed
15
const VendorDetails = ({ id, backClick, setShowDetail, showDetail, detail }) => {
.  
jaymehta committed
16
  const { allVendors } = useSelector(state => state.allVendors);
Jyotsna committed
17

.  
jaymehta committed
18 19 20 21 22
  const dispatch = useDispatch();
  useEffect(() => {
    dispatch(getActivitiesForAdmin({ vendorId: detail[0].id }));
    console.log("cancel policy", detail[0]);
  }, []);
jaymehta committed
23

.  
jaymehta committed
24 25 26
  useEffect(() => {
    dispatch(getActivitiesForAdmin({ vendorId: detail[0].id }));
  }, [allVendors]);
jaymehta committed
27

.  
jaymehta committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  console.log("detail", detail);
  const [showActivityDetailsModal, setShowActivityDetailsModal] = useState(false);
  const [showRejectModal, setShowRejectModal] = useState(false);
  const [activityDetailInfo, setactivityDetailInfo] = useState();
  const handleShowActivityDetails = () => {
    setShowActivityDetailsModal(true);
  };
  const handleCloseActivityDetails = () => {
    setShowActivityDetailsModal(false);
  };
  const handleShowRejectModal = () => {
    setShowRejectModal(true);
  };
  const handleCloseRejectModal = () => {
    setShowRejectModal(false);
  };
jaymehta committed
44

.  
jaymehta committed
45 46 47 48 49 50 51 52 53 54
  const UserStatus = () => {
    if (!detail || !detail.length > 0) return;
    const currentStatus = detail[0].attributes.user.data.attributes.approved;
    let message;
    let color;
    switch (currentStatus) {
      case "approved":
        message = "Approved";
        color = "success";
        break;
jaymehta committed
55

.  
jaymehta committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 116 117 118 119 120 121 122
      case "rejected":
        message = "Rejected";
        color = "error";
        break;
      case "pending":
        message = "Pending";
        color = "warning";
        break;
      default:
        break;
    }
    return <Tag color={color}>{message.toUpperCase()}</Tag>;
  };
  return (
    <Fragment>
      <div className="vendorDetails">
        <div className="row">
          <div className="col-12 col-lg-12">
            <div className="d-flex align-items-center justify-content-between">
              <div className="backDiv">
                <span className="backArrow">
                  <FaAngleLeft
                    onClick={() => {
                      setShowDetail(false);
                    }}
                  />
                </span>
                <span>Vendors List</span>
              </div>
            </div>
          </div>
          <div className="col-8 col-lg-8 mt-4">
            <h4>Business Information</h4>
            <div className="row">
              <div className="col-12 col-lg-5">
                <p className="phead">Business Documents</p>
                {/* <div className="row">
                  <p className="col-12 col-lg-6">Business PAN No.</p>
                  <p className="col-12 col-lg-6">{detail[0].attributes.pan}</p>
                </div> */}
                {/* <div className="row">
                  <p className="col-12 col-lg-6">PAN</p>
                  <p className="col-12 col-lg-6 pview">View</p>
                </div> */}
                <div className="row">
                  <p className="col-12 col-lg-6">EIN Number</p>
                  <p className="col-12 col-lg-6">{detail[0].attributes.einNumber}</p>
                </div>
                {/* <div className="row">
                  <p className="col-12 col-lg-6">GST Certificate</p>
                  <p className="col-12 col-lg-6 pview">View</p>
                </div> */}
                <div className="row">
                  <p className="col-12 col-lg-6">Business Name</p>
                  <p className="col-12 col-lg-6">{detail[0].attributes.businessName}</p>
                </div>
              </div>
              <div className="col-12 col-lg-7 borderLeft">
                <p className="phead">Business Address</p>
                <div className="row">
                  <p className="col-12 col-lg-4">Pincode</p>
                  <p className="col-12 col-lg-8">{detail[0].attributes.pincode}</p>
                </div>
                <div className="row">
                  <p className="col-12 col-lg-4">Country</p>
                  <p className="col-12 col-lg-8">United States</p>
                </div>
jaymehta committed
123
                <div className="row">
.  
jaymehta committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
                  <p className="col-12 col-lg-4">State</p>
                  <p className="col-12 col-lg-8">{detail[0].attributes.state}</p>
                </div>
                <div className="row">
                  <p className="col-12 col-lg-4">City</p>
                  <p className="col-12 col-lg-8">{detail[0].attributes.city}</p>
                </div>
                <div className="row">
                  <p className="col-12 col-lg-4">Address Line 1</p>
                  <p className="col-12 col-lg-8">{detail[0].attributes.addressLine1}</p>
                </div>
                <div className="row">
                  <p className="col-12 col-lg-4">Address Line 2</p>
                  <p className="col-12 col-lg-8">{detail[0].attributes.addressLine2 ? detail[0].attributes.addressLine2 : "N/A"}</p>
                </div>
              </div>
            </div>
          </div>
Ravindra Kanojiya committed
142

.  
jaymehta committed
143 144 145
          <div className=" col-4">
            <div className="row">
              {/* <div className="col-12">
jaymehta committed
146 147 148 149 150 151 152
                <div className="row">
                  <div className="col-6">Current status:</div>
                  <div className="col-6">
                    <UserStatus />
                  </div>
                </div>
              </div> */}
.  
jaymehta committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
              <div className="col-md-12 d-flex">
                <Button
                  variant=""
                  className="btnAdd btnApprove  col-6 me-2"
                  onClick={async () => {
                    await updateApprovalStatusAdmin({ status: "approved", userId: detail[0].attributes.user.data.id });
                    toast.success("User approved");
                    await dispatch(getAllVendors());
                  }}
                >
                  Approve
                </Button>
                <Button variant="" className="btnAdd btnReject  col-6" onClick={handleShowRejectModal}>
                  Reject
                </Button>
              </div>
              <div className="col-12">
                <div className="d-flex align-items-center gap-4">
                  <p className="phead m-0">Status :</p> <UserStatus />
Ravindra Kanojiya committed
172
                </div>
.  
jaymehta committed
173
              </div>
jaymehta committed
174
            </div>
.  
jaymehta committed
175 176 177 178 179 180 181
          </div>
          <div className="col-12 col-lg-12 mt-4">
            <h4 className="mb-1">Activities</h4>
            <ActivityListingRBAC setactivityDetailInfo={setactivityDetailInfo} setShowActivityDetailsModal={setShowActivityDetailsModal} />
          </div>
        </div>
      </div>
Jyotsna committed
182

.  
jaymehta committed
183
      {showActivityDetailsModal && <ActivityDetailsModal show={showActivityDetailsModal} handleClose={handleCloseActivityDetails} activityDetailInfo={activityDetailInfo} />}
Jyotsna committed
184

.  
jaymehta committed
185 186 187
      {showRejectModal && <RejectModal show={showRejectModal} handleClose={handleCloseRejectModal} detail={detail} setShowDetail={setShowDetail} />}
    </Fragment>
  );
jaymehta committed
188 189
};
export default VendorDetails;