diff --git a/frontend/src/components/TicketListItem/index.js b/frontend/src/components/TicketListItem/index.js index 52495bf..04f3720 100644 --- a/frontend/src/components/TicketListItem/index.js +++ b/frontend/src/components/TicketListItem/index.js @@ -1,5 +1,6 @@ import React from "react"; +import { useHistory, useParams } from "react-router-dom"; import { parseISO, format, isSameDay } from "date-fns"; import { makeStyles } from "@material-ui/core/styles"; @@ -15,6 +16,8 @@ import Button from "@material-ui/core/Button"; import { i18n } from "../../translate/i18n"; +import api from "../../services/api"; + const useStyles = makeStyles(theme => ({ ticket: { position: "relative", @@ -82,13 +85,27 @@ const useStyles = makeStyles(theme => ({ }, })); -const TicketListItem = ({ - ticket, - handleAcepptTicket, - handleSelectTicket, - selectedTicketId, -}) => { +const TicketListItem = ({ ticket }) => { const classes = useStyles(); + const history = useHistory(); + const userId = +localStorage.getItem("userId"); + const { ticketId } = useParams(); + + const handleAcepptTicket = async ticketId => { + try { + await api.put(`/tickets/${ticketId}`, { + status: "open", + userId: userId, + }); + } catch (err) { + alert(err); + } + history.push(`/chat/${ticketId}`); + }; + + const handleSelectTicket = (e, ticket) => { + history.push(`/chat/${ticket.id}`); + }; return ( @@ -99,7 +116,7 @@ const TicketListItem = ({ if (ticket.status === "pending" && handleAcepptTicket) return; handleSelectTicket(e, ticket); }} - selected={selectedTicketId && +selectedTicketId === ticket.id} + selected={ticketId && +ticketId === ticket.id} className={classes.ticket} > diff --git a/frontend/src/components/Tickets/index.js b/frontend/src/components/Tickets/index.js index 6540c2a..18236a2 100644 --- a/frontend/src/components/Tickets/index.js +++ b/frontend/src/components/Tickets/index.js @@ -1,5 +1,4 @@ import React, { useState } from "react"; -import { useHistory, useParams } from "react-router-dom"; import { makeStyles } from "@material-ui/core/styles"; import Paper from "@material-ui/core/Paper"; @@ -19,7 +18,6 @@ import TicketsList from "../TicketsList"; import TabPanel from "../TabPanel"; import { i18n } from "../../translate/i18n"; -import api from "../../services/api"; const useStyles = makeStyles(theme => ({ ticketsWrapper: { @@ -85,19 +83,12 @@ const useStyles = makeStyles(theme => ({ const Tickets = () => { const classes = useStyles(); - const history = useHistory(); - const userId = +localStorage.getItem("userId"); - const { ticketId } = useParams(); const [searchParam, setSearchParam] = useState(""); const [tab, setTab] = useState("open"); const [newTicketModalOpen, setNewTicketModalOpen] = useState(false); const [showAllTickets, setShowAllTickets] = useState(false); - const handleSelectTicket = (e, ticket) => { - history.push(`/chat/${ticket.id}`); - }; - const handleSearchContact = e => { if (e.target.value === "") { setSearchParam(e.target.value.toLowerCase()); @@ -112,18 +103,6 @@ const Tickets = () => { setTab(newValue); }; - const handleAcepptTicket = async ticketId => { - try { - await api.put(`/tickets/${ticketId}`, { - status: "open", - userId: userId, - }); - } catch (err) { - alert(err); - } - history.push(`/chat/${ticketId}`); - }; - return ( { - {/* */} - + + - + - + ); diff --git a/frontend/src/components/TicketsList/index.js b/frontend/src/components/TicketsList/index.js index b551930..2df65a8 100644 --- a/frontend/src/components/TicketsList/index.js +++ b/frontend/src/components/TicketsList/index.js @@ -76,14 +76,7 @@ const useStyles = makeStyles(theme => ({ }, })); -const TicketsList = ({ - status, - searchParam, - handleSelectTicket, - handleAcepptTicket, - selectedTicketId, - showAll, -}) => { +const TicketsList = ({ status, searchParam, showAll }) => { const classes = useStyles(); const [pageNumber, setPageNumber] = useState(1); @@ -105,9 +98,7 @@ const TicketsList = ({ const handleScroll = e => { if (!hasMore || loading) return; - const { scrollTop, scrollHeight, clientHeight } = e.currentTarget; - if (scrollHeight - (scrollTop + 100) < clientHeight) { loadMore(); } @@ -145,13 +136,7 @@ const TicketsList = ({ ) : ( <> {tickets.map(ticket => ( - + ))} )}