Skip to content

Commit

Permalink
chore: migrate tanstack query to v5
Browse files Browse the repository at this point in the history
  • Loading branch information
heryTz committed Sep 12, 2024
1 parent 0f3e4dd commit 393d899
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 115 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
"@tanstack/react-query": "^5.56.0",
"@tanstack/react-table": "^8.20.1",
"@tippyjs/react": "^4.2.6",
"@types/node": "20.5.0",
Expand All @@ -57,7 +58,6 @@
"react-hook-form": "^7.49.2",
"react-i18next": "^15.0.1",
"react-modal": "^3.16.1",
"react-query": "^3.39.3",
"recharts": "2.13.0-alpha.4",
"sonner": "^1.5.0",
"tailwind-merge": "^2.4.0",
Expand Down
110 changes: 18 additions & 92 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app/(dashboard)/invoice/(index)/invoice-query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { httpClient } from "@/lib/http-client";
import { useQuery } from "react-query";
import { useQuery } from "@tanstack/react-query";
import { GetInvoiceById } from "./invoice-service";

export function useGetInvoiceById(id: string | null) {
Expand Down
10 changes: 6 additions & 4 deletions src/app/(dashboard)/invoice/client/client-query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { httpClient } from "@/lib/http-client";
import { Client } from "@prisma/client";
import { useQuery } from "react-query";
import { useQuery } from "@tanstack/react-query";
import { GetClients } from "./client-service";

export function useGetClientById(id?: string | null) {
Expand All @@ -12,7 +12,9 @@ export function useGetClientById(id?: string | null) {
}

export function useGetClients() {
return useQuery(useGetClients.name, () =>
httpClient.get<GetClients>("/invoice/client").then((res) => res.data),
);
return useQuery({
queryKey: [useGetClients.name],
queryFn: () =>
httpClient.get<GetClients>("/invoice/client").then((res) => res.data),
});
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { httpClient } from "@/lib/http-client";
import { useQuery } from "react-query";
import { useQuery } from "@tanstack/react-query";
import type {
GetPaymentModeById,
GetPaymentsMode,
Expand Down
10 changes: 6 additions & 4 deletions src/app/(dashboard)/invoice/provider/provider-query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { httpClient } from "@/lib/http-client";
import { useQuery } from "react-query";
import { useQuery } from "@tanstack/react-query";
import type { GetProviderById, GetProviders } from "./provider-service";

export function useGetProviderById(id?: string) {
Expand All @@ -14,7 +14,9 @@ export function useGetProviderById(id?: string) {
}

export function useGetProviders() {
return useQuery([useGetProviders.name], () =>
httpClient.get<GetProviders>("/invoice/provider").then((res) => res.data),
);
return useQuery({
queryKey: [useGetProviders.name],
queryFn: () =>
httpClient.get<GetProviders>("/invoice/provider").then((res) => res.data),
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Button } from "@/components/ui/button";
import { MoreHorizontalIcon } from "lucide-react";
import { useState } from "react";
import { OperationSave } from "./operation-save";
import { useQueryClient } from "react-query";
import { useQueryClient } from "@tanstack/react-query";
import { useGetOperations } from "../operation-query";
import { ModalDelete } from "@/components/modal-delete";
import { deleteOperationAction } from "../operation-action";
Expand Down
19 changes: 11 additions & 8 deletions src/app/(dashboard)/operation/operation-query.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { httpClient } from "@/lib/http-client";
import { useQuery } from "react-query";
import { useQuery } from "@tanstack/react-query";
import type { GetOperationQuery } from "./operation-dto";
import type { GetOperationById, GetOperations } from "./operation-service";

export function useGetOperations({ q, distinct }: GetOperationQuery = {}) {
return useQuery([useGetOperations.name, q, distinct], ({ queryKey }) => {
const [_, q, distinct] = queryKey;
return httpClient
.get<GetOperations>(`/operations`, {
params: { q, distinct },
})
.then((resp) => resp.data);
return useQuery({
queryKey: [useGetOperations.name, q, distinct],
queryFn: ({ queryKey }) => {
const [_, q, distinct] = queryKey;
return httpClient
.get<GetOperations>(`/operations`, {
params: { q, distinct },
})
.then((resp) => resp.data);
},
});
}

Expand Down
Loading

0 comments on commit 393d899

Please sign in to comment.