diff --git a/src/components/UniversiForm/UniversiForm.tsx b/src/components/UniversiForm/UniversiForm.tsx index 0337100d..980a9de3 100644 --- a/src/components/UniversiForm/UniversiForm.tsx +++ b/src/components/UniversiForm/UniversiForm.tsx @@ -95,6 +95,8 @@ export function UniversiForm(props : formProps){ const [objects, setObjects] = useState(props.objects); const [canSave, setCanSave] = useState(false) + const [isSubmitting, setIsSubmitting] = useState(false) + const MAX_TEXT_LENGTH = 50 const MAX_LONG_TEXT_LENGTH = 150 const MAX_URL_LENGTH = 100 @@ -130,7 +132,7 @@ export function UniversiForm(props : formProps){ } if(obj.type == FormInputs.SELECT_SINGLE){ - obj.value = obj.value?.value + obj.value = obj.value?.value ?? obj.value } } @@ -546,17 +548,31 @@ export function UniversiForm(props : formProps){ }, {} as Record); }; - function makeRequest(){ - props.requisition(convertToDTO(objects)) - if(props.callback) - props.callback() + function handleCallback() { + try { + if(props.callback) + props.callback() + } catch { + } + setTimeout(() => { + setIsSubmitting(false); + }, 1000); + } + + async function makeRequest() { + try { + setIsSubmitting(true); + await props.requisition(convertToDTO(objects)); + } catch { + } + handleCallback(); } function handleCancel(){ if(props.cancelProps?.confirmCancel == undefined || props.cancelProps.confirmCancel == true) cancelPopup() else - props.callback() + handleCallback() } @@ -571,7 +587,7 @@ export function UniversiForm(props : formProps){ confirmButtonColor: props.cancelProps?.confirmButtonColor ?? "var(--wrong-invalid-color)" }).then(response =>{ if(response.isConfirmed){ - props.callback(); + handleCallback() } }) } @@ -595,7 +611,7 @@ export function UniversiForm(props : formProps){ Cancelar - diff --git a/src/components/UniversiForm/Validation/RequiredValidation.tsx b/src/components/UniversiForm/Validation/RequiredValidation.tsx index 79d46fb2..f5cd43da 100644 --- a/src/components/UniversiForm/Validation/RequiredValidation.tsx +++ b/src/components/UniversiForm/Validation/RequiredValidation.tsx @@ -6,7 +6,7 @@ export class RequiredValidation implements Validation { if(!object.required) return true - if (object.value === undefined) + if (object.value === undefined || object.value === null || object.value?.length === 0) return false; return true;