Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
feat(redux): add API query for `/api/queries/clients/overtime?formatt…
Browse files Browse the repository at this point in the history
…ed=true` using Redux Toolkit Query

  ## what
  - add API query for `/api/queries/clients/overtime?formatted=true` using Redux Toolkit Query
  - Query
    - GET `queries/clients/overtime?formatted=true`
      - fetch formatted data from NextJS API url `/api/queries/overtime?formatted=true`
  - export prebuilt React hook `useGetClientsOvertimeFormattedQuery`

  ## 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
  • Loading branch information
Clumsy-Coder committed Aug 20, 2023
1 parent c30384e commit 2b3a80d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/redux/Queries/Overtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IGetQueriesOvertimeFormatted } from '@pages/api/queries/overtime';
import { IOverTimeData10minutes } from '@utils/url/upstream.types';
import {
IGetClientsOvertimeResponseData as IGetClientsOvertimeRaw,
IGetClientsOvertimeFormatted,
} from '@pages/api/queries/clients/overtime';

const clientsApi = apiSlice.injectEndpoints({
Expand Down Expand Up @@ -32,6 +33,14 @@ const clientsApi = apiSlice.injectEndpoints({
}),
providesTags: () => [{ type: TagTypes.QUERY_CLIENTS_OVERTIME_RAW }],
}),
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
getClientsOvertimeFormatted: build.query<IGetClientsOvertimeFormatted, void>({
query: () => ({
url: `${getClientsOvertimeUrl}?formatted=true`,
method: HttpQueryType.GET,
}),
providesTags: () => [{ type: TagTypes.QUERY_CLIENTS_OVERTIME_FORMATTED }],
}),
}),
});

Expand All @@ -40,4 +49,5 @@ export const {
useGetQueriesOvertimeRawQuery,
useGetQueriesOvertimeFormattedQuery,
useGetClientsOvertimeRawQuery,
useGetClientsOvertimeFormattedQuery,
} = clientsApi;

0 comments on commit 2b3a80d

Please sign in to comment.