From 680a361906a8c1d14597f7552a9ad41d1520ab8c Mon Sep 17 00:00:00 2001 From: Clumsy-Coder <19594044+Clumsy-Coder@users.noreply.github.com> Date: Fri, 7 Oct 2022 19:09:01 -0600 Subject: [PATCH] feat(redux): add API query for `/api/queries/overtime` using Redux Toolkit Query ## what - add API query for `/api/queries/overtime` using Redux Toolkit Query - Query - GET queries/overtime - fetch data from NextJS API url `/api/queries/overtime` - export prebuilt React hook `useGetQueriesOvertimeRawQuery ` ## how - https://redux-toolkit.js.org/rtk-query/overview - https://redux-toolkit.js.org/rtk-query/usage/queries - https://redux-toolkit.js.org/rtk-query/usage/code-splitting ## why - Easy way to manage fetching data from API, etc - Less overhead to manage the code to handle these operations - most of the work is done for you ## where - ./src/redux/Queries/Overtime/index.ts ## usage --- src/redux/Queries/Overtime/index.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/redux/Queries/Overtime/index.ts diff --git a/src/redux/Queries/Overtime/index.ts b/src/redux/Queries/Overtime/index.ts new file mode 100644 index 00000000..d921ebb9 --- /dev/null +++ b/src/redux/Queries/Overtime/index.ts @@ -0,0 +1,19 @@ +import apiSlice, { TagTypes, HttpQueryType } from '@redux/apiSlice'; +import { getQueriesOvertimeUrl } from '@utils/url/api'; +import { IOverTimeData10minutes } from '@utils/url/upstream.types'; + +const clientsApi = apiSlice.injectEndpoints({ + endpoints: (build) => ({ + // eslint-disable-next-line @typescript-eslint/no-invalid-void-type + getQueriesOvertimeRaw: build.query({ + query: () => ({ + url: `${getQueriesOvertimeUrl}`, + method: HttpQueryType.GET, + }), + providesTags: () => [{ type: TagTypes.QUERY_OVERTIME_RAW }], + }), + }), +}); + +// eslint-disable-next-line import/prefer-default-export +export const { useGetQueriesOvertimeRawQuery } = clientsApi;