tab count
This commit is contained in:
@@ -18,6 +18,7 @@ import { getOrderListColumns } from "./components/OrderListColumns";
|
|||||||
import {
|
import {
|
||||||
useDeleteOrder,
|
useDeleteOrder,
|
||||||
useGetOrders,
|
useGetOrders,
|
||||||
|
useGetOrderTabCounts,
|
||||||
useUpdateOrderStatus,
|
useUpdateOrderStatus,
|
||||||
} from "./hooks/useOrderData";
|
} from "./hooks/useOrderData";
|
||||||
import {
|
import {
|
||||||
@@ -51,11 +52,39 @@ const OrdersList: FC = () => {
|
|||||||
} = useOrderListParams();
|
} = useOrderListParams();
|
||||||
|
|
||||||
const { data, refetch, isFetching } = useGetOrders(queryParams);
|
const { data, refetch, isFetching } = useGetOrders(queryParams);
|
||||||
|
const { data: tabCounts } = useGetOrderTabCounts({
|
||||||
|
designId: params.designerId,
|
||||||
|
categoryId: params.categoryId,
|
||||||
|
userId: params.userId,
|
||||||
|
search: params.search ?? null,
|
||||||
|
from: params.from ?? null,
|
||||||
|
to: params.to ?? null,
|
||||||
|
});
|
||||||
const { mutate: deleteOrder, isPending: isDeleting } = useDeleteOrder();
|
const { mutate: deleteOrder, isPending: isDeleting } = useDeleteOrder();
|
||||||
const { mutate: updateOrderStatus, isPending: isUpdatingStatus } =
|
const { mutate: updateOrderStatus, isPending: isUpdatingStatus } =
|
||||||
useUpdateOrderStatus();
|
useUpdateOrderStatus();
|
||||||
const activeFilterCount = useMemo(() => countActiveFilters(params), [params]);
|
const activeFilterCount = useMemo(() => countActiveFilters(params), [params]);
|
||||||
const hasActiveFilters = activeFilterCount > 0;
|
const hasActiveFilters = activeFilterCount > 0;
|
||||||
|
const tabCountByTab: Record<TabOrderListEnum, number> = useMemo(
|
||||||
|
() => ({
|
||||||
|
[TabOrderListEnum.IN_PROGRESS]: tabCounts?.inProgress ?? 0,
|
||||||
|
[TabOrderListEnum.FINISHED]: tabCounts?.finished ?? 0,
|
||||||
|
[TabOrderListEnum.CANCELED]: tabCounts?.canceled ?? 0,
|
||||||
|
[TabOrderListEnum.INVOICED]: tabCounts?.invoiced ?? 0,
|
||||||
|
}),
|
||||||
|
[tabCounts],
|
||||||
|
);
|
||||||
|
const tabsWithCount = useMemo(
|
||||||
|
() =>
|
||||||
|
orderListTabs.map((tab) => {
|
||||||
|
const total = tabCountByTab[tab.value as TabOrderListEnum] ?? 0;
|
||||||
|
return {
|
||||||
|
...tab,
|
||||||
|
label: total > 0 ? `${tab.label} (${total.toLocaleString("fa-IR")})` : tab.label,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
[tabCountByTab],
|
||||||
|
);
|
||||||
|
|
||||||
const handleDelete = useCallback(
|
const handleDelete = useCallback(
|
||||||
(id: string) => {
|
(id: string) => {
|
||||||
@@ -126,7 +155,7 @@ const OrdersList: FC = () => {
|
|||||||
|
|
||||||
<Tabs
|
<Tabs
|
||||||
activeTab={params.tab}
|
activeTab={params.tab}
|
||||||
items={[...orderListTabs]}
|
items={tabsWithCount}
|
||||||
onTabChange={(tab) => setTab(tab as TabOrderListEnum)}
|
onTabChange={(tab) => setTab(tab as TabOrderListEnum)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ export const useGetOrders = (params?: api.GetOrdersParams) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useGetOrderTabCounts = (params?: api.GetOrderTabCountsParams) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["orders-tab-counts", params],
|
||||||
|
queryFn: () => api.getOrderTabCounts(params),
|
||||||
|
refetchInterval: 60_000,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const useGetOrdersInvoiced = (page: number = 1) => {
|
export const useGetOrdersInvoiced = (page: number = 1) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["orders-invoiced", page],
|
queryKey: ["orders-invoiced", page],
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import type {
|
|||||||
TicketsResponseType,
|
TicketsResponseType,
|
||||||
UpdateOrderType,
|
UpdateOrderType,
|
||||||
} from "../types/Types";
|
} from "../types/Types";
|
||||||
|
import type { BaseResponse } from "@/shared/types/Types";
|
||||||
import type {
|
import type {
|
||||||
FieldResponseType,
|
FieldResponseType,
|
||||||
ProductResponeType,
|
ProductResponeType,
|
||||||
@@ -27,6 +28,15 @@ export type GetOrdersParams = {
|
|||||||
statuses?: OrderStatusEnum[];
|
statuses?: OrderStatusEnum[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type GetOrderTabCountsParams = Omit<GetOrdersParams, "statuses">;
|
||||||
|
|
||||||
|
export type OrderTabCountsResponseType = {
|
||||||
|
inProgress: number;
|
||||||
|
finished: number;
|
||||||
|
canceled: number;
|
||||||
|
invoiced: number;
|
||||||
|
};
|
||||||
|
|
||||||
const cleanParams = (params?: GetOrdersParams) => {
|
const cleanParams = (params?: GetOrdersParams) => {
|
||||||
if (!params) return undefined;
|
if (!params) return undefined;
|
||||||
const { designId, statuses, ...rest } = params;
|
const { designId, statuses, ...rest } = params;
|
||||||
@@ -57,6 +67,17 @@ export const getOrders = async (params?: GetOrdersParams) => {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getOrderTabCounts = async (params?: GetOrderTabCountsParams) => {
|
||||||
|
const query = cleanParams(params);
|
||||||
|
const { data } = await axios.get<BaseResponse<OrderTabCountsResponseType>>(
|
||||||
|
`/admin/orders/tab-counts`,
|
||||||
|
{
|
||||||
|
params: query,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return data.data;
|
||||||
|
};
|
||||||
|
|
||||||
export const getOrdersInvoiced = async (page: number = 1) => {
|
export const getOrdersInvoiced = async (page: number = 1) => {
|
||||||
const { data } = await axios.get<OrderListResponseType>(
|
const { data } = await axios.get<OrderListResponseType>(
|
||||||
`/admin/orders/invoiced?page=${page}`,
|
`/admin/orders/invoiced?page=${page}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user