summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/form/InputTaxes.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/frontend/src/components/form/InputTaxes.tsx')
-rw-r--r--packages/frontend/src/components/form/InputTaxes.tsx30
1 files changed, 18 insertions, 12 deletions
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<T>({ name, readonly, label }: Props<keyof T>): VNode
const { value: taxes, onChange, } = useField<T>(name);
const [value, valueHandler] = useState<Partial<Entity>>({})
- const [errors, setErrors] = useState<FormErrors<Entity>>({})
+ // const [errors, setErrors] = useState<FormErrors<Entity>>({})
+
+ let errors: FormErrors<Entity> = {}
+
+ 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<T>({ name, readonly, label }: Props<keyof T>): VNode
<Translate>currency and value separated with colon</Translate> <b>USD:2.3</b>
</Input>
- <Input<Entity> name="name" label={i18n`Name`} />
+ <Input<Entity> name="name" label={i18n`Description`} />
<div class="buttons is-right mt-5">
- <button class="button is-info" onClick={submit}><Translate>Add</Translate></button>
+ <button class="button is-info"
+ data-tooltip={i18n`add tax to the tax list`}
+ disabled={hasErrors}
+ onClick={submit}><Translate>Add</Translate></button>
</div>
</FormProvider>
</InputGroup>