From b0ef070921f02dfc7f2682c111f24a76debae365 Mon Sep 17 00:00:00 2001 From: wirys da cunha francisco Date: Wed, 28 Oct 2020 10:49:40 -0300 Subject: [PATCH 1/3] functionality to create ticket in contact implemented --- .../src/components/ContactDrawer/index.js | 4 ++ frontend/src/pages/Contacts/index.js | 40 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/ContactDrawer/index.js b/frontend/src/components/ContactDrawer/index.js index bb6dc9c..185d502 100644 --- a/frontend/src/components/ContactDrawer/index.js +++ b/frontend/src/components/ContactDrawer/index.js @@ -11,6 +11,7 @@ import Avatar from "@material-ui/core/Avatar"; import Button from "@material-ui/core/Button"; import Paper from "@material-ui/core/Paper"; + import { i18n } from "../../translate/i18n"; import LinkifyWithTargetBlank from "../LinkifyWithTargetBlank"; import ContactModal from "../ContactModal"; @@ -18,6 +19,8 @@ import ContactDrawerSkeleton from "../ContactDrawerSkeleton"; const drawerWidth = 320; + + const useStyles = makeStyles(theme => ({ drawer: { width: drawerWidth, @@ -148,6 +151,7 @@ const ContactDrawer = ({ open, handleDrawerClose, contact, loading }) => { variant="outlined" className={classes.contactExtraInfo} > + {info.name} diff --git a/frontend/src/pages/Contacts/index.js b/frontend/src/pages/Contacts/index.js index 95f1fcd..557d89e 100644 --- a/frontend/src/pages/Contacts/index.js +++ b/frontend/src/pages/Contacts/index.js @@ -12,7 +12,7 @@ import TableRow from "@material-ui/core/TableRow"; import Paper from "@material-ui/core/Paper"; import Button from "@material-ui/core/Button"; import Avatar from "@material-ui/core/Avatar"; - +import WhatsAppIcon from "@material-ui/icons/WhatsApp"; import SearchIcon from "@material-ui/icons/Search"; import TextField from "@material-ui/core/TextField"; import InputAdornment from "@material-ui/core/InputAdornment"; @@ -88,6 +88,7 @@ const useStyles = makeStyles(theme => ({ const Contacts = () => { const classes = useStyles(); const history = useHistory(); + const userId = +localStorage.getItem("userId"); const [loading, setLoading] = useState(false); const [pageNumber, setPageNumber] = useState(1); @@ -164,6 +165,33 @@ const Contacts = () => { 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 => { setSelectedContactId(contactId); setContactModalOpen(true); @@ -308,11 +336,19 @@ const Contacts = () => { {contact.number} {contact.email} + + handleSaveTicket(contact.id)} + > + + + hadleEditContact(contact.id)} > - + + Date: Fri, 13 Nov 2020 07:12:00 -0300 Subject: [PATCH 2/3] https://github.com/canove/whaticket/pull/58/commits/b0ef070921f02dfc7f2682c111f24a76debae365 --- frontend/src/pages/Contacts/index.js | 31 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/frontend/src/pages/Contacts/index.js b/frontend/src/pages/Contacts/index.js index 557d89e..da1d546 100644 --- a/frontend/src/pages/Contacts/index.js +++ b/frontend/src/pages/Contacts/index.js @@ -188,10 +188,8 @@ const Contacts = () => { } } setLoading(false); - }; - const hadleEditContact = contactId => { setSelectedContactId(contactId); setContactModalOpen(true); @@ -318,9 +316,13 @@ const Contacts = () => { {i18n.t("contacts.table.name")} - {i18n.t("contacts.table.whatsapp")} - {i18n.t("contacts.table.email")} - + + {i18n.t("contacts.table.whatsapp")} + + + {i18n.t("contacts.table.email")} + + {i18n.t("contacts.table.actions")} @@ -333,24 +335,21 @@ const Contacts = () => { {} {contact.name} - {contact.number} - {contact.email} - - - handleSaveTicket(contact.id)} + {contact.number} + {contact.email} + + handleSaveTicket(contact.id)} > - + - hadleEditContact(contact.id)} > - - + - { From 9e82c5cc1f7b78f2fa47a9888284af83eb9929b7 Mon Sep 17 00:00:00 2001 From: canove Date: Fri, 13 Nov 2020 07:12:27 -0300 Subject: [PATCH 3/3] improvement: better on table row skeleton styles --- .../src/components/ContactDrawer/index.js | 4 --- .../src/components/TableRowSkeleton/index.js | 28 +++++++++++++++---- frontend/src/pages/Users/index.js | 23 ++++++++++----- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/ContactDrawer/index.js b/frontend/src/components/ContactDrawer/index.js index 185d502..bb6dc9c 100644 --- a/frontend/src/components/ContactDrawer/index.js +++ b/frontend/src/components/ContactDrawer/index.js @@ -11,7 +11,6 @@ import Avatar from "@material-ui/core/Avatar"; import Button from "@material-ui/core/Button"; import Paper from "@material-ui/core/Paper"; - import { i18n } from "../../translate/i18n"; import LinkifyWithTargetBlank from "../LinkifyWithTargetBlank"; import ContactModal from "../ContactModal"; @@ -19,8 +18,6 @@ import ContactDrawerSkeleton from "../ContactDrawerSkeleton"; const drawerWidth = 320; - - const useStyles = makeStyles(theme => ({ drawer: { width: drawerWidth, @@ -151,7 +148,6 @@ const ContactDrawer = ({ open, handleDrawerClose, contact, loading }) => { variant="outlined" className={classes.contactExtraInfo} > - {info.name} diff --git a/frontend/src/components/TableRowSkeleton/index.js b/frontend/src/components/TableRowSkeleton/index.js index 4d808f5..411cb03 100644 --- a/frontend/src/components/TableRowSkeleton/index.js +++ b/frontend/src/components/TableRowSkeleton/index.js @@ -2,8 +2,18 @@ import React from "react"; import TableCell from "@material-ui/core/TableCell"; import TableRow from "@material-ui/core/TableRow"; import Skeleton from "@material-ui/lab/Skeleton"; +import { makeStyles } from "@material-ui/core"; + +const useStyles = makeStyles(theme => ({ + customTableCell: { + display: "flex", + alignItems: "center", + justifyContent: "center", + }, +})); const TableRowSkeleton = () => { + const classes = useStyles(); return ( <> @@ -13,13 +23,21 @@ const TableRowSkeleton = () => { - - + +
+ +
- - + +
+ +
+
+ +
+ +
-
); diff --git a/frontend/src/pages/Users/index.js b/frontend/src/pages/Users/index.js index 9e750c5..b260623 100644 --- a/frontend/src/pages/Users/index.js +++ b/frontend/src/pages/Users/index.js @@ -28,6 +28,7 @@ import { i18n } from "../../translate/i18n"; import TableRowSkeleton from "../../components/TableRowSkeleton"; import UserModal from "../../components/UserModal"; import ConfirmationModal from "../../components/ConfirmationModal"; +import { Avatar } from "@material-ui/core"; const reducer = (state, action) => { if (action.type === "LOAD_USERS") { @@ -110,7 +111,7 @@ const Users = () => { }); dispatch({ type: "LOAD_USERS", payload: data.users }); setHasMore(data.hasMore); - setLoading(false); + // setLoading(false); } catch (err) { const errorMsg = err.response?.data?.error; if (errorMsg) { @@ -252,10 +253,15 @@ const Users = () => { + {i18n.t("users.table.name")} - {i18n.t("users.table.email")} - {i18n.t("users.table.profile")} - + + {i18n.t("users.table.email")} + + + {i18n.t("users.table.profile")} + + {i18n.t("users.table.actions")} @@ -264,10 +270,13 @@ const Users = () => { <> {users.map(user => ( + + {} + {user.name} - {user.email} - {user.profile} - + {user.email} + {user.profile} + handleEditUser(user)}