mirror of
https://github.com/vercel/commerce.git
synced 2025-03-14 22:42:33 +00:00
Fix Compile errors.
This commit is contained in:
parent
0190f3b541
commit
30b99374ba
1
.vercelignore
Normal file
1
.vercelignore
Normal file
@ -0,0 +1 @@
|
||||
lib
|
@ -1,5 +1,5 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import useSWR, { mutate } from 'swr';
|
||||
import { useState, useCallback } from "react";
|
||||
import useSWR, { mutate } from "swr";
|
||||
|
||||
async function getText(res) {
|
||||
try {
|
||||
@ -10,7 +10,7 @@ async function getText(res) {
|
||||
}
|
||||
|
||||
async function getError(res) {
|
||||
if (res.headers.get('Content-Type')?.includes('application/json')) {
|
||||
if (res.headers.get("Content-Type")?.includes("application/json")) {
|
||||
const data = await res.json();
|
||||
return data.errors[0];
|
||||
}
|
||||
@ -27,7 +27,7 @@ async function fetcher(url) {
|
||||
}
|
||||
|
||||
export function useCart() {
|
||||
return useSWR('/api/cart', fetcher);
|
||||
return useSWR("/api/cart", fetcher);
|
||||
}
|
||||
|
||||
export function useAddToCart() {
|
||||
@ -37,10 +37,10 @@ export function useAddToCart() {
|
||||
const addToCart = useCallback(async ({ product }) => {
|
||||
setStatus({ addingToCart: true });
|
||||
|
||||
const res = await fetch('/api/cart', {
|
||||
method: 'POST',
|
||||
const res = await fetch("/api/cart", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ product }),
|
||||
});
|
||||
@ -48,12 +48,12 @@ export function useAddToCart() {
|
||||
// Product added as expected
|
||||
if (res.status === 200) {
|
||||
setStatus({ addingToCart: false });
|
||||
return mutate('/api/cart');
|
||||
return mutate("/api/cart");
|
||||
}
|
||||
|
||||
const error = await getError(res);
|
||||
|
||||
console.error('Adding product to cart failed with:', res.status, error);
|
||||
console.error("Adding product to cart failed with:", res.status, error);
|
||||
setStatus({ addingToCart: false, error });
|
||||
}, []);
|
||||
|
||||
@ -70,11 +70,11 @@ export function useUpdateCart() {
|
||||
const res = await fetch(
|
||||
`/api/cart?itemId=${item.id}`,
|
||||
product.quantity < 1
|
||||
? { method: 'DELETE' }
|
||||
? { method: "DELETE" }
|
||||
: {
|
||||
method: 'PUT',
|
||||
method: "PUT",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ product }),
|
||||
}
|
||||
@ -83,12 +83,12 @@ export function useUpdateCart() {
|
||||
// Product updated as expected
|
||||
if (res.status === 200) {
|
||||
setStatus({ updatingCart: false });
|
||||
return mutate('/api/cart');
|
||||
return mutate("/api/cart");
|
||||
}
|
||||
|
||||
const error = await getError(res);
|
||||
|
||||
console.error('Update to cart failed with:', res.status, error);
|
||||
console.error("Update to cart failed with:", res.status, error);
|
||||
setStatus({ updatingCart: false, error });
|
||||
}, []);
|
||||
|
@ -16,7 +16,6 @@
|
||||
"jsx": "preserve",
|
||||
"paths": {
|
||||
"@components/*": ["components/*"],
|
||||
"@lib/*": ["lib/*"],
|
||||
"@styles/*": ["styles/*"]
|
||||
}
|
||||
},
|
||||
|
@ -7,7 +7,6 @@ interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
className?: string;
|
||||
variant?: "filled" | "outlined" | "flat" | "none";
|
||||
active?: boolean;
|
||||
disabled?: boolean;
|
||||
type?: "submit" | "reset" | "button";
|
||||
}
|
||||
|
||||
@ -24,7 +23,9 @@ export default class Button extends React.Component<Props> {
|
||||
} = this.props;
|
||||
|
||||
let Component: React.ComponentType<
|
||||
React.ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement> &
|
||||
React.AnchorHTMLAttributes<
|
||||
HTMLAnchorElement | HTMLButtonElement | HTMLDivElement
|
||||
> &
|
||||
React.ClassAttributes<HTMLButtonElement | HTMLAnchorElement>
|
||||
> = "a" as any;
|
||||
|
||||
@ -41,7 +42,6 @@ export default class Button extends React.Component<Props> {
|
||||
return (
|
||||
<Component
|
||||
className={rootClassName}
|
||||
disabled={disabled}
|
||||
href={href}
|
||||
aria-pressed={active}
|
||||
data-variant={variant}
|
||||
|
Loading…
x
Reference in New Issue
Block a user