fix type error
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import * as api from "../service/CartService";
|
import * as api from "../service/CartService";
|
||||||
import type { CartResponse } from "../types/Types";
|
import type { CartResponse, CartItem } from "../types/Types";
|
||||||
|
|
||||||
export const useBulkCart = () => {
|
export const useBulkCart = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
@@ -76,7 +76,7 @@ export const useDecrementCart = () => {
|
|||||||
|
|
||||||
if (previousCart?.data) {
|
if (previousCart?.data) {
|
||||||
const updatedItems = previousCart.data.items
|
const updatedItems = previousCart.data.items
|
||||||
.map((item) => {
|
.map((item: CartItem) => {
|
||||||
if (item.foodId === String(id)) {
|
if (item.foodId === String(id)) {
|
||||||
const newQuantity = item.quantity - 1;
|
const newQuantity = item.quantity - 1;
|
||||||
if (newQuantity <= 0) {
|
if (newQuantity <= 0) {
|
||||||
@@ -89,7 +89,7 @@ export const useDecrementCart = () => {
|
|||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
})
|
})
|
||||||
.filter((item): item is NonNullable<typeof item> => item !== null);
|
.filter((item: CartItem | null): item is CartItem => item !== null);
|
||||||
|
|
||||||
queryClient.setQueryData<CartResponse>(["cart-items"], {
|
queryClient.setQueryData<CartResponse>(["cart-items"], {
|
||||||
...previousCart,
|
...previousCart,
|
||||||
|
|||||||
@@ -33,4 +33,45 @@ export interface CartData {
|
|||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CartCategory {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
title: string;
|
||||||
|
isActive: boolean;
|
||||||
|
restaurant: string;
|
||||||
|
avatarUrl: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CartFood {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
restaurant: string;
|
||||||
|
category: CartCategory;
|
||||||
|
title: string;
|
||||||
|
desc: string;
|
||||||
|
content: string | string[] | null;
|
||||||
|
price: number;
|
||||||
|
points: number | null;
|
||||||
|
order: number | null;
|
||||||
|
prepareTime: number | null;
|
||||||
|
sat: boolean;
|
||||||
|
sun: boolean;
|
||||||
|
mon: boolean;
|
||||||
|
breakfast: boolean;
|
||||||
|
noon: boolean;
|
||||||
|
dinner: boolean;
|
||||||
|
stock: number;
|
||||||
|
stockDefault: number;
|
||||||
|
isActive: boolean;
|
||||||
|
images: string[];
|
||||||
|
inPlaceServe: boolean;
|
||||||
|
pickupServe: boolean;
|
||||||
|
rate: number;
|
||||||
|
discount: number;
|
||||||
|
}
|
||||||
|
|
||||||
export type CartResponse = BaseResponse<CartData>;
|
export type CartResponse = BaseResponse<CartData>;
|
||||||
|
|||||||
Reference in New Issue
Block a user