diff --git a/apps/site.ts b/apps/site.ts index ee0feb75..1414b433 100644 --- a/apps/site.ts +++ b/apps/site.ts @@ -1,9 +1,10 @@ import commerce, { Props as CommerceProps } from "apps/commerce/mod.ts"; -import { color as shopify } from "apps/shopify/mod.ts"; +import { color as wap } from "apps/wap/mod.ts"; import { color as vnda } from "apps/vnda/mod.ts"; import { color as vtex } from "apps/vtex/mod.ts"; import { color as wake } from "apps/wake/mod.ts"; import { color as linx } from "apps/linx/mod.ts"; +import { color as shopify } from "apps/shopify/mod.ts"; import { color as nuvemshop } from "apps/nuvemshop/mod.ts"; import { Section } from "deco/blocks/section.ts"; import type { App as A, AppContext as AC } from "deco/mod.ts"; @@ -25,6 +26,7 @@ export type Platform = | "vnda" | "shopify" | "wake" + | "wap" | "linx" | "nuvemshop" | "custom"; @@ -44,6 +46,8 @@ const color = (platform: string) => { return wake; case "shopify": return shopify; + case "wap": + return wap; case "linx": return linx; case "nuvemshop": @@ -66,8 +70,7 @@ export default function Site( if (firstRun) { firstRun = false; console.info( - ` 🐁 ${rgb24("Storefront", color("deco"))} | ${ - rgb24(_platform, color(_platform)) + ` 🐁 ${rgb24("Storefront", color("deco"))} | ${rgb24(_platform, color(_platform)) } \n`, ); } diff --git a/components/header/Buttons/Cart/wap.tsx b/components/header/Buttons/Cart/wap.tsx new file mode 100644 index 00000000..879c8e12 --- /dev/null +++ b/components/header/Buttons/Cart/wap.tsx @@ -0,0 +1,20 @@ +import { itemToAnalyticsItem, useCart } from "apps/wap/hooks/useCart.ts"; +import Button from "./common.tsx"; + +function CartButton() { + const { loading, cart } = useCart(); + const { subtotal, itens } = cart.value ?? {}; + + return ( + WISHLIST @@ -138,6 +143,7 @@ function Navbar( {platform === "linx" && } {platform === "shopify" && } {platform === "nuvemshop" && } + {platform === "wap" && } )} diff --git a/components/minicart/Cart.tsx b/components/minicart/Cart.tsx index c3e43078..c58a65d5 100644 --- a/components/minicart/Cart.tsx +++ b/components/minicart/Cart.tsx @@ -8,6 +8,7 @@ const CartWake = lazy(() => import("./wake/Cart.tsx")); const CartLinx = lazy(() => import("./linx/Cart.tsx")); const CartShopify = lazy(() => import("./shopify/Cart.tsx")); const CartNuvemshop = lazy(() => import("./nuvemshop/Cart.tsx")); +const CartWap = lazy(() => import("./wap/Cart.tsx")); export interface Props { platform: ReturnType; @@ -26,6 +27,10 @@ function Cart({ platform }: Props) { return ; } + if (platform === "wap") { + return ; + } + if (platform === "linx") { return ; } diff --git a/components/minicart/wap/Cart.tsx b/components/minicart/wap/Cart.tsx new file mode 100644 index 00000000..9ada588e --- /dev/null +++ b/components/minicart/wap/Cart.tsx @@ -0,0 +1,59 @@ +import { itemToAnalyticsItem, useCart } from "apps/wap/hooks/useCart.ts"; +import BaseCart from "../common/Cart.tsx"; + +function Cart() { + const { cart, loading, updateItem, updateCoupon, removeItem } = useCart(); + const items = cart.value?.itens ?? []; + + const total = cart.value?.subtotal?.valor ?? 0; + const subtotal = cart.value?.subtotal?.valor ?? 0; + const locale = "pt-BR"; + const currency = "BRL"; + const coupon = cart.value?.coupon ?? undefined; + + return ( + ({ + image: { src: item!.imagem!, alt: "product image" }, + quantity: item!.quantidade!, + name: item!.nome!, + price: { sale: item!.precos.precoPor!, list: item!.precos.precoDe! }, + }))} + total={total} + subtotal={subtotal} + discounts={0} + locale={locale} + currency={currency} + loading={loading.value} + freeShippingTarget={1000} + coupon={coupon} + checkoutHref={`/checkout/carrinho/`} + onAddCoupon={(code) => updateCoupon({ hashCupom: code })} + onUpdateQuantity={(quantidade: number, index: number) => + quantidade === 0 + ? removeItem({ + tipo: "produto", + idProduto: items[index]?.hash.idProduto, + idAtributoSimples: items[index]?.hash.idAtributoSimples, + idUnidadeVenda: items[index]?.hash.idUnidadeVenda, + idArmazem: items[index]?.hash.idArmazem, + }) + : updateItem({ + tipo: "produto", + quantidade, + idProduto: items[index]?.hash.idProduto, + idAtributoSimples: items[index]?.hash.idAtributoSimples, + idUnidadeVenda: items[index]?.hash.idUnidadeVenda, + idArmazem: items[index]?.hash.idArmazem, + }) + } + itemToAnalyticsItem={(index) => { + const item = items[index]; + + return item && itemToAnalyticsItem(item, index); + }} + /> + ); +} + +export default Cart; diff --git a/components/product/AddToCartButton/wap.tsx b/components/product/AddToCartButton/wap.tsx new file mode 100644 index 00000000..3e7622f8 --- /dev/null +++ b/components/product/AddToCartButton/wap.tsx @@ -0,0 +1,33 @@ +import { useCart } from "apps/wap/hooks/useCart.ts"; +import Button, { Props as BtnProps } from "./common.tsx"; + +export interface Props extends Omit { + productID: string; + idAtributoSimples: number; +} + +function AddToCartButton({ + productID, + eventParams, + idAtributoSimples = 0, +}: Props) { + const { addItems } = useCart(); + + const onAddItem = () => + addItems({ + tipo: "produto", + itens: [ + { + idProduto: Number(productID), + quantidade: 1, + idAtributoSimples, + idUnidadeVenda: 0, + idArmazem: 0, + }, + ], + }); + + return