mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 20:59:16 +00:00
feat: started whatsapp modal queue selection
This commit is contained in:
@@ -13,10 +13,6 @@ import DialogActions from "@material-ui/core/DialogActions";
|
|||||||
import DialogContent from "@material-ui/core/DialogContent";
|
import DialogContent from "@material-ui/core/DialogContent";
|
||||||
import DialogTitle from "@material-ui/core/DialogTitle";
|
import DialogTitle from "@material-ui/core/DialogTitle";
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
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";
|
import { i18n } from "../../translate/i18n";
|
||||||
|
|
||||||
@@ -120,7 +116,13 @@ const QueueModal = ({ open, onClose, queueId }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<Dialog open={open} onClose={handleClose} maxWidth="lg" scroll="paper">
|
<Dialog
|
||||||
|
open={open}
|
||||||
|
onClose={handleClose}
|
||||||
|
maxWidth="sm"
|
||||||
|
fullWidth
|
||||||
|
scroll="paper"
|
||||||
|
>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
{queueId
|
{queueId
|
||||||
? `${i18n.t("queueModal.title.edit")}`
|
? `${i18n.t("queueModal.title.edit")}`
|
||||||
|
|||||||
91
frontend/src/components/QueueSelector/index.js
Normal file
91
frontend/src/components/QueueSelector/index.js
Normal file
@@ -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 (
|
||||||
|
<div style={{ marginTop: 6 }}>
|
||||||
|
<FormControl fullWidth variant="outlined">
|
||||||
|
<InputLabel>Filas</InputLabel>
|
||||||
|
<Select
|
||||||
|
multiple
|
||||||
|
value={selectedQueueIds}
|
||||||
|
onChange={handleChange}
|
||||||
|
input={<OutlinedInput label="Filas" id="select-multiple-chip" />}
|
||||||
|
MenuProps={{
|
||||||
|
anchorOrigin: {
|
||||||
|
vertical: "bottom",
|
||||||
|
horizontal: "left",
|
||||||
|
},
|
||||||
|
transformOrigin: {
|
||||||
|
vertical: "top",
|
||||||
|
horizontal: "left",
|
||||||
|
},
|
||||||
|
getContentAnchorEl: null,
|
||||||
|
}}
|
||||||
|
renderValue={selected => (
|
||||||
|
<div className={classes.chips}>
|
||||||
|
{selected.length > 0 &&
|
||||||
|
selected.map(value => {
|
||||||
|
const queue = queues.find(q => q.id === value);
|
||||||
|
return queue ? (
|
||||||
|
<Chip
|
||||||
|
key={value}
|
||||||
|
style={{ backgroundColor: queue.color }}
|
||||||
|
variant="outlined"
|
||||||
|
label={queue.name}
|
||||||
|
className={classes.chip}
|
||||||
|
/>
|
||||||
|
) : null;
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{queues.map(queue => (
|
||||||
|
<MenuItem key={queue.id} value={queue.id}>
|
||||||
|
{queue.name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default QueueSelector;
|
||||||
@@ -22,15 +22,18 @@ import { i18n } from "../../translate/i18n";
|
|||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import toastError from "../../errors/toastError";
|
import toastError from "../../errors/toastError";
|
||||||
|
import QueueSelector from "../QueueSelector";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
root: {
|
root: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexWrap: "wrap",
|
flexWrap: "wrap",
|
||||||
},
|
},
|
||||||
textField: {
|
multFieldLine: {
|
||||||
|
display: "flex",
|
||||||
|
"& > *:not(:last-child)": {
|
||||||
marginRight: theme.spacing(1),
|
marginRight: theme.spacing(1),
|
||||||
flex: 1,
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
btnWrapper: {
|
btnWrapper: {
|
||||||
@@ -71,6 +74,7 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const [user, setUser] = useState(initialState);
|
const [user, setUser] = useState(initialState);
|
||||||
|
const [selectedQueueIds, setSelectedQueueIds] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUser = async () => {
|
const fetchUser = async () => {
|
||||||
@@ -80,6 +84,8 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
setUser(prevState => {
|
setUser(prevState => {
|
||||||
return { ...prevState, ...data };
|
return { ...prevState, ...data };
|
||||||
});
|
});
|
||||||
|
const userQueueIds = data.queues?.map(queue => queue.id);
|
||||||
|
setSelectedQueueIds(userQueueIds);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toastError(err);
|
toastError(err);
|
||||||
}
|
}
|
||||||
@@ -94,11 +100,12 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveUser = async values => {
|
const handleSaveUser = async values => {
|
||||||
|
const userData = { ...values, queueIds: selectedQueueIds };
|
||||||
try {
|
try {
|
||||||
if (userId) {
|
if (userId) {
|
||||||
await api.put(`/users/${userId}`, values);
|
await api.put(`/users/${userId}`, userData);
|
||||||
} else {
|
} else {
|
||||||
await api.post("/users", values);
|
await api.post("/users", userData);
|
||||||
}
|
}
|
||||||
toast.success(i18n.t("userModal.success"));
|
toast.success(i18n.t("userModal.success"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -109,7 +116,13 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<Dialog open={open} onClose={handleClose} maxWidth="lg" scroll="paper">
|
<Dialog
|
||||||
|
open={open}
|
||||||
|
onClose={handleClose}
|
||||||
|
maxWidth="xs"
|
||||||
|
fullWidth
|
||||||
|
scroll="paper"
|
||||||
|
>
|
||||||
<DialogTitle id="form-dialog-title">
|
<DialogTitle id="form-dialog-title">
|
||||||
{userId
|
{userId
|
||||||
? `${i18n.t("userModal.title.edit")}`
|
? `${i18n.t("userModal.title.edit")}`
|
||||||
@@ -129,6 +142,7 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
{({ touched, errors, isSubmitting }) => (
|
{({ touched, errors, isSubmitting }) => (
|
||||||
<Form>
|
<Form>
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
|
<div className={classes.multFieldLine}>
|
||||||
<Field
|
<Field
|
||||||
as={TextField}
|
as={TextField}
|
||||||
label={i18n.t("userModal.form.name")}
|
label={i18n.t("userModal.form.name")}
|
||||||
@@ -138,18 +152,8 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
helperText={touched.name && errors.name}
|
helperText={touched.name && errors.name}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
margin="dense"
|
margin="dense"
|
||||||
className={classes.textField}
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<Field
|
|
||||||
as={TextField}
|
|
||||||
label={i18n.t("userModal.form.email")}
|
|
||||||
name="email"
|
|
||||||
error={touched.email && Boolean(errors.email)}
|
|
||||||
helperText={touched.email && errors.email}
|
|
||||||
variant="outlined"
|
|
||||||
margin="dense"
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<Field
|
<Field
|
||||||
as={TextField}
|
as={TextField}
|
||||||
label={i18n.t("userModal.form.password")}
|
label={i18n.t("userModal.form.password")}
|
||||||
@@ -159,6 +163,19 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
helperText={touched.password && errors.password}
|
helperText={touched.password && errors.password}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
margin="dense"
|
margin="dense"
|
||||||
|
fullWidth
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className={classes.multFieldLine}>
|
||||||
|
<Field
|
||||||
|
as={TextField}
|
||||||
|
label={i18n.t("userModal.form.email")}
|
||||||
|
name="email"
|
||||||
|
error={touched.email && Boolean(errors.email)}
|
||||||
|
helperText={touched.email && errors.email}
|
||||||
|
variant="outlined"
|
||||||
|
margin="dense"
|
||||||
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<FormControl
|
<FormControl
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@@ -181,6 +198,10 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
</Field>
|
</Field>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</div>
|
</div>
|
||||||
|
<QueueSelector
|
||||||
|
selectedQueueIds={selectedQueueIds}
|
||||||
|
onChange={values => setSelectedQueueIds(values)}
|
||||||
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -21,19 +21,19 @@ import {
|
|||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import toastError from "../../errors/toastError";
|
import toastError from "../../errors/toastError";
|
||||||
|
import QueueSelector from "../QueueSelector";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
form: {
|
root: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
flexWrap: "wrap",
|
||||||
justifySelf: "center",
|
|
||||||
"& > *": {
|
|
||||||
margin: theme.spacing(1),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
textField: {
|
multFieldLine: {
|
||||||
flex: 1,
|
display: "flex",
|
||||||
|
"& > *:not(:last-child)": {
|
||||||
|
marginRight: theme.spacing(1),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
btnWrapper: {
|
btnWrapper: {
|
||||||
@@ -61,9 +61,11 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const initialState = {
|
const initialState = {
|
||||||
name: "",
|
name: "",
|
||||||
|
greetingMessage: "",
|
||||||
isDefault: false,
|
isDefault: false,
|
||||||
};
|
};
|
||||||
const [whatsApp, setWhatsApp] = useState(initialState);
|
const [whatsApp, setWhatsApp] = useState(initialState);
|
||||||
|
const [selectedQueueIds, setSelectedQueueIds] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchSession = async () => {
|
const fetchSession = async () => {
|
||||||
@@ -72,6 +74,9 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
try {
|
try {
|
||||||
const { data } = await api.get(`whatsapp/${whatsAppId}`);
|
const { data } = await api.get(`whatsapp/${whatsAppId}`);
|
||||||
setWhatsApp(data);
|
setWhatsApp(data);
|
||||||
|
|
||||||
|
const whatsQueueIds = data.whatsappQueues?.map(q => q.queue.id);
|
||||||
|
setSelectedQueueIds(whatsQueueIds);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toastError(err);
|
toastError(err);
|
||||||
}
|
}
|
||||||
@@ -80,14 +85,13 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
}, [whatsAppId]);
|
}, [whatsAppId]);
|
||||||
|
|
||||||
const handleSaveWhatsApp = async values => {
|
const handleSaveWhatsApp = async values => {
|
||||||
|
const whatsappData = { ...values, queueIds: selectedQueueIds };
|
||||||
|
console.log("SELECTED", whatsappData);
|
||||||
try {
|
try {
|
||||||
if (whatsAppId) {
|
if (whatsAppId) {
|
||||||
await api.put(`/whatsapp/${whatsAppId}`, {
|
await api.put(`/whatsapp/${whatsAppId}`, whatsappData);
|
||||||
name: values.name,
|
|
||||||
isDefault: values.isDefault,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
await api.post("/whatsapp", values);
|
await api.post("/whatsapp", whatsappData);
|
||||||
}
|
}
|
||||||
toast.success(i18n.t("whatsappModal.success"));
|
toast.success(i18n.t("whatsappModal.success"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -102,7 +106,14 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onClose={handleClose} maxWidth="lg" scroll="paper">
|
<div className={classes.root}>
|
||||||
|
<Dialog
|
||||||
|
open={open}
|
||||||
|
onClose={handleClose}
|
||||||
|
maxWidth="sm"
|
||||||
|
fullWidth
|
||||||
|
scroll="paper"
|
||||||
|
>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
{whatsAppId
|
{whatsAppId
|
||||||
? i18n.t("whatsappModal.title.edit")
|
? i18n.t("whatsappModal.title.edit")
|
||||||
@@ -121,7 +132,8 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
>
|
>
|
||||||
{({ values, touched, errors, isSubmitting }) => (
|
{({ values, touched, errors, isSubmitting }) => (
|
||||||
<Form>
|
<Form>
|
||||||
<DialogContent dividers className={classes.form}>
|
<DialogContent dividers>
|
||||||
|
<div className={classes.multFieldLine}>
|
||||||
<Field
|
<Field
|
||||||
as={TextField}
|
as={TextField}
|
||||||
label={i18n.t("whatsappModal.form.name")}
|
label={i18n.t("whatsappModal.form.name")}
|
||||||
@@ -144,6 +156,30 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
}
|
}
|
||||||
label={i18n.t("whatsappModal.form.default")}
|
label={i18n.t("whatsappModal.form.default")}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Field
|
||||||
|
as={TextField}
|
||||||
|
label={i18n.t("queueModal.form.greetingMessage")}
|
||||||
|
type="greetingMessage"
|
||||||
|
multiline
|
||||||
|
rows={5}
|
||||||
|
fullWidth
|
||||||
|
name="greetingMessage"
|
||||||
|
error={
|
||||||
|
touched.greetingMessage && Boolean(errors.greetingMessage)
|
||||||
|
}
|
||||||
|
helperText={
|
||||||
|
touched.greetingMessage && errors.greetingMessage
|
||||||
|
}
|
||||||
|
variant="outlined"
|
||||||
|
margin="dense"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<QueueSelector
|
||||||
|
selectedQueueIds={selectedQueueIds}
|
||||||
|
onChange={values => setSelectedQueueIds(values)}
|
||||||
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button
|
||||||
@@ -176,6 +212,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user