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/Contacts/index.js b/frontend/src/pages/Contacts/index.js index 95f1fcd..da1d546 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,31 @@ 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); @@ -290,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")} @@ -305,16 +335,21 @@ const Contacts = () => { {} {contact.name} - {contact.number} - {contact.email} - + {contact.number} + {contact.email} + + handleSaveTicket(contact.id)} + > + + hadleEditContact(contact.id)} > - { 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)}