Skip to content

Commit

Permalink
Merge pull request #338 from universi-me/change#337/executar-corretam…
Browse files Browse the repository at this point in the history
…ente-callback-em-universiform
  • Loading branch information
julio-ufpb authored Dec 29, 2023
2 parents 32f8aa8 + a285b72 commit 13bc65c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
32 changes: 24 additions & 8 deletions src/components/UniversiForm/UniversiForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export function UniversiForm(props : formProps){

const [objects, setObjects] = useState<FormObject[]>(props.objects);
const [canSave, setCanSave] = useState<boolean>(false)
const [isSubmitting, setIsSubmitting] = useState(false)

const MAX_TEXT_LENGTH = 50
const MAX_LONG_TEXT_LENGTH = 150
const MAX_URL_LENGTH = 100
Expand Down Expand Up @@ -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
}

}
Expand Down Expand Up @@ -546,17 +548,31 @@ export function UniversiForm(props : formProps){
}, {} as Record<string, any>);
};

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()

}

Expand All @@ -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()
}
})
}
Expand All @@ -595,7 +611,7 @@ export function UniversiForm(props : formProps){
<i className="bi bi-x-circle-fill" />
Cancelar
</button>
<button type="button" className="submit-button" onClick={makeRequest} disabled={!canSave} title={canSave ? undefined : "Preencha os dados antes de salvar"}>
<button type="button" className="submit-button" onClick={makeRequest} disabled={isSubmitting || !canSave} title={canSave ? undefined : "Preencha os dados antes de salvar"}>
<i className="bi bi-check-circle-fill" />
Salvar
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class RequiredValidation implements Validation<any> {
if(!object.required)
return true

if (object.value === undefined)
if (object.value === undefined || object.value === null || object.value?.length === 0)
return false;

return true;
Expand Down

0 comments on commit 13bc65c

Please sign in to comment.