43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
|
import { baseUrl } from "../config/baseUrl";
|
|
import { RootState } from "../config/store";
|
|
|
|
export type CreateQueueRequest = {
|
|
name: string;
|
|
description: string | null;
|
|
};
|
|
|
|
export type Queue = {
|
|
id: string;
|
|
name: string;
|
|
description: string | null;
|
|
};
|
|
|
|
export const QueueApi = createApi({
|
|
reducerPath: "QueueApi",
|
|
baseQuery: fetchBaseQuery({
|
|
baseUrl: `${baseUrl}/queue`,
|
|
prepareHeaders: (headers, { getState }) => {
|
|
const token = (getState() as RootState).auth.token;
|
|
if (token) {
|
|
headers.set("authorization", `Bearer ${token}`);
|
|
}
|
|
return headers;
|
|
},
|
|
}),
|
|
endpoints: (builder) => ({
|
|
getQueues: builder.query({
|
|
query: () => "/",
|
|
}),
|
|
createQueue: builder.mutation({
|
|
query: (data: CreateQueueRequest) => ({
|
|
url: "/",
|
|
method: "POST",
|
|
body: data,
|
|
}),
|
|
}),
|
|
}),
|
|
});
|
|
|
|
export const { useGetQueuesQuery, useCreateQueueMutation } = QueueApi;
|