mirror of
https://github.com/morbalint/kemkas.git
synced 2026-07-18 03:13:46 +00:00
refactor API calls and routers
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import * as React from "react";
|
||||
import axios from "axios";
|
||||
import {Container, Nav, Navbar} from "react-bootstrap";
|
||||
import {unsetUser, userSelector} from "./domain-models/userSlice";
|
||||
import {AppDispatch, RootState} from "../store";
|
||||
import {useDispatch, useSelector} from "react-redux";
|
||||
import {Link, useNavigate} from "react-router-dom";
|
||||
import {postVoid} from "./api/http";
|
||||
|
||||
function Header() {
|
||||
|
||||
@@ -13,7 +13,7 @@ function Header() {
|
||||
const fetchedUser = useSelector.withTypes<RootState>()(userSelector);
|
||||
|
||||
const logout = async () => {
|
||||
await axios.post("/Identity/Account/Logout")
|
||||
await postVoid("/Identity/Account/Logout")
|
||||
dispatch(unsetUser())
|
||||
navigate("/")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import axios, {AxiosRequestConfig} from "axios";
|
||||
|
||||
export const http = axios.create({
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
export async function getJson<T>(url: string, config?: AxiosRequestConfig): Promise<T> {
|
||||
const response = await http.get<T>(url, config)
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function getText(url: string, config?: AxiosRequestConfig): Promise<string> {
|
||||
const response = await http.get<string>(url, {
|
||||
...config,
|
||||
responseType: "text",
|
||||
})
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function postJson<TRequest, TResponse>(url: string, body: TRequest, config?: AxiosRequestConfig): Promise<TResponse> {
|
||||
const response = await http.post<TResponse>(url, body, config)
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function postVoid<TRequest = undefined>(url: string, body?: TRequest, config?: AxiosRequestConfig): Promise<void> {
|
||||
await http.post(url, body, config)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ interface CharacterListItemDto2E {
|
||||
edition: "2e"
|
||||
}
|
||||
|
||||
type CharacterListItemDto = CharacterListItemDto1E | CharacterListItemDto2E;
|
||||
export type CharacterListItemDto = CharacterListItemDto1E | CharacterListItemDto2E;
|
||||
|
||||
function mapDtoToViewModel(dto: CharacterListItemDto): CharacterListItemViewModel {
|
||||
if (dto.edition === "1e") {
|
||||
|
||||
Reference in New Issue
Block a user