Implemented logic to edit domain redirects

This commit is contained in:
Alejandro Celaya
2021-08-21 17:53:06 +02:00
parent bf29158a8a
commit 69cb3bd619
28 changed files with 347 additions and 141 deletions

View File

@@ -16,6 +16,8 @@ import {
ShlinkDomain,
ShlinkDomainsResponse,
ShlinkVisitsOverview,
ShlinkEditDomainRedirects,
ShlinkDomainRedirects,
} from '../types';
const buildShlinkBaseUrl = (url: string, apiVersion: number) => url ? `${url}/rest/v${apiVersion}` : '';
@@ -108,6 +110,11 @@ export default class ShlinkApiClient {
public readonly listDomains = async (): Promise<ShlinkDomain[]> =>
this.performRequest<{ domains: ShlinkDomainsResponse }>('/domains', 'GET').then(({ data }) => data.domains.data);
public readonly editDomainRedirects = async (
domainRedirects: ShlinkEditDomainRedirects,
): Promise<ShlinkDomainRedirects> =>
this.performRequest<ShlinkDomainRedirects>('/domains/redirects', 'PATCH', {}, domainRedirects).then(({ data }) => data);
private readonly performRequest = async <T>(url: string, method: Method = 'GET', query = {}, body = {}): Promise<AxiosResponse<T>> => {
try {
return await this.axios({

6
src/api/types/actions.ts Normal file
View File

@@ -0,0 +1,6 @@
import { Action } from 'redux';
import { ProblemDetailsError } from './index';
export interface ApiErrorAction extends Action<string> {
errorData?: ProblemDetailsError;
}

View File

@@ -65,10 +65,14 @@ export interface ShlinkShortUrlData extends ShortUrlMeta {
tags?: string[];
}
interface ShlinkDomainRedirects {
baseUrlRedirect: string,
regular404Redirect: string,
invalidShortUrlRedirect: string
export interface ShlinkDomainRedirects {
baseUrlRedirect: string | null;
regular404Redirect: string | null;
invalidShortUrlRedirect: string | null;
}
export interface ShlinkEditDomainRedirects extends Partial<ShlinkDomainRedirects> {
domain: string;
}
export interface ShlinkDomain {