merchant-backoffice

ZZZ: Inactive/Deprecated
Log | Files | Refs | Submodules | README

commit ad62f32473f4b87840fa14c2a12c2257ee8414be
parent 30d06a1a2d53a51c01a99832868cd6b2055c5845
Author: Sebastian <sebasjm@gmail.com>
Date:   Mon, 29 Nov 2021 00:47:47 -0300

fix new typescript checks

Diffstat:
Mpackages/merchant-backoffice/package.json | 4++--
Mpackages/merchant-backoffice/src/components/form/InputTaxes.tsx | 6++++--
Mpackages/merchant-backoffice/src/components/product/NonInventoryProductForm.tsx | 6++++--
Mpackages/merchant-backoffice/src/components/product/ProductForm.tsx | 6++++--
Mpackages/merchant-backoffice/src/hooks/backend.ts | 11+++++++++--
Mpackages/merchant-backoffice/src/paths/admin/list/index.tsx | 4++--
Mpackages/merchant-backoffice/src/paths/instance/orders/list/Table.tsx | 11++++++++---
Mpackages/merchant-backoffice/src/paths/instance/reserves/list/AutorizeTipModal.tsx | 7+++++--
Mpackages/merchant-backoffice/src/paths/instance/reserves/list/index.tsx | 2+-
9 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/packages/merchant-backoffice/package.json b/packages/merchant-backoffice/package.json @@ -67,7 +67,7 @@ "@storybook/preset-scss": "^1.0.3", "@testing-library/preact": "^2.0.1", "@testing-library/preact-hooks": "^1.1.0", - "@types/enzyme": "^3.10.8", + "@types/enzyme": "^3.10.10", "@types/history": "^4.7.8", "@types/jest": "^26.0.23", "@types/mocha": "^8.2.2", @@ -84,7 +84,7 @@ "bulma-upload-control": "^1.2.0", "dotenv": "^8.2.0", "enzyme": "^3.11.0", - "enzyme-adapter-preact-pure": "^3.1.0", + "enzyme-adapter-preact-pure": "^3.2.0", "eslint": "^7.25.0", "eslint-config-preact": "^1.1.4", "eslint-plugin-header": "^3.1.1", diff --git a/packages/merchant-backoffice/src/components/form/InputTaxes.tsx b/packages/merchant-backoffice/src/components/form/InputTaxes.tsx @@ -45,8 +45,10 @@ export function InputTaxes<T>({ name, readonly, label }: Props<keyof T>): VNode try { schema.validateSync(value, { abortEarly: false }) } catch (err) { - const yupErrors = err.inner as yup.ValidationError[] - errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) + if (err instanceof yup.ValidationError) { + const yupErrors = err.inner as yup.ValidationError[] + errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) + } } const hasErrors = Object.keys(errors).some(k => (errors as any)[k] !== undefined) diff --git a/packages/merchant-backoffice/src/components/product/NonInventoryProductForm.tsx b/packages/merchant-backoffice/src/components/product/NonInventoryProductForm.tsx @@ -111,8 +111,10 @@ export function ProductForm({ onSubscribe, initial }: ProductProps): VNode { try { schema.validateSync(value, { abortEarly: false }) } catch (err) { - const yupErrors = err.inner as yup.ValidationError[] - errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) + if (err instanceof yup.ValidationError) { + const yupErrors = err.inner as yup.ValidationError[] + errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) + } } const submit = useCallback((): Entity | undefined => { diff --git a/packages/merchant-backoffice/src/components/product/ProductForm.tsx b/packages/merchant-backoffice/src/components/product/ProductForm.tsx @@ -65,8 +65,10 @@ export function ProductForm({ onSubscribe, initial, alreadyExist, }: Props) { try { (alreadyExist ? updateSchema : createSchema).validateSync(value, { abortEarly: false }) } catch (err) { - const yupErrors = err.inner as yup.ValidationError[] - errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) + if (err instanceof yup.ValidationError) { + const yupErrors = err.inner as yup.ValidationError[] + errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) + } } const hasErrors = Object.keys(errors).some(k => (errors as any)[k] !== undefined) diff --git a/packages/merchant-backoffice/src/hooks/backend.ts b/packages/merchant-backoffice/src/hooks/backend.ts @@ -201,6 +201,10 @@ export function setAxiosRequestAsTestingEnvironment() { removeAxiosCancelToken = true } +export function isAxiosError<T>(error: AxiosError | any): error is AxiosError<T> { + return error && error.isAxiosError +} + export async function request<T>(url: string, options: RequestOptions = {}): Promise<HttpResponseOk<T>> { const headers = options.token ? { Authorization: `Bearer ${options.token}` } : undefined @@ -217,8 +221,11 @@ export async function request<T>(url: string, options: RequestOptions = {}): Pro }) return buildRequestOk<T>(res, url, !!options.token) } catch (e) { - const error = buildRequestFailed(e, url, !!options.token) - throw error + if (isAxiosError<MerchantBackend.ErrorDetail>(e)) { + const error = buildRequestFailed(e, url, !!options.token) + throw error + } + throw e } } diff --git a/packages/merchant-backoffice/src/paths/admin/list/index.tsx b/packages/merchant-backoffice/src/paths/admin/list/index.tsx @@ -80,7 +80,7 @@ export default function Instances({ onUnauthorized, onLoadError, onNotFound, onC setNotif({ message: i18n`Failed to delete instance`, type: "ERROR", - description: error.message + description: error instanceof Error ? error.message : undefined }) // pushNotification({ message: 'delete_error', type: 'ERROR' }) } @@ -101,7 +101,7 @@ export default function Instances({ onUnauthorized, onLoadError, onNotFound, onC setNotif({ message: i18n`Failed to purge instance`, type: "ERROR", - description: error.message + description: error instanceof Error ? error.message : undefined }) } setPurging(null) diff --git a/packages/merchant-backoffice/src/paths/instance/orders/list/Table.tsx b/packages/merchant-backoffice/src/paths/instance/orders/list/Table.tsx @@ -34,6 +34,7 @@ import { RefundSchema } from "../../../../schemas"; import { mergeRefunds } from "../../../../utils/amount"; import { Amounts } from "@gnu-taler/taler-util"; import { useConfigContext } from "../../../../context/config"; +import * as yup from 'yup'; type Entity = MerchantBackend.Orders.OrderHistoryEntry & WithId interface Props { @@ -169,9 +170,13 @@ export function RefundModal({ order, onCancel, onConfirm }: RefundModalProps): V reason: `${form.mainReason}: ${form.description}` }) } catch (err) { - const errors = err.inner as any[] - const pathMessages = errors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) - setErrors(pathMessages) + if (err instanceof yup.ValidationError) { + const errors = err.inner as any[] + const pathMessages = errors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) + setErrors(pathMessages) + } else { + console.log(err) + } } } diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/list/AutorizeTipModal.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/list/AutorizeTipModal.tsx @@ -29,6 +29,7 @@ import { MerchantBackend } from "../../../../declaration"; import { useTranslator } from "../../../../i18n"; import { AuthorizeTipSchema } from "../../../../schemas"; import { CreatedSuccessfully } from "./CreatedSuccessfully"; +import * as yup from 'yup'; interface AuthorizeTipModalProps { onCancel: () => void; @@ -50,8 +51,10 @@ export function AuthorizeTipModal({ onCancel, onConfirm, tipAuthorized }: Author try { AuthorizeTipSchema.validateSync(form, { abortEarly: false }) } catch (err) { - const yupErrors = err.inner as any[] - errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) + if (err instanceof yup.ValidationError) { + const yupErrors = err.inner as any[] + errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) + } } const hasErrors = Object.keys(errors).some(k => (errors as any)[k] !== undefined) diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/list/index.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/list/index.tsx @@ -78,7 +78,7 @@ export default function ListTips({ onUnauthorized, onLoadError, onNotFound, onSe setNotif({ message: i18n`could not create the tip`, type: "ERROR", - description: error.message + description: error instanceof Error ? error.message : undefined }) setReserveForTip(undefined) }