From a75eb49b31c83c63db3d69fb46006f0e103562b8 Mon Sep 17 00:00:00 2001 From: canove Date: Sun, 10 Jan 2021 20:01:05 -0300 Subject: [PATCH] feat: started whatsapp modal queue selection --- frontend/src/components/QueueModal/index.js | 12 +- .../src/components/QueueSelector/index.js | 91 ++++++++ frontend/src/components/UserModal/index.js | 75 ++++--- .../src/components/WhatsAppModal/index.js | 203 +++++++++++------- 4 files changed, 266 insertions(+), 115 deletions(-) create mode 100644 frontend/src/components/QueueSelector/index.js diff --git a/frontend/src/components/QueueModal/index.js b/frontend/src/components/QueueModal/index.js index 9261cb3..b083993 100644 --- a/frontend/src/components/QueueModal/index.js +++ b/frontend/src/components/QueueModal/index.js @@ -13,10 +13,6 @@ import DialogActions from "@material-ui/core/DialogActions"; import DialogContent from "@material-ui/core/DialogContent"; import DialogTitle from "@material-ui/core/DialogTitle"; import CircularProgress from "@material-ui/core/CircularProgress"; -import Select from "@material-ui/core/Select"; -import InputLabel from "@material-ui/core/InputLabel"; -import MenuItem from "@material-ui/core/MenuItem"; -import FormControl from "@material-ui/core/FormControl"; import { i18n } from "../../translate/i18n"; @@ -120,7 +116,13 @@ const QueueModal = ({ open, onClose, queueId }) => { return (
- + {queueId ? `${i18n.t("queueModal.title.edit")}` diff --git a/frontend/src/components/QueueSelector/index.js b/frontend/src/components/QueueSelector/index.js new file mode 100644 index 0000000..545131c --- /dev/null +++ b/frontend/src/components/QueueSelector/index.js @@ -0,0 +1,91 @@ +import React, { useEffect, useState } from "react"; +import { makeStyles } from "@material-ui/core/styles"; +import InputLabel from "@material-ui/core/InputLabel"; +import MenuItem from "@material-ui/core/MenuItem"; +import FormControl from "@material-ui/core/FormControl"; +import Select from "@material-ui/core/Select"; +import Chip from "@material-ui/core/Chip"; +import { OutlinedInput } from "@material-ui/core"; +import toastError from "../../errors/toastError"; +import api from "../../services/api"; + +const useStyles = makeStyles(theme => ({ + chips: { + display: "flex", + flexWrap: "wrap", + }, + chip: { + margin: 2, + }, +})); + +const QueueSelector = ({ selectedQueueIds, onChange }) => { + const classes = useStyles(); + // const [selectedQueues, setSelectedQueues] = useState([]); + const [queues, setQueues] = useState([]); + + useEffect(() => { + (async () => { + try { + const { data } = await api.get("/queue"); + setQueues(data); + } catch (err) { + toastError(err); + } + })(); + }, []); + + const handleChange = event => { + onChange(event.target.value); + }; + + return ( +
+ + Filas + + +
+ ); +}; + +export default QueueSelector; diff --git a/frontend/src/components/UserModal/index.js b/frontend/src/components/UserModal/index.js index dffdd6e..a01012c 100644 --- a/frontend/src/components/UserModal/index.js +++ b/frontend/src/components/UserModal/index.js @@ -22,15 +22,18 @@ import { i18n } from "../../translate/i18n"; import api from "../../services/api"; import toastError from "../../errors/toastError"; +import QueueSelector from "../QueueSelector"; const useStyles = makeStyles(theme => ({ root: { display: "flex", flexWrap: "wrap", }, - textField: { - marginRight: theme.spacing(1), - flex: 1, + multFieldLine: { + display: "flex", + "& > *:not(:last-child)": { + marginRight: theme.spacing(1), + }, }, btnWrapper: { @@ -71,6 +74,7 @@ const UserModal = ({ open, onClose, userId }) => { }; const [user, setUser] = useState(initialState); + const [selectedQueueIds, setSelectedQueueIds] = useState([]); useEffect(() => { const fetchUser = async () => { @@ -80,6 +84,8 @@ const UserModal = ({ open, onClose, userId }) => { setUser(prevState => { return { ...prevState, ...data }; }); + const userQueueIds = data.queues?.map(queue => queue.id); + setSelectedQueueIds(userQueueIds); } catch (err) { toastError(err); } @@ -94,11 +100,12 @@ const UserModal = ({ open, onClose, userId }) => { }; const handleSaveUser = async values => { + const userData = { ...values, queueIds: selectedQueueIds }; try { if (userId) { - await api.put(`/users/${userId}`, values); + await api.put(`/users/${userId}`, userData); } else { - await api.post("/users", values); + await api.post("/users", userData); } toast.success(i18n.t("userModal.success")); } catch (err) { @@ -109,7 +116,13 @@ const UserModal = ({ open, onClose, userId }) => { return (
- + {userId ? `${i18n.t("userModal.title.edit")}` @@ -129,27 +142,18 @@ const UserModal = ({ open, onClose, userId }) => { {({ touched, errors, isSubmitting }) => (
- - -
+
+ { helperText={touched.password && errors.password} variant="outlined" margin="dense" + fullWidth + /> +
+
+ {
+ setSelectedQueueIds(values)} + /> - - - - )} - -
+
+
+ +
+ setSelectedQueueIds(values)} + /> + + + + + + + )} + +
+
); };