Skip to content

Commit

Permalink
refactor: replace postIdoso with salvarNoBancoLocal and switch to Toa…
Browse files Browse the repository at this point in the history
…stAndroid

Co-authored-by: Ugor Marcilio <https://github.com/ubrando>
  • Loading branch information
Natyrodrigues committed Aug 31, 2024
1 parent 9649dc8 commit 7e10395
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/app/private/pages/cadastrarIdoso.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,29 @@ export default function CadastrarIdoso() {
} catch (error) {
console.error("Erro ao salvar o idoso no banco local:", error);
}
};
};

const salvar = async () => {
if (Object.keys(erros).length > 0) {
setShowErrors(true);
return;
}

try {
setShowLoading(true);
await salvarNoBancoLocal();
ToastAndroid.show("Idoso salvo no banco local com sucesso!", ToastAndroid.SHORT);
router.replace("/private/pages/listarIdosos");
} catch (err) {
const error = err as { message: string };
ToastAndroid.show(`Erro: ${error.message}`, ToastAndroid.SHORT);
} finally {
setShowLoading(false);
}
};

useEffect(() => handleErrors(), [nome, telefoneResponsavel, dataNascimento]);

const metricas = [
{ key: EMetricas.FREQ_CARDIACA, value: EMetricas.FREQ_CARDIACA },
{ key: EMetricas.GLICEMIA, value: EMetricas.GLICEMIA },
Expand All @@ -160,28 +175,6 @@ export default function CadastrarIdoso() {
dataHora: new Date(),
};

try {
setShowLoading(true);
const response = await postIdoso(body, token);
Toast.show({
type: "success",
text1: "Sucesso!",
text2: response.message as string,
});
cadastrarMetricas(response.data?.id as number);
router.replace("private/pages/listarIdosos");
} catch (err) {
const error = err as { message: string };
Toast.show({
type: "error",
text1: "Erro!",
text2: error.message,
});
} finally {
setShowLoading(false);
}
};

const cadastrarMetricas = async (idIdoso: number) => {
for (const metrica of metricas) {
const body = {
Expand Down

0 comments on commit 7e10395

Please sign in to comment.