diff --git a/src/app/components/ModalButtons.tsx b/src/app/components/ModalButtons.tsx new file mode 100755 index 0000000..a0672c9 --- /dev/null +++ b/src/app/components/ModalButtons.tsx @@ -0,0 +1,76 @@ +import React from 'react'; +import { Pressable, Text, View, StyleSheet } from 'react-native'; + +interface IErrors { + valor?: string; + } + +interface IModalButtonsProps { + onCancel: () => void; + onSave: () => void; + showErrors: boolean; + setShowErrors: (value: boolean) => void; + erros: IErrors; +} + +const ModalButtons: React.FC = ({ + onCancel, + onSave, + showErrors, + setShowErrors, + erros, +}) => { + return ( + + + Cancelar + + { + if (Object.keys(erros).length > 0) { + setShowErrors(true); + } else { + onSave(); + } + }} + > + Salvar + + + ); +}; + +const styles = StyleSheet.create({ + buttonContainer: { + flexDirection: "row", + justifyContent: "space-between", + marginTop: 20, + }, + button: { + borderRadius: 20, + padding: 10, + elevation: 2, + width: 100, + }, + buttonClose: { + backgroundColor: "#2CCDB5", + marginHorizontal: 15, + }, + buttonCancel: { + backgroundColor: "#FF7F7F", + marginHorizontal: 15, + }, + textStyle: { + color: "white", + fontWeight: "bold", + textAlign: "center", + }, +}); + +export default ModalButtons; diff --git a/src/app/components/ModalConfirmation.tsx b/src/app/components/ModalConfirmation.tsx index 1508301..4299911 100644 --- a/src/app/components/ModalConfirmation.tsx +++ b/src/app/components/ModalConfirmation.tsx @@ -3,11 +3,11 @@ import { Modal, StyleSheet, Text, Pressable, View } from "react-native"; interface IProps { visible: boolean; - callbackFn: () => void; // Atualizado para void - closeModal: () => void; // Atualizado para void + callbackFn: () => void; + closeModal: () => void; message: string; messageButton: string; - testID?: string; // Adicione esta linha para suportar o testID + testID?: string; } export default function ModalConfirmation({ @@ -16,7 +16,7 @@ export default function ModalConfirmation({ closeModal, message, messageButton, - testID, // Receba o testID + testID, }: Readonly) { return ( diff --git a/src/app/components/ModalMeta.tsx b/src/app/components/ModalMeta.tsx index 4a1e553..d8b2871 100644 --- a/src/app/components/ModalMeta.tsx +++ b/src/app/components/ModalMeta.tsx @@ -5,6 +5,7 @@ import { MaterialCommunityIcons } from "@expo/vector-icons"; import { TextInput } from "react-native-gesture-handler"; import ErrorMessage from "./ErrorMessage"; import { validateValue } from "../shared/helpers/modal.helper"; +import ModalButtons from "./ModalButtons"; interface IProps { visible: boolean; @@ -59,28 +60,13 @@ export default function ModalMeta({ - - closeModal()} - > - Cancelar - - { - if (Object.keys(erros).length > 0) { - setShowErrors(true); - } else { - callbackFn(valor); - } - }} - > - {"Salvar"} - - + callbackFn(valor)} + showErrors={showErrors} + setShowErrors={setShowErrors} + erros={erros} + /> @@ -127,34 +113,9 @@ const styles = StyleSheet.create({ 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", - }, }); diff --git a/src/app/components/ModalMetrica.tsx b/src/app/components/ModalMetrica.tsx index fb6f689..be311c4 100644 --- a/src/app/components/ModalMetrica.tsx +++ b/src/app/components/ModalMetrica.tsx @@ -7,6 +7,7 @@ import { FontAwesome, Entypo } from "@expo/vector-icons"; import { TextInput } from "react-native"; import ErrorMessage from "./ErrorMessage"; import { validateValue } from "../shared/helpers/modal.helper"; +import ModalButtons from "./ModalButtons"; interface IProps { visible: boolean; @@ -97,28 +98,13 @@ export default function ModalMetrica({ - - closeModal()} - > - Cancelar - - { - if (Object.keys(erros).length > 0) { - setShowErrors(true); - } else { - callbackFn(valor); - } - }} - > - {"Salvar"} - - + callbackFn(valor)} + showErrors={showErrors} + setShowErrors={setShowErrors} + erros={erros} + /> @@ -165,34 +151,9 @@ const styles = StyleSheet.create({ 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", - }, });