mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 04:39:20 +00:00
Merge pull request #58 from wirys/master
functionality to create ticket in contact implemented
This commit is contained in:
@@ -11,6 +11,7 @@ import Avatar from "@material-ui/core/Avatar";
|
|||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import Paper from "@material-ui/core/Paper";
|
import Paper from "@material-ui/core/Paper";
|
||||||
|
|
||||||
|
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import LinkifyWithTargetBlank from "../LinkifyWithTargetBlank";
|
import LinkifyWithTargetBlank from "../LinkifyWithTargetBlank";
|
||||||
import ContactModal from "../ContactModal";
|
import ContactModal from "../ContactModal";
|
||||||
@@ -18,6 +19,8 @@ import ContactDrawerSkeleton from "../ContactDrawerSkeleton";
|
|||||||
|
|
||||||
const drawerWidth = 320;
|
const drawerWidth = 320;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
drawer: {
|
drawer: {
|
||||||
width: drawerWidth,
|
width: drawerWidth,
|
||||||
@@ -148,6 +151,7 @@ const ContactDrawer = ({ open, handleDrawerClose, contact, loading }) => {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
className={classes.contactExtraInfo}
|
className={classes.contactExtraInfo}
|
||||||
>
|
>
|
||||||
|
|
||||||
<InputLabel>{info.name}</InputLabel>
|
<InputLabel>{info.name}</InputLabel>
|
||||||
<LinkifyWithTargetBlank>
|
<LinkifyWithTargetBlank>
|
||||||
<Typography noWrap style={{ paddingTop: 2 }}>
|
<Typography noWrap style={{ paddingTop: 2 }}>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import TableRow from "@material-ui/core/TableRow";
|
|||||||
import Paper from "@material-ui/core/Paper";
|
import Paper from "@material-ui/core/Paper";
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import Avatar from "@material-ui/core/Avatar";
|
import Avatar from "@material-ui/core/Avatar";
|
||||||
|
import WhatsAppIcon from "@material-ui/icons/WhatsApp";
|
||||||
import SearchIcon from "@material-ui/icons/Search";
|
import SearchIcon from "@material-ui/icons/Search";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
import InputAdornment from "@material-ui/core/InputAdornment";
|
import InputAdornment from "@material-ui/core/InputAdornment";
|
||||||
@@ -88,6 +88,7 @@ const useStyles = makeStyles(theme => ({
|
|||||||
const Contacts = () => {
|
const Contacts = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const userId = +localStorage.getItem("userId");
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [pageNumber, setPageNumber] = useState(1);
|
const [pageNumber, setPageNumber] = useState(1);
|
||||||
@@ -164,6 +165,33 @@ const Contacts = () => {
|
|||||||
setContactModalOpen(false);
|
setContactModalOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSaveTicket = async contactId => {
|
||||||
|
if (!contactId) return;
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const { data: ticket } = await api.post("/tickets", {
|
||||||
|
contactId: contactId,
|
||||||
|
userId: userId,
|
||||||
|
status: "open",
|
||||||
|
});
|
||||||
|
history.push(`/tickets/${ticket.id}`);
|
||||||
|
} catch (err) {
|
||||||
|
const errorMsg = err.response?.data?.error;
|
||||||
|
if (errorMsg) {
|
||||||
|
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
||||||
|
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
||||||
|
} else {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toast.error("Unknown error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const hadleEditContact = contactId => {
|
const hadleEditContact = contactId => {
|
||||||
setSelectedContactId(contactId);
|
setSelectedContactId(contactId);
|
||||||
setContactModalOpen(true);
|
setContactModalOpen(true);
|
||||||
@@ -308,11 +336,19 @@ const Contacts = () => {
|
|||||||
<TableCell>{contact.number}</TableCell>
|
<TableCell>{contact.number}</TableCell>
|
||||||
<TableCell>{contact.email}</TableCell>
|
<TableCell>{contact.email}</TableCell>
|
||||||
<TableCell align="right">
|
<TableCell align="right">
|
||||||
|
|
||||||
|
<IconButton size = "small"
|
||||||
|
onClick = {()=> handleSaveTicket(contact.id)}
|
||||||
|
>
|
||||||
|
<WhatsAppIcon/>
|
||||||
|
</IconButton>
|
||||||
|
|
||||||
<IconButton
|
<IconButton
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => hadleEditContact(contact.id)}
|
onClick={() => hadleEditContact(contact.id)}
|
||||||
>
|
>
|
||||||
<EditIcon />
|
|
||||||
|
<EditIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
<IconButton
|
<IconButton
|
||||||
|
|||||||
Reference in New Issue
Block a user