OwlCyberSecurity - MANAGER
Edit File: AddToChinaBasketButton.tsx
"use client"; import { addToChinaBasket, updateChinaCart, } from "@/redux/features/chinaBasketSlice"; import { useRouter } from "next/navigation"; import React, { useEffect } from "react"; import { useDispatch } from "react-redux"; function AddToChinaBasketButton({ link, weight_unit, firstweight, exchange_id, region_id, // image, // name, cost, buyCost, buyProfit, shipBroker, // id, description, count, singleitemfullprice, }: any) { const dispatch = useDispatch(); const router = useRouter(); useEffect(() => { const prevStateCart = localStorage.getItem("persist:root") ? JSON?.parse( // @ts-ignore JSON.parse(localStorage.getItem("persist:root")).chinaBasket ).cart : []; dispatch(updateChinaCart(prevStateCart)); }, []); function addItemToChinaBasket() { const prevStateCart = JSON?.parse( // @ts-ignore JSON.parse(localStorage.getItem("persist:root")).chinaBasket ).cart; dispatch(updateChinaCart(prevStateCart)); const chinaProduct = { link, weight_unit, firstweight, exchange_id, region_id, image: "/assets/images/icons/charsooq-logo.png", name: link.slice(0, 40), cost, buyCost, buyProfit, shipBroker, description, count, singleitemfullprice, }; setTimeout(() => { dispatch(addToChinaBasket(chinaProduct)); }, 500); setTimeout(() => { router.push("/checkout/china"); }, 1000); } return ( <div className="basis-1/4 h-28 bg-white md:h-auto w-full fixed md:static bottom-0 flex flex-col border-t border-[var(--light-border)] right-0 z-20"> <div className="flex md:hidden items-center justify-between px-6 pt-3"> <p className="font-IRANSansBold">قیمت کالا</p> <span className="flex items-center gap-7 font-IRANSansBold pl-14 text-sm md:text-base"> {singleitemfullprice.toLocaleString()} {process.env.price} </span> </div> <button type="submit" onClick={addItemToChinaBasket} className="bg-[var(--base-green)] text-white w-[90%] md:w-full bottom-0 flex items-center gap-4 text-base p-3" style={{ backgroundColor: "var(--base-green)" }} > <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" > <g clipPath="url(#clip0_1603_14426)"> <path d="M5.83366 20.0003C6.75413 20.0003 7.50032 19.2541 7.50032 18.3337C7.50032 17.4132 6.75413 16.667 5.83366 16.667C4.91318 16.667 4.16699 17.4132 4.16699 18.3337C4.16699 19.2541 4.91318 20.0003 5.83366 20.0003Z" fill="white" /> <path d="M14.1667 20.0003C15.0871 20.0003 15.8333 19.2541 15.8333 18.3337C15.8333 17.4132 15.0871 16.667 14.1667 16.667C13.2462 16.667 12.5 17.4132 12.5 18.3337C12.5 19.2541 13.2462 20.0003 14.1667 20.0003Z" fill="white" /> <path d="M19.1663 2.5H17.4997V0.833333C17.4997 0.61232 17.4119 0.400358 17.2556 0.244078C17.0993 0.0877974 16.8873 0 16.6663 0C16.4453 0 16.2334 0.0877974 16.0771 0.244078C15.9208 0.400358 15.833 0.61232 15.833 0.833333V2.5H14.1663C13.9453 2.5 13.7334 2.5878 13.5771 2.74408C13.4208 2.90036 13.333 3.11232 13.333 3.33333C13.333 3.55435 13.4208 3.76631 13.5771 3.92259C13.7334 4.07887 13.9453 4.16667 14.1663 4.16667H15.833V5.83333C15.833 6.05435 15.9208 6.26631 16.0771 6.42259C16.2334 6.57887 16.4453 6.66667 16.6663 6.66667C16.8873 6.66667 17.0993 6.57887 17.2556 6.42259C17.4119 6.26631 17.4997 6.05435 17.4997 5.83333V4.16667H19.1663C19.3873 4.16667 19.5993 4.07887 19.7556 3.92259C19.9119 3.76631 19.9997 3.55435 19.9997 3.33333C19.9997 3.11232 19.9119 2.90036 19.7556 2.74408C19.5993 2.5878 19.3873 2.5 19.1663 2.5Z" fill="white" /> <path d="M18.1425 8.105C18.0348 8.08484 17.9241 8.08626 17.8169 8.10919C17.7097 8.13212 17.6081 8.1761 17.518 8.23857C17.428 8.30105 17.3512 8.38078 17.2922 8.47315C17.2331 8.56552 17.193 8.66868 17.1742 8.77667C17.0702 9.35346 16.767 9.87541 16.3173 10.2513C15.8677 10.6272 15.3003 10.8332 14.7142 10.8333H4.515L3.73167 4.16667H10.8333C11.0543 4.16667 11.2663 4.07887 11.4226 3.92259C11.5789 3.76631 11.6667 3.55435 11.6667 3.33333C11.6667 3.11232 11.5789 2.90036 11.4226 2.74408C11.2663 2.5878 11.0543 2.5 10.8333 2.5H3.535L3.5 2.20667C3.42818 1.59883 3.13588 1.03846 2.67849 0.631753C2.2211 0.225045 1.6304 0.000260697 1.01833 0L0.833333 0C0.61232 0 0.400358 0.0877974 0.244078 0.244078C0.0877974 0.400358 0 0.61232 0 0.833333C0 1.05435 0.0877974 1.26631 0.244078 1.42259C0.400358 1.57887 0.61232 1.66667 0.833333 1.66667H1.01833C1.22244 1.66669 1.41945 1.74163 1.57198 1.87726C1.72451 2.0129 1.82195 2.19979 1.84583 2.4025L2.9925 12.1525C3.11154 13.1665 3.59873 14.1015 4.36159 14.78C5.12445 15.4585 6.10988 15.8334 7.13083 15.8333H15.8333C16.0543 15.8333 16.2663 15.7455 16.4226 15.5893C16.5789 15.433 16.6667 15.221 16.6667 15C16.6667 14.779 16.5789 14.567 16.4226 14.4107C16.2663 14.2545 16.0543 14.1667 15.8333 14.1667H7.13083C6.61377 14.1668 6.10939 14.0065 5.68718 13.708C5.26496 13.4096 4.94569 12.9875 4.77333 12.5H14.7142C15.691 12.5001 16.6367 12.157 17.3863 11.5307C18.1358 10.9044 18.6415 10.0346 18.815 9.07333C18.8345 8.96559 18.8325 8.85507 18.8092 8.74808C18.786 8.6411 18.7419 8.53974 18.6794 8.44981C18.6169 8.35989 18.5374 8.28315 18.4453 8.22398C18.3531 8.16482 18.2503 8.12439 18.1425 8.105Z" fill="white" /> </g> <defs> <clipPath id="clip0_1603_14426"> <rect width="20" height="20" fill="white" /> </clipPath> </defs> </svg> <p>افزودن به سبد خرید</p> {/* <p>{asin}</p> */} </button> </div> ); } export default AddToChinaBasketButton;