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 (
@@ -105,101 +72,134 @@ const AddContactModal = ({ modalOpen, setModalOpen, handleAddContact }) => { scroll="paper" className={classes.modal} > - Adicionar contato - - - Dados do contato - - - -
- -
- - Informações extras - - {extraInfo && - extraInfo.map((extra, index) => ( -
+ { + setTimeout(() => { + alert(JSON.stringify(values, null, 2)); + setSubmitting(false); + }, 400); + }} + > + {({ + values, + errors, + touched, + handleChange, + handleBlur, + handleSubmit, + isSubmitting, + }) => ( + <> + + Adicionar contato + + + + Dados do contato + handleChangeExtraInfoInput(e, extra.id)} + value={values.name} + onChange={handleChange} variant="outlined" margin="dense" required className={classes.textField} /> handleChangeExtraInfoInput(e, extra.id)} + label="Número do Whatsapp" + name="number" + value={values.number} + onChange={handleChange} + placeholder="Ex: 13912344321" variant="outlined" margin="dense" required /> - handleDeleteExtraInfo(extra.id, index)} +
+ +
+ - -
-
- ))} + Informações extras + -
- -
-
- - - - + + {({ push, remove }) => ( + <> + {values.extraInfo && + values.extraInfo.length > 0 && + values.extraInfo.map((info, index) => ( +
+ + + remove(index)} + > + + +
+ ))} +
+ +
+ + )} +
+ + + + + + + )} +
); diff --git a/frontend/src/pages/Contacts/ContactsList.js b/frontend/src/pages/Contacts/ContactsList.js index 3def2c5..358b6d9 100644 --- a/frontend/src/pages/Contacts/ContactsList.js +++ b/frontend/src/pages/Contacts/ContactsList.js @@ -15,6 +15,7 @@ import SearchIcon from "@material-ui/icons/Search"; import TextField from "@material-ui/core/TextField"; import Container from "@material-ui/core/Container"; import InputAdornment from "@material-ui/core/InputAdornment"; +import Typography from "@material-ui/core/Typography"; import IconButton from "@material-ui/core/IconButton"; import DeleteOutlineIcon from "@material-ui/icons/DeleteOutline"; @@ -128,7 +129,9 @@ const Contacts = () => { aria-labelledby="form-dialog-title" >
-

Todos os contatos

+ + Contatos +