Blame view

components/admin/GiftcardListing.js 5.75 KB
Chetan committed
1 2
import { Fragment, useEffect, useState } from "react";
import { Button, Image } from "react-bootstrap";
3
import { Dropdown, Menu, Space, Table, Tag } from "antd";
Chetan committed
4
import axios from "axios";
5 6 7
import { DownCircleOutlined, MoreOutlined } from "@ant-design/icons";
import { getSession } from "next-auth/react";
import { toast } from "react-toastify";
Jyotsna committed
8
const GiftcardListing = () => {
.  
jaymehta committed
9 10
  const [session, setSession] = useState();
  const [update, setupdate] = useState(false);
11 12 13 14 15 16 17 18 19
  useEffect(() => {
    const fetchSession = async () => {
      setSession(await getSession());
    };
    fetchSession();
    // dispatch(getLoggedInVendor());
  }, []);
  const [giftData, setGiftData] = useState([]);
  useEffect(() => {
.  
jaymehta committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    axios
      .get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/gift-cards`)
      .then(res => {
        let giftDatas =
          res.data &&
          res.data.data.map(data => {
            return {
              key: data.id,
              amount: data?.attributes?.amount,
              senderEmail: data?.attributes?.senderEmail,
              receiverEmail: data?.attributes?.receiverEmail,
              status: data?.attributes?.status,
              senderName: data?.attributes?.senderName,
              receiverName: data?.attributes?.receiverName
            };
          });
        setGiftData(giftDatas);
      })
      .catch(err => {
        console.log(err);
      });
  }, [update]);
42 43 44 45 46 47
  const changeStatusFn = async ({ id, data }) => {
    const config = {
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${session.jwt}`
      }
.  
jaymehta committed
48
    };
49 50
    const giftdata = {
      data
.  
jaymehta committed
51
    };
52

.  
jaymehta committed
53
    const response = await axios.put(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/gift-cards/${id}`, giftdata, config);
54
    if (response.status == 200) {
.  
jaymehta committed
55 56
      toast.success("Status changed");
      setupdate(!update);
57 58
    }
    console.log("response gift card", response);
.  
jaymehta committed
59
  };
60 61 62 63 64 65 66 67
  const columns = [
    {
      title: "Sender Email Address",
      dataIndex: "senderEmail",
      key: "senderEmail",
      render: text => <a>{text}</a>
    },
    {
.  
jaymehta committed
68 69 70 71 72 73
      title: "Sender Name",
      dataIndex: "senderName",
      key: "senderName",
      render: text => <a>{text}</a>
    },
    {
74 75 76 77 78 79
      title: "Receiver Email Address",
      dataIndex: "receiverEmail",
      key: "receiverEmail",
      render: text => <a>{text}</a>
    },
    {
.  
jaymehta committed
80 81 82 83 84 85
      title: "Receiver Name",
      dataIndex: "receiverName",
      key: "receiverName",
      render: text => <a>{text}</a>
    },
    {
86 87 88 89 90
      title: "Amount",
      dataIndex: "amount",
      key: "amount",
      render: text => <a>{text}</a>
    }
.  
jaymehta committed
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 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
    // {
    //   title: "Status",
    //   dataIndex: "status",
    //   key: "status",
    //   render: tag => (
    //     <span>
    //       {tag == "rejected" ? (
    //         <Tag color={"red"} key={tag}>
    //           {tag.toUpperCase()}
    //         </Tag>
    //       ) : (
    //         <Tag color={"blue"} key={tag}>
    //           {tag === "fulfilled" ? "APPROVED" : tag.toUpperCase()}
    //         </Tag>
    //       )}
    //     </span>
    //   )
    // },
    // {
    //   title: "Actions",
    //   width: 100,
    //   dataIndex: "key",
    //   key: "key",
    //   render: (_, record) => (
    //     <Space size="middle">
    //       {/* <a>Invite {record.name}</a> */}
    //       <Dropdown
    //         menu={{
    //           items: [
    //             {
    //               key: "1",
    //               label: (
    //                 <a
    //                   rel="noopener noreferrer"
    //                   onClick={async () => {
    //                     console.log("record", record);
    //                     await changeStatusFn({ id: record.key, data: { status: "fulfilled" } });
    //                     // setrejectionId(record.key);
    //                     // adminActions({ type: "reject", activityId: record.key });
    //                   }}
    //                 >
    //                   Approve
    //                 </a>
    //               )
    //             },
    //             {
    //               key: "2",
    //               label: (
    //                 <a
    //                   target="_blank"
    //                   rel="noopener noreferrer"
    //                   onClick={async () => {
    //                     console.log("record", record);
    //                     await changeStatusFn({ id: record.key, data: { status: "rejected" } });
    //                     // setrejectionId(record.key);
    //                     // adminActions({ type: "reject", activityId: record.key });
    //                   }}
    //                 >
    //                   Reject
    //                 </a>
    //               )
    //             }
    //           ]
    //         }}
    //         placement="bottomLeft"
    //         trigger={["click"]}
    //       >
    //         <button className="btn border-0">
    //           <DownCircleOutlined style={{ fontSize: "20px", color: "#08c" }} onClick={() => {}} />
    //         </button>
    //       </Dropdown>
    //     </Space>
    //   )
    // }
  ];
  console.log("giftData", giftData);
167 168 169 170 171 172 173 174
  return (
    <Fragment>
      <div className="p-5 h-100">
        <div className="d-flex align-items-center justify-content-between px-2 mb-2">
          <div>
            <h2 style={{ fontSize: 28 }}>Gift Card Requests</h2>
            <p>View all the gift cards</p>
          </div>
jaymehta committed
175
          {/* <div>
176 177 178
            <Button type="button" variant="" className="btnAdd m-0">
              <Image alt="" width="16" height="16" src="/images/vendor/icon-filter.svg" className="me-2" /> Filter
            </Button>
jaymehta committed
179
          </div> */}
180 181 182 183 184
        </div>
        <Table columns={columns} dataSource={giftData} />
      </div>
    </Fragment>
  );
Jyotsna committed
185 186 187
};

export default GiftcardListing;