import "./ShopCoupons.scss"; import { useState, useEffect } from "react"; import { post } from "../../js/helpers/data-helper"; const ShopCoupons = ({ onBack, shop, memberID }) => { const [coupons, setCoupons] = useState([]); const [receiving, setReceiving] = useState(false); const getList = async () => { try { const { code, data, msg } = await post( "/Api/Coupon/ShopDetailCouponList", { paging: 0, memberID, shopCode: shop.code, } ); if (code !== 200) window.weui.toast(msg, { className: "toast", }); else setCoupons(data); } catch (error) { console.warn(error); } }; useEffect(() => { getList(); }, []); const receive = async (coupon) => { setReceiving(true); try { const { code, data, msg } = await post( "/api/ar/v1/applet/ShopCouponReceive", { couponCode: coupon.code, memberID, } ); window.weui.toast(msg, { className: "toast", }); if (code === 200) { getList(); } } catch (error) { console.warn(error); } finally { setReceiving(false); } }; return (