Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: attachment product #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions components/product/AddToCartButton/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,19 @@ export default function AddToCartButton(props: Props) {
return (
<Button
{...btnProps}
class="rounded-none btn shadow-none border-0 bg-[#B4CBF0] hover:bg-[#81A1D4] transition-[0.3s] hover:text-white flex h-12 justify-center items-center gap-2.5 self-stretch px-4 py-2.5 text-xs not-italic font-bold leading-[normal] tracking-[1.2px] uppercase text-[#243959]"
class={`rounded-none btn shadow-none border-0 transition-[0.3s] flex h-12 justify-center items-center gap-2.5 self-stretch px-4 py-2.5 text-xs not-italic font-bold leading-[normal] tracking-[1.2px] uppercase text-[#243959] ${
props.buttonDisabled
? "bg-[#f5f5f5] cursor-not-allowed pointer-events-none"
: "bg-[#B4CBF0] hover:bg-[#81A1D4] hover:text-white"
}`}
>
comprar
{props.buttonDisabled
? (
"Selecione o tamanho"
)
: (
"Comprar"
)}
</Button>
);
}
96 changes: 77 additions & 19 deletions components/product/AddToCartButton/vtex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,92 @@ export interface Props extends Omit<BtnProps, "onAddItem"> {
}

function AddToCartButton({ seller, productID, category, eventParams }: Props) {
const { addItems } = useCart();
const { cart, addItems, addItemAttachment } = useCart();
const { items } = cart.value ?? { items: [] };

const [selectedSize, setSelectedSize] = useState<string>("");

const onAddItem = () =>
addItems({
orderItems: [{
id: productID,
seller: seller,
quantity: 1,
}],
const handleSizeChange = (e: Event) => {
const target = e.target as HTMLSelectElement;
setSelectedSize(target.value);
};

const onAddItem = async () => {
await addItems({
orderItems: [{ id: productID, seller, quantity: 1 }],
});

if (category === "Anéis") {
const existingItemIndex = items.findIndex((item) =>
item.id === productID
);
const index = existingItemIndex >= 0 ? existingItemIndex : items.length;

await addItemAttachment({
index: index,
attachment: "personalization",
content: { aro: selectedSize },
});
}
};

const RING_SIZES = [
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
];

return (
<>
{/* <p>{category}</p> */}

{
/* {category === "Anéis" && (
<select name="" id="">
<option value="">Teste 1</option>
<option value="">Teste 2</option>
<option value="">Teste 3</option>
{category === "Anéis" && (
<p className="text-[12px] font-normal not-italic leading-normal">
Tamanho
</p>
)}

{category === "Anéis" && (
<select
name="size"
id="size"
onChange={handleSizeChange}
className="w-full border border-gray-300 rounded-none p-2 text-gray-900 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
>
<option value="" disabled selected>
Selecione
</option>

{RING_SIZES.map((size) => (
<option key={size} value={size}>
{size}
</option>
))}
</select>
)} */
}
)}

{category === "Anéis" && (
<Button
onAddItem={onAddItem}
eventParams={eventParams}
buttonDisabled={!selectedSize}
/>
)}

<Button onAddItem={onAddItem} eventParams={eventParams} />
{category !== "Anéis" && (
<Button
onAddItem={onAddItem}
eventParams={eventParams}
buttonDisabled={false}
/>
)}
</>
);
}
Expand Down
30 changes: 30 additions & 0 deletions static/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -4568,6 +4568,9 @@ details.collapse summary::-webkit-details-marker {
white-space: nowrap;
border-width: 0;
}
.pointer-events-none {
pointer-events: none;
}
.pointer-events-auto {
pointer-events: auto;
}
Expand Down Expand Up @@ -5832,6 +5835,9 @@ details.collapse summary::-webkit-details-marker {
.cursor-default {
cursor: default;
}
.cursor-not-allowed {
cursor: not-allowed;
}
.cursor-pointer {
cursor: pointer;
}
Expand Down Expand Up @@ -6363,6 +6369,10 @@ details.collapse summary::-webkit-details-marker {
--tw-border-opacity: 1;
border-color: rgb(0 0 0 / var(--tw-border-opacity));
}
.border-gray-300 {
--tw-border-opacity: 1;
border-color: rgb(209 213 219 / var(--tw-border-opacity));
}
.border-neutral {
--tw-border-opacity: 1;
border-color: var(--fallback-n,oklch(var(--n)/var(--tw-border-opacity)));
Expand Down Expand Up @@ -7333,6 +7343,10 @@ details.collapse summary::-webkit-details-marker {
--tw-text-opacity: 1;
color: rgb(0 0 0 / var(--tw-text-opacity));
}
.text-gray-900 {
--tw-text-opacity: 1;
color: rgb(17 24 39 / var(--tw-text-opacity));
}
.text-neutral {
--tw-text-opacity: 1;
color: var(--fallback-n,oklch(var(--n)/var(--tw-text-opacity)));
Expand Down Expand Up @@ -8754,6 +8768,11 @@ summary {
border-color: rgb(18 119 73 / var(--tw-border-opacity));
}

.focus\:border-blue-500:focus {
--tw-border-opacity: 1;
border-color: rgb(59 130 246 / var(--tw-border-opacity));
}

.focus\:outline-none:focus {
outline: 2px solid transparent;
outline-offset: 2px;
Expand All @@ -8763,6 +8782,17 @@ summary {
outline-width: 0px;
}

.focus\:ring-2:focus {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}

.focus\:ring-blue-500:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity));
}

.disabled\:hidden:disabled {
display: none;
}
Expand Down