Skip to content

Commit ed7ce77

Browse files
committed
Typescript update for update cart
1 parent 83472f5 commit ed7ce77

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

refactor/src/utils/functions/functions.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ export interface IProductRootObject {
5757

5858
type TUpdatedItems = { key: string; quantity: number }[];
5959

60+
export interface IUpdateCartItem {
61+
key: string;
62+
quantity: number;
63+
}
64+
65+
export interface IUpdateCartInput {
66+
clientMutationId: string;
67+
items: IUpdateCartItem[];
68+
}
69+
70+
export interface IUpdateCartVariables {
71+
input: IUpdateCartInput;
72+
}
73+
74+
export interface IUpdateCartRootObject {
75+
variables: IUpdateCartVariables;
76+
}
77+
6078
/* Interface for props */
6179

6280
interface IFormattedCartProps {
@@ -271,7 +289,7 @@ export const handleQuantityChange = (
271289
event: ChangeEvent<HTMLInputElement>,
272290
cartKey: string,
273291
cart: IProductRootObject[],
274-
updateCart: any, // Lazy solution, but saves us from a lot of warnings
292+
updateCart: (variables: IUpdateCartRootObject) => void,
275293
updateCartProcessing: boolean
276294
) => {
277295
if (process.browser) {
@@ -288,6 +306,15 @@ export const handleQuantityChange = (
288306
if (cart.length) {
289307
const updatedItems = getUpdatedItems(cart, newQty, cartKey);
290308

309+
const test = {
310+
variables: {
311+
input: {
312+
clientMutationId: uuidv4(),
313+
items: updatedItems,
314+
},
315+
},
316+
};
317+
291318
updateCart({
292319
variables: {
293320
input: {

0 commit comments

Comments
 (0)