forked from fga-eps-mds/2023-2-GEROcuidado-Front
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#225) Adiciona metrica de hidratacao
- Loading branch information
1 parent
5d8ddc0
commit 0add917
Showing
9 changed files
with
373 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}>{message}</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", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.