diff --git a/frontend/package.json b/frontend/package.json index 99ce713..4916b2b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -13,6 +13,7 @@ "date-fns": "^2.14.0", "dotenv": "^8.2.0", "emoji-mart": "^3.0.0", + "formik": "^2.1.5", "mic-recorder-to-mp3": "^2.2.1", "qrcode.react": "^1.0.0", "react": "^16.13.1", @@ -21,6 +22,7 @@ "react-modal-image": "^2.5.0", "react-router-dom": "^5.2.0", "react-scripts": "3.4.1", + "shortid": "^2.2.15", "socket.io-client": "^2.3.0" }, "scripts": { diff --git a/frontend/src/pages/Contacts/ContactModal.js b/frontend/src/pages/Contacts/ContactModal.js index 46b975a..f70c4dd 100644 --- a/frontend/src/pages/Contacts/ContactModal.js +++ b/frontend/src/pages/Contacts/ContactModal.js @@ -1,11 +1,11 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; + +import { Formik, FieldArray } from "formik"; + import Button from "@material-ui/core/Button"; import TextField from "@material-ui/core/TextField"; import Dialog from "@material-ui/core/Dialog"; -import FormControl from "@material-ui/core/FormControl"; -import InputLabel from "@material-ui/core/InputLabel"; -import Input from "@material-ui/core/Input"; -import FormHelperText from "@material-ui/core/FormHelperText"; + import DialogActions from "@material-ui/core/DialogActions"; import DialogContent from "@material-ui/core/DialogContent"; import DialogTitle from "@material-ui/core/DialogTitle"; @@ -34,65 +34,32 @@ const useStyles = makeStyles(theme => ({ }, })); -const AddContactModal = ({ modalOpen, setModalOpen, handleAddContact }) => { +const AddContactModal = ({ + modalOpen, + setModalOpen, + handleAddContact, + contactId, +}) => { const classes = useStyles(); - const initialState = { name: "", number: "" }; - const [contact, setContact] = useState(initialState); - const [newInfo, setNewInfo] = useState({ - name: "", - value: "", - }); - const [extraInfo, setExtraInfo] = useState([ - { - id: "test1", - name: "Teste", - value: "testera", - }, - { - id: "test2", - name: "Mesh Agent URL", - value: "http://10.10.10.2", - }, - { - id: "test3", - name: "Atera Agent URL", - value: "http://10.10.10.5", - }, - ]); + const [contact, setContact] = useState({ + id: "", + name: "", + number: "", + email: "", + extraInfo: [ + { + id: "", + name: "", + value: "", + }, + ], + }); const handleClose = () => { setModalOpen(false); }; - const handleChangeInput = e => { - setContact({ ...contact, [e.target.name]: e.target.value }); - }; - - const handleChangeExtraInfoInput = (e, id) => { - setExtraInfo(prevState => { - const index = prevState.findIndex(ext => ext.id === id); - if (index === -1) return prevState; - let aux = [...prevState]; - aux[index] = { ...aux[index], [e.target.name]: e.target.value }; - return aux; - }); - }; - - console.log(extraInfo); - - const handleAddExtraInfo = () => { - setExtraInfo(prevState => [newInfo, ...extraInfo]); - }; - - const handleDeleteExtraInfo = (extraId, id) => { - setExtraInfo(prevState => { - const index = prevState.findIndex(ext => ext.id === id); - if (index === -1) return prevState; - let aux = [...prevState]; - aux.splice(index, 1); - return aux; - }); - }; + useEffect(() => {}, [contactId]); return (