diff --git a/.eslintrc b/.eslintrc index 619f69857..990ea66d9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,7 +8,8 @@ "standard", "prettier", "plugin:@typescript-eslint/recommended", - "plugin:react/recommended" + "plugin:react/recommended", + "plugin:@tanstack/eslint-plugin-query/recommended" ], "plugins": ["@typescript-eslint"], "env": { diff --git a/client/package.json b/client/package.json index df889a17a..2617042d9 100644 --- a/client/package.json +++ b/client/package.json @@ -14,6 +14,7 @@ "@mui/material": "^5.14.2", "@mui/system": "^5.14.1", "@mui/x-date-pickers": "^6.10.2", + "@tanstack/react-query": "^5.26.3", "@types/react-dom": "^18.2.18", "@types/stripe": "^8.0.417", "@vitejs/plugin-react": "^4.2.1", diff --git a/client/src/App.tsx b/client/src/App.tsx index 497779dbe..d26ce2efa 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -16,40 +16,44 @@ import { BrowserRouter as Router, Route, Routes } from "react-router-dom" import { ThemeProvider } from "@mui/material" import { LocalizationProvider } from "@mui/x-date-pickers" import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs" +import queryClient from "services/QueryClient" import theme from "theme" +import { QueryClientProvider } from "@tanstack/react-query" function App() { return ( - -
- - -
- -
- - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } - /> - + + +
+ + +
+ +
+ + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } + /> + +
-
- - -
- + + +
+ + ) } diff --git a/client/src/services/FetchClient.ts b/client/src/services/FetchClient.ts deleted file mode 100644 index 8d8947aa9..000000000 --- a/client/src/services/FetchClient.ts +++ /dev/null @@ -1,23 +0,0 @@ -import createClient, { Middleware } from "openapi-fetch" -import type { paths } from "models/__generated__/schema" - -let accessToken: string | undefined - -const authMiddleware: Middleware = { - async onRequest(req) { - // TODO: Handle Auth - if (!accessToken) { - accessToken = "placeholder" - } - req.headers.set("Authorization", `Bearer ${accessToken}`) - return req - } -} - -const fetchClient = createClient({ - baseUrl: import.meta.env.VITE_BACKEND_BASE_URL -}) - -fetchClient.use(authMiddleware) - -export default fetchClient diff --git a/client/src/services/UserService.ts b/client/src/services/UserService.ts index bfc8e1f91..b777b711a 100644 --- a/client/src/services/UserService.ts +++ b/client/src/services/UserService.ts @@ -1,16 +1,10 @@ -import fetchClient from "./FetchClient" +import fetchClient from "./OpenApiFetchClient" const UserService = { getUsers: async function () { - const res = await fetchClient.GET("/users/{userId}", { - params: { - path: { - userId: 1232 - } - } - }) - return res.data + const { data } = await fetchClient.GET("/users", {}) + return data } -} +} as const export default UserService diff --git a/client/src/store/store.ts b/client/src/store/store.ts index 785c9ee5a..d38c8718a 100644 --- a/client/src/store/store.ts +++ b/client/src/store/store.ts @@ -5,18 +5,16 @@ import { createHook } from "react-sweet-state" -type State = { userData: number } +type State = { current: number } const initialState: State = { - userData: 1000 + current: 1000 } const actions = { - loadUsers: + loadInfo: (): Action => - async ({ setState }) => { - setState({}) - } + async ({ setState }) => {} } type Actions = typeof actions diff --git a/package.json b/package.json index 790410ae3..52095314c 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "server" ], "devDependencies": { + "@tanstack/eslint-plugin-query": "^5.20.1", "@types/jest": "^29.5.12", "@types/node": "^20.11.23", "@typescript-eslint/eslint-plugin": "^7.1.0", diff --git a/yarn.lock b/yarn.lock index 855ccf56d..2d2ed6dcc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3803,6 +3803,25 @@ "@types/express" "^4.7.0" file-system-cache "2.3.0" +"@tanstack/eslint-plugin-query@^5.20.1": + version "5.20.1" + resolved "https://registry.yarnpkg.com/@tanstack/eslint-plugin-query/-/eslint-plugin-query-5.20.1.tgz#861afedd7cde6b98c88cf86a5923bb659122e7af" + integrity sha512-oIp7Wh90KHOm1FKCvcv87fiD2H96xo/crFrlhbvqBzR2f0tMEGOK/ANKMGNFQprd6BT6lyZhQPlOEkFdezsjIg== + dependencies: + "@typescript-eslint/utils" "^6.20.0" + +"@tanstack/query-core@5.26.3": + version "5.26.3" + resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.26.3.tgz#0e1075de03904165d892e2b801b49f21d6a88b66" + integrity sha512-kKv7VHIleC7cwpMS3M63mWUFFbdiRo7JZMVUyZ4z/79RZoAi7/vGTVkCrnNqyKl+zwBRkumYL+eiYtyShGZd0A== + +"@tanstack/react-query@^5.26.3": + version "5.26.3" + resolved "https://registry.yarnpkg.com/@tanstack/react-query/-/react-query-5.26.3.tgz#263bc60ee0b80a95773a0b9872030ccf07edb2a0" + integrity sha512-fP/kEu8aVLb6ln0ySazaeyivVkSQ9EnFfA5kQ7yIQNklx5JCW7otHVY6GVjZtd/3wK6QU99yvdSH0rN0LV2vmA== + dependencies: + "@tanstack/query-core" "5.26.3" + "@testing-library/dom@^9.3.1": version "9.3.4" resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-9.3.4.tgz#50696ec28376926fec0a1bf87d9dbac5e27f60ce" @@ -4470,6 +4489,14 @@ "@typescript-eslint/visitor-keys" "7.1.0" debug "^4.3.4" +"@typescript-eslint/scope-manager@6.21.0": + version "6.21.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.21.0.tgz#ea8a9bfc8f1504a6ac5d59a6df308d3a0630a2b1" + integrity sha512-OwLUIWZJry80O99zvqXVEioyniJMa+d2GrqpUTqi5/v5D5rOrppJVBPa0yKCblcigC0/aYAzxxqQ1B+DS2RYsg== + dependencies: + "@typescript-eslint/types" "6.21.0" + "@typescript-eslint/visitor-keys" "6.21.0" + "@typescript-eslint/scope-manager@7.1.0": version "7.1.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.1.0.tgz#e4babaa39a3d612eff0e3559f3e99c720a2b4a54" @@ -4488,11 +4515,30 @@ debug "^4.3.4" ts-api-utils "^1.0.1" +"@typescript-eslint/types@6.21.0": + version "6.21.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.21.0.tgz#205724c5123a8fef7ecd195075fa6e85bac3436d" + integrity sha512-1kFmZ1rOm5epu9NZEZm1kckCDGj5UJEf7P1kliH4LKu/RkwpsfqqGmY2OOcUs18lSlQBKLDYBOGxRVtrMN5lpg== + "@typescript-eslint/types@7.1.0": version "7.1.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.1.0.tgz#52a86d6236fda646e7e5fe61154991dc0dc433ef" integrity sha512-qTWjWieJ1tRJkxgZYXx6WUYtWlBc48YRxgY2JN1aGeVpkhmnopq+SUC8UEVGNXIvWH7XyuTjwALfG6bFEgCkQA== +"@typescript-eslint/typescript-estree@6.21.0": + version "6.21.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.21.0.tgz#c47ae7901db3b8bddc3ecd73daff2d0895688c46" + integrity sha512-6npJTkZcO+y2/kr+z0hc4HwNfrrP4kNYh57ek7yCNlrBjWQ1Y0OS7jiZTkgumrvkX5HkEKXFZkkdFNkaW2wmUQ== + dependencies: + "@typescript-eslint/types" "6.21.0" + "@typescript-eslint/visitor-keys" "6.21.0" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + minimatch "9.0.3" + semver "^7.5.4" + ts-api-utils "^1.0.1" + "@typescript-eslint/typescript-estree@7.1.0": version "7.1.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.1.0.tgz#419b1310f061feee6df676c5bed460537310c593" @@ -4520,6 +4566,27 @@ "@typescript-eslint/typescript-estree" "7.1.0" semver "^7.5.4" +"@typescript-eslint/utils@^6.20.0": + version "6.21.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.21.0.tgz#4714e7a6b39e773c1c8e97ec587f520840cd8134" + integrity sha512-NfWVaC8HP9T8cbKQxHcsJBY5YE1O33+jpMwN45qzWWaPDZgLIbo12toGMWnmhvCpd3sIxkpDw3Wv1B3dYrbDQQ== + dependencies: + "@eslint-community/eslint-utils" "^4.4.0" + "@types/json-schema" "^7.0.12" + "@types/semver" "^7.5.0" + "@typescript-eslint/scope-manager" "6.21.0" + "@typescript-eslint/types" "6.21.0" + "@typescript-eslint/typescript-estree" "6.21.0" + semver "^7.5.4" + +"@typescript-eslint/visitor-keys@6.21.0": + version "6.21.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.21.0.tgz#87a99d077aa507e20e238b11d56cc26ade45fe47" + integrity sha512-JJtkDduxLi9bivAB+cYOVMtbkqdPOhZ+ZI5LC47MIRrDV4Yn2o+ZnW10Nkmr28xRpSpdJ6Sm42Hjf2+REYXm0A== + dependencies: + "@typescript-eslint/types" "6.21.0" + eslint-visitor-keys "^3.4.1" + "@typescript-eslint/visitor-keys@7.1.0": version "7.1.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.1.0.tgz#576c4ad462ca1378135a55e2857d7aced96ce0a0"