From d4bce8447350148c24a6ac0717d4d979d6fc0cfe Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
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<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>
-- 
cgit v1.2.3

