This commit is contained in:
felinae98
2022-10-07 00:57:12 +08:00
parent 469dc8877b
commit 89787a187d
10 changed files with 392 additions and 50 deletions
@@ -0,0 +1,15 @@
import { RootState, store } from '../../app/store';
import { baseUrl } from '../../utils/urls';
export default async function getTargetName(platformName: string, target: string) {
const url = `${baseUrl}target_name?platformName=${platformName}&target=${target}`;
const state = store.getState() as RootState;
const authToken = state.auth.token;
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${authToken}`,
},
});
const resObj = await res.json();
return resObj.targetName as string;
}
@@ -0,0 +1,14 @@
import { createApi } from '@reduxjs/toolkit/query/react';
import baseQueryWithAuth from '../auth/authQuery';
export const targetNameApi = createApi({
reducerPath: 'targetName',
baseQuery: baseQueryWithAuth,
endpoints: (builder) => ({
getTargetName: builder.query<{targetName: string}, {target: string; platformName: string}>({
query: () => '/target_name',
}),
}),
});
export const { useGetTargetNameQuery } = targetNameApi;