Skip to content

Commit

Permalink
Merge pull request #54 from fga-eps-mds/hotfix/#225-CardMetrica-nao-a…
Browse files Browse the repository at this point in the history
…tualiza

[#225] visualização da última métrica cadastrada
  • Loading branch information
HenriqueAmorim20 authored Dec 13, 2023
2 parents f76de7c + 3266d25 commit d68530b
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 20 deletions.
9 changes: 9 additions & 0 deletions src/app/components/CardMetrica.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react";
import { View, Text, StyleSheet, ScrollView } from "react-native";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import FontAwesome from "react-native-vector-icons/FontAwesome";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import {
EMetricas,
IMetrica,
Expand Down Expand Up @@ -59,6 +60,9 @@ export default function CardMetrica({ item }: IProps) {
if (item.categoria == EMetricas.IMC) {
return "kg/m²";
}
if (item.categoria == EMetricas.HIDRATACAO) {
return "ml";
}
};

const icone = () => {
Expand Down Expand Up @@ -102,6 +106,11 @@ export default function CardMetrica({ item }: IProps) {
if (item.categoria == EMetricas.IMC) {
return <Entypo name="calculator" color={"#000"} size={25} />;
}
if (item.categoria == EMetricas.HIDRATACAO) {
return (
<MaterialCommunityIcons name="cup-water" color={"#1075c8"} size={25} />
);
}
};

const getMetricas = () => {
Expand Down
31 changes: 29 additions & 2 deletions src/app/components/CardValorMetrica.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { deleteMetricaValue } from "../services/metricaValue.service";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { router } from "expo-router";
import Toast from "react-native-toast-message";
import ModalConfirmation from "./ModalConfirmation";
import { MaterialCommunityIcons } from "@expo/vector-icons";

interface IProps {
item: IValorMetricaCategoria;
Expand All @@ -22,6 +24,7 @@ export default function CardValorMetrica({ item, metrica }: IProps) {
const [data, setData] = useState("");
const [hora, setHora] = useState("");
const [token, setToken] = useState<string>("");
const [modalVisible, setModalVisible] = useState(false);

const titleColor = "#000";
const textColor = "#888";
Expand Down Expand Up @@ -60,7 +63,11 @@ export default function CardValorMetrica({ item, metrica }: IProps) {
if (item.categoria == EMetricas.IMC) {
return "kg/m²";
}
if (item.categoria == EMetricas.HIDRATACAO) {
return "ml";
}
};

const separaDataHora = () => {
const dataHoraNum = new Date(item.dataHora).getTime();
const fuso = new Date(item.dataHora).getTimezoneOffset() * 60000;
Expand Down Expand Up @@ -113,9 +120,15 @@ export default function CardValorMetrica({ item, metrica }: IProps) {
if (item.categoria == EMetricas.IMC) {
return <Entypo name="calculator" color={"#000"} size={25} />;
}
if (item.categoria == EMetricas.HIDRATACAO) {
return (
<MaterialCommunityIcons name="cup-water" color={"#1075c8"} size={25} />
);
}
};

const apagarValor = async () => {
setModalVisible(false);
try {
await deleteMetricaValue(item.id, token);
router.replace({
Expand All @@ -130,10 +143,17 @@ export default function CardValorMetrica({ item, metrica }: IProps) {
text2: error.message,
});
} finally {

}
};

const confirmation = () => {
setModalVisible(!modalVisible);
};

const closeModal = () => {
setModalVisible(false);
};

useEffect(() => separaDataHora(), []);
useEffect(() => getToken(), []);

Expand All @@ -160,7 +180,14 @@ export default function CardValorMetrica({ item, metrica }: IProps) {
style={styles.apagar}
size={22}
color={"#FF7F7F"}
onPress={apagarValor}
onPress={confirmation}
/>
<ModalConfirmation
visible={modalVisible}
callbackFn={apagarValor}
closeModal={closeModal}
message={`Apagar registro ${item.categoria}?`}
messageButton="Apagar"
/>
<View style={styles.dataHora}>
<Text style={[styles.time, { color: textColor }]}>{data}</Text>
Expand Down
169 changes: 169 additions & 0 deletions src/app/components/ModalMeta.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import React, { useEffect, useState } from "react";
import { Modal, StyleSheet, Text, Pressable, View } from "react-native";
import { EMetricas, IMetrica } from "../interfaces/metricas.interface";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { TextInput } from "react-native-gesture-handler";
import ErrorMessage from "./ErrorMessage";
interface IProps {
visible: boolean;
callbackFn: (valor: string) => unknown;
closeModal: () => unknown;
message: string;
metrica: IMetrica;
}

interface IErrors {
valor?: string;
}

export default function ModalMeta({
visible,
callbackFn,
closeModal,
metrica,
message,
}: Readonly<IProps>) {
const [valor, setValor] = useState<string>("");
const [erros, setErros] = useState<IErrors>({});
const [showErrors, setShowErrors] = useState(false);

const handleErrors = () => {
const erros: IErrors = {};

if (!valor) {
erros.valor = "Campo obrigatório!";
setShowErrors(true);
} else if (!/^[0-9/.]+$/.test(valor)) {
erros.valor = "Formato inválido!";
setShowErrors(true);
}

setErros(erros);
};

useEffect(() => handleErrors(), [valor]);

return (
<Modal animationType="fade" transparent={true} visible={visible}>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<Text style={styles.modalText}>Adicionar uma nova meta</Text>
<View style={styles.modal}>
{metrica.categoria == EMetricas.HIDRATACAO && (
<MaterialCommunityIcons
name="cup-water"
color={"#1075c8"}
size={60}
/>
)}
<View style={styles.input}>
<TextInput
value={valor}
onChangeText={setValor}
style={styles.textInput}
placeholderTextColor={"#3D3D3D"}
/>
<View style={styles.erroValor}>
<ErrorMessage show={showErrors} text={erros.valor} />
</View>
</View>
</View>
<View style={styles.buttonContainer}>
<Pressable
testID="cancelarBtn"
style={[styles.button, styles.buttonCancel]}
onPress={() => closeModal()}
>
<Text style={styles.textStyle}>Cancelar</Text>
</Pressable>
<Pressable
testID="callbackBtn"
style={[styles.button, styles.buttonClose]}
onPress={() => {
if (Object.keys(erros).length > 0) {
setShowErrors(true);
} else {
callbackFn(valor);
}
}}
>
<Text style={styles.textStyle}>{"Salvar"}</Text>
</Pressable>
</View>
</View>
</View>
</Modal>
);
}

const styles = StyleSheet.create({
centeredView: {
flexDirection: "column",
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#00000098",
},
modal: {
flexDirection: "row",
marginBottom: 30,
},
erroValor: {
padding: 5,
},
input: {
flexDirection: "column",
alignItems: "center",
},
textInput: {
fontSize: 40,
width: 150,
marginLeft: 15,
textAlign: "center",
},
modalView: {
margin: 20,
backgroundColor: "white",
borderRadius: 20,
padding: 35,
alignItems: "center",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
},
button: {
borderRadius: 20,
padding: 10,
elevation: 2,
width: 100,
},
buttonOpen: {
backgroundColor: "#F194FF",
},
buttonClose: {
backgroundColor: "#2CCDB5",
marginHorizontal: 15,
},
buttonCancel: {
backgroundColor: "#FF7F7F",
marginHorizontal: 15,
},
textStyle: {
color: "white",
fontWeight: "bold",
textAlign: "center",
},
modalText: {
marginBottom: 35,
textAlign: "center",
fontWeight: "bold",
},
buttonContainer: {
flexDirection: "row",
},
});
13 changes: 9 additions & 4 deletions src/app/components/ModalMetrica.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React, { useEffect, useState } from "react";
import { Modal, StyleSheet, Text, Pressable, View } from "react-native";
import {
EMetricas,
IMetrica,
} from "../interfaces/metricas.interface";
import { EMetricas, IMetrica } from "../interfaces/metricas.interface";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { FontAwesome, Entypo } from "@expo/vector-icons";
import { TextInput } from "react-native-gesture-handler";
import ErrorMessage from "./ErrorMessage";
Expand Down Expand Up @@ -89,6 +87,13 @@ export default function ModalMetrica({
{metrica.categoria == EMetricas.IMC && (
<Entypo name="calculator" color={"#000"} size={60} />
)}
{metrica.categoria == EMetricas.HIDRATACAO && (
<MaterialCommunityIcons
name="cup-water"
color={"#1075c8"}
size={60}
/>
)}
<View style={styles.input}>
<TextInput
value={valor}
Expand Down
2 changes: 2 additions & 0 deletions src/app/interfaces/metricas.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ export enum EMetricas {
ALTURA = "Altura",
HORAS_DORMIDAS = "Horas Dormidas",
IMC = "IMC",
HIDRATACAO = "Hidratação",
}

export interface IMetricaBody {
idIdoso: number;
categoria: EMetricas;
valorMaximo?: string;
}
export interface IMetrica extends IMetricaBody {
id: number;
Expand Down
23 changes: 20 additions & 3 deletions src/app/private/pages/cadastrarIdoso.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default function CadastrarIdoso() {
{ key: EMetricas.ALTURA, value: EMetricas.ALTURA },
{ key: EMetricas.IMC, value: EMetricas.IMC },
{ key: EMetricas.HORAS_DORMIDAS, value: EMetricas.HORAS_DORMIDAS },
{ key: EMetricas.HIDRATACAO, value: EMetricas.HIDRATACAO },
];

const salvar = async () => {
Expand Down Expand Up @@ -115,6 +116,7 @@ export default function CadastrarIdoso() {
const body = {
idIdoso: Number(idIdoso),
categoria: metrica.value,
valorMaximo: "0",
};

try {
Expand Down Expand Up @@ -194,7 +196,12 @@ export default function CadastrarIdoso() {
placeholder="Nome"
style={styles.textInput}
/>
<Icon style={styles.requiredIcon} name="asterisk" size={10} color="red" />
<Icon
style={styles.requiredIcon}
name="asterisk"
size={10}
color="red"
/>
</View>
<View testID="Erro-nome">
<ErrorMessage show={showErrors} text={erros.nome} />
Expand All @@ -215,7 +222,12 @@ export default function CadastrarIdoso() {
mask={Masks.DATE_DDMMYYYY}
placeholder="Data de Nascimento"
/>
<Icon style={styles.requiredIcon} name="asterisk" size={10} color="red" />
<Icon
style={styles.requiredIcon}
name="asterisk"
size={10}
color="red"
/>
</View>
<View testID="Erro-data">
<ErrorMessage show={showErrors} text={erros.dataNascimento} />
Expand All @@ -235,7 +247,12 @@ export default function CadastrarIdoso() {
mask={Masks.BRL_PHONE}
placeholder="Telefone Responsável"
/>
<Icon style={styles.requiredIcon} name="asterisk" size={10} color="red" />
<Icon
style={styles.requiredIcon}
name="asterisk"
size={10}
color="red"
/>
</View>
<View testID="Erro-telefone">
<ErrorMessage show={showErrors} text={erros.telefoneResponsavel} />
Expand Down
Loading

0 comments on commit d68530b

Please sign in to comment.