From d4bce8447350148c24a6ac0717d4d979d6fc0cfe Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 15 Jun 2021 10:28:46 -0300 Subject: add tooltips to the buttons --- .../frontend/src/components/form/InputTaxes.tsx | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'packages/frontend/src/components/form/InputTaxes.tsx') diff --git a/packages/frontend/src/components/form/InputTaxes.tsx b/packages/frontend/src/components/form/InputTaxes.tsx index af1dddd..91bbf85 100644 --- a/packages/frontend/src/components/form/InputTaxes.tsx +++ b/packages/frontend/src/components/form/InputTaxes.tsx @@ -38,18 +38,21 @@ export function InputTaxes({ name, readonly, label }: Props): VNode const { value: taxes, onChange, } = useField(name); const [value, valueHandler] = useState>({}) - const [errors, setErrors] = useState>({}) + // const [errors, setErrors] = useState>({}) + + let errors: FormErrors = {} + + 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 }), {}) + } + const hasErrors = Object.keys(errors).some(k => (errors as any)[k] !== undefined) const submit = useCallback((): void => { - try { - schema.validateSync(value, { abortEarly: false }) - onChange([value as any, ...taxes] as any) - valueHandler({}) - } catch (err) { - const errors = err.inner as yup.ValidationError[] - const pathMessages = errors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev, [cur.path]: cur.message }), {}) - setErrors(pathMessages) - } + onChange([value as any, ...taxes] as any) + valueHandler({}) }, [value]) const i18n = useTranslator() @@ -78,10 +81,13 @@ export function InputTaxes({ name, readonly, label }: Props): VNode currency and value separated with colon USD:2.3 - name="name" label={i18n`Name`} /> + name="name" label={i18n`Description`} />
- +
-- cgit v1.2.3