mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-08-02 00:51:52 +00:00
Created component holding the logic to render Shlink API errors
This commit is contained in:
@@ -4,6 +4,7 @@ import { GetState } from '../../container/types';
|
||||
import { buildActionCreator, buildReducer } from '../../utils/helpers/redux';
|
||||
import { OptionalString } from '../../utils/utils';
|
||||
import { ShlinkApiClientBuilder } from '../../utils/services/ShlinkApiClientBuilder';
|
||||
import { ProblemDetailsError } from '../../utils/services/types';
|
||||
|
||||
/* eslint-disable padding-line-between-statements */
|
||||
export const EDIT_SHORT_URL_META_START = 'shlink/shortUrlMeta/EDIT_SHORT_URL_META_START';
|
||||
@@ -17,12 +18,17 @@ export interface ShortUrlMetaEdition {
|
||||
meta: ShortUrlMeta;
|
||||
saving: boolean;
|
||||
error: boolean;
|
||||
errorData?: ProblemDetailsError;
|
||||
}
|
||||
|
||||
export interface ShortUrlMetaEditedAction extends Action<string>, ShortUrlIdentifier {
|
||||
meta: ShortUrlMeta;
|
||||
}
|
||||
|
||||
export interface ShortUrlMetaEditionFailedAction extends Action<string> {
|
||||
errorData?: ProblemDetailsError;
|
||||
}
|
||||
|
||||
const initialState: ShortUrlMetaEdition = {
|
||||
shortCode: null,
|
||||
meta: {},
|
||||
@@ -30,9 +36,9 @@ const initialState: ShortUrlMetaEdition = {
|
||||
error: false,
|
||||
};
|
||||
|
||||
export default buildReducer<ShortUrlMetaEdition, ShortUrlMetaEditedAction>({
|
||||
export default buildReducer<ShortUrlMetaEdition, ShortUrlMetaEditedAction & ShortUrlMetaEditionFailedAction>({
|
||||
[EDIT_SHORT_URL_META_START]: (state) => ({ ...state, saving: true, error: false }),
|
||||
[EDIT_SHORT_URL_META_ERROR]: (state) => ({ ...state, saving: false, error: true }),
|
||||
[EDIT_SHORT_URL_META_ERROR]: (state, { errorData }) => ({ ...state, saving: false, error: true, errorData }),
|
||||
[SHORT_URL_META_EDITED]: (_, { shortCode, meta }) => ({ shortCode, meta, saving: false, error: false }),
|
||||
[RESET_EDIT_SHORT_URL_META]: () => initialState,
|
||||
}, initialState);
|
||||
@@ -49,7 +55,7 @@ export const editShortUrlMeta = (buildShlinkApiClient: ShlinkApiClientBuilder) =
|
||||
await updateShortUrlMeta(shortCode, domain, meta);
|
||||
dispatch<ShortUrlMetaEditedAction>({ shortCode, meta, domain, type: SHORT_URL_META_EDITED });
|
||||
} catch (e) {
|
||||
dispatch({ type: EDIT_SHORT_URL_META_ERROR });
|
||||
dispatch<ShortUrlMetaEditionFailedAction>({ type: EDIT_SHORT_URL_META_ERROR, errorData: e.response?.data });
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user