forked from crowetic/commerce
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 { useState, useCallback } from "react";
|
||||||
import useSWR, { mutate } from 'swr';
|
import useSWR, { mutate } from "swr";
|
||||||
|
|
||||||
async function getText(res) {
|
async function getText(res) {
|
||||||
try {
|
try {
|
||||||
@ -10,7 +10,7 @@ async function getText(res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getError(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();
|
const data = await res.json();
|
||||||
return data.errors[0];
|
return data.errors[0];
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ async function fetcher(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useCart() {
|
export function useCart() {
|
||||||
return useSWR('/api/cart', fetcher);
|
return useSWR("/api/cart", fetcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAddToCart() {
|
export function useAddToCart() {
|
||||||
@ -37,10 +37,10 @@ export function useAddToCart() {
|
|||||||
const addToCart = useCallback(async ({ product }) => {
|
const addToCart = useCallback(async ({ product }) => {
|
||||||
setStatus({ addingToCart: true });
|
setStatus({ addingToCart: true });
|
||||||
|
|
||||||
const res = await fetch('/api/cart', {
|
const res = await fetch("/api/cart", {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ product }),
|
body: JSON.stringify({ product }),
|
||||||
});
|
});
|
||||||
@ -48,12 +48,12 @@ export function useAddToCart() {
|
|||||||
// Product added as expected
|
// Product added as expected
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
setStatus({ addingToCart: false });
|
setStatus({ addingToCart: false });
|
||||||
return mutate('/api/cart');
|
return mutate("/api/cart");
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = await getError(res);
|
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 });
|
setStatus({ addingToCart: false, error });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -70,11 +70,11 @@ export function useUpdateCart() {
|
|||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`/api/cart?itemId=${item.id}`,
|
`/api/cart?itemId=${item.id}`,
|
||||||
product.quantity < 1
|
product.quantity < 1
|
||||||
? { method: 'DELETE' }
|
? { method: "DELETE" }
|
||||||
: {
|
: {
|
||||||
method: 'PUT',
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ product }),
|
body: JSON.stringify({ product }),
|
||||||
}
|
}
|
||||||
@ -83,12 +83,12 @@ export function useUpdateCart() {
|
|||||||
// Product updated as expected
|
// Product updated as expected
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
setStatus({ updatingCart: false });
|
setStatus({ updatingCart: false });
|
||||||
return mutate('/api/cart');
|
return mutate("/api/cart");
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = await getError(res);
|
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 });
|
setStatus({ updatingCart: false, error });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
@ -16,7 +16,6 @@
|
|||||||
"jsx": "preserve",
|
"jsx": "preserve",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@components/*": ["components/*"],
|
"@components/*": ["components/*"],
|
||||||
"@lib/*": ["lib/*"],
|
|
||||||
"@styles/*": ["styles/*"]
|
"@styles/*": ["styles/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -7,7 +7,6 @@ interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|||||||
className?: string;
|
className?: string;
|
||||||
variant?: "filled" | "outlined" | "flat" | "none";
|
variant?: "filled" | "outlined" | "flat" | "none";
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
disabled?: boolean;
|
|
||||||
type?: "submit" | "reset" | "button";
|
type?: "submit" | "reset" | "button";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +23,9 @@ export default class Button extends React.Component<Props> {
|
|||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
let Component: React.ComponentType<
|
let Component: React.ComponentType<
|
||||||
React.ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement> &
|
React.AnchorHTMLAttributes<
|
||||||
|
HTMLAnchorElement | HTMLButtonElement | HTMLDivElement
|
||||||
|
> &
|
||||||
React.ClassAttributes<HTMLButtonElement | HTMLAnchorElement>
|
React.ClassAttributes<HTMLButtonElement | HTMLAnchorElement>
|
||||||
> = "a" as any;
|
> = "a" as any;
|
||||||
|
|
||||||
@ -41,7 +42,6 @@ export default class Button extends React.Component<Props> {
|
|||||||
return (
|
return (
|
||||||
<Component
|
<Component
|
||||||
className={rootClassName}
|
className={rootClassName}
|
||||||
disabled={disabled}
|
|
||||||
href={href}
|
href={href}
|
||||||
aria-pressed={active}
|
aria-pressed={active}
|
||||||
data-variant={variant}
|
data-variant={variant}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user