From e88bd102448eaeeedc0ce04b40fbaf3e593662bb Mon Sep 17 00:00:00 2001 From: adriano Date: Tue, 13 Jun 2023 16:21:08 -0300 Subject: [PATCH] =?UTF-8?q?Novas=20altera=C3=A7=C3=B5es=20para=20possibili?= =?UTF-8?q?tar=20=20abrir=20links?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MessageServices/ListMessagesService.ts | 7 ++++-- .../TicketServices/CreateTicketService.ts | 16 ++++++++---- frontend/src/components/Ticket/index.js | 12 ++++----- frontend/src/pages/Tickets/WhatsLink/index.js | 25 +++++++++++-------- frontend/src/routes/index.js | 3 ++- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/backend/src/services/MessageServices/ListMessagesService.ts b/backend/src/services/MessageServices/ListMessagesService.ts index a6261f2..469887a 100644 --- a/backend/src/services/MessageServices/ListMessagesService.ts +++ b/backend/src/services/MessageServices/ListMessagesService.ts @@ -18,9 +18,12 @@ interface Response { const ListMessagesService = async ({ pageNumber = "1", ticketId -}: Request): Promise => { +}: Request): Promise => { - if ((ticketId && ticketId.length > 9) || !ticketId || (ticketId && ticketId === 'undefined')) { + + const regex = /^[0-9\b]+$/; // Regular expression to match only numbers + + if ((ticketId && ticketId.length > 9) || !ticketId || !ticketId.match(regex)) { return { messages: [], ticket: new Ticket, diff --git a/backend/src/services/TicketServices/CreateTicketService.ts b/backend/src/services/TicketServices/CreateTicketService.ts index be7ff80..de5e049 100644 --- a/backend/src/services/TicketServices/CreateTicketService.ts +++ b/backend/src/services/TicketServices/CreateTicketService.ts @@ -42,7 +42,7 @@ const CreateTicketService = async ({ console.log('Create contact service........') - const defaultWhatsapp = await GetDefaultWhatsApp(userId); + const defaultWhatsapp = await GetDefaultWhatsApp(userId); const user = await User.findByPk(userId, { raw: true, }) console.log('user.profile: ', user?.profile) @@ -70,10 +70,16 @@ const CreateTicketService = async ({ if (!ticket) { throw new AppError("ERR_CREATING_TICKET"); - } - - if (msg.length > 0) { - sendWhatsAppMessageSocket(ticket, msg) + } + + if (msg.length > 0) { + + setTimeout(async () => { + + sendWhatsAppMessageSocket(ticket, msg) + + }, 3000) + } diff --git a/frontend/src/components/Ticket/index.js b/frontend/src/components/Ticket/index.js index 28a7d0a..bdd8fff 100644 --- a/frontend/src/components/Ticket/index.js +++ b/frontend/src/components/Ticket/index.js @@ -83,14 +83,14 @@ const Ticket = () => { const [contact, setContact] = useState({}); const [ticket, setTicket] = useState({}); - const [statusChatEnd, setStatusChatEnd] = useState({}) + const [statusChatEnd, setStatusChatEnd] = useState({}) useEffect(() => { setLoading(true); const delayDebounceFn = setTimeout(() => { const fetchTicket = async () => { try { - + // maria julia const { data } = await api.get("/tickets/" + ticketId); @@ -101,7 +101,7 @@ const Ticket = () => { setContact(data.contact.contact); setTicket(data.contact); - setStatusChatEnd(data.statusChatEnd) + setStatusChatEnd(data.statusChatEnd) setLoading(false); } catch (err) { @@ -115,9 +115,9 @@ const Ticket = () => { }, [ticketId, history]); useEffect(() => { - + const regex = /^[0-9\b]+$/; // Regular expression to match only numbers - if (ticketId && !ticketId.match(regex) || ticketId && ticketId.length > 9 || !ticketId) return + if ((ticketId && !ticketId.match(regex)) || (ticketId && ticketId.length > 9) || (!ticketId)) return const socket = openSocket(process.env.REACT_APP_BACKEND_URL); @@ -176,7 +176,7 @@ const Ticket = () => { />
- +
diff --git a/frontend/src/pages/Tickets/WhatsLink/index.js b/frontend/src/pages/Tickets/WhatsLink/index.js index 3b47905..851983c 100644 --- a/frontend/src/pages/Tickets/WhatsLink/index.js +++ b/frontend/src/pages/Tickets/WhatsLink/index.js @@ -12,7 +12,7 @@ import ContactDrawer from "../../../components/ContactDrawer"; import MessageInput from "../../../components/MessageInput"; import TicketHeader from "../../../components/TicketHeader"; import TicketInfo from "../../../components/TicketInfo"; -import TicketActionButtons from "../../../components/TicketActionButtons"; +// import TicketActionButtons from "../../../components/TicketActionButtons"; import MessagesList from "../../../components/MessagesList"; import api from "../../../services/api"; import { ReplyMessageProvider } from "../../../context/ReplyingMessage/ReplyingMessageContext"; @@ -89,7 +89,7 @@ const Ticket = () => { const [contact, setContact] = useState({}); const [ticket, setTicket] = useState({}); - const [statusChatEnd, setStatusChatEnd] = useState({}) + // const [statusChatEnd, setStatusChatEnd] = useState({}) useEffect(() => { setLoading(true); @@ -105,6 +105,10 @@ const Ticket = () => { link = window.location.href + console.log('>>>>>>>>>>>>>>>>>>>>> link: ', link ) + + // alert('LINK: '+link) + if (link.includes('/https://wa.me/')) { link = window.location.href.split('/https://wa.me/') @@ -112,7 +116,8 @@ const Ticket = () => { number = link[1].split('?text=')[0] msg = link[1].split('?text=')[1] || '' } - else if (link.includes('https://web.whatsapp.com/send/?phone')) { + else if (link.includes('https://web.whatsapp.com/send/?phone') || + link.includes('https://web.whatsapp.com/send?phone')) { let aux = link.split('?phone=') @@ -127,14 +132,14 @@ const Ticket = () => { msg = msg.split('&type=')[0] } - } + } if (msg && msg.trim().length > 0) { msg = decodeURIComponent(msg); - } - - console.log('NUMBER: ', number, ' | MESSAGE: ', msg) + } + console.log('NUMBER: ', number, ' | MESSAGE: ', msg) + const { data: data0 } = await api.get("/contacts/", { params: { searchParam: number, pageNumber: "1" }, }); if (data0 && data0.contacts.length > 0) { @@ -183,7 +188,7 @@ const Ticket = () => { useEffect(() => { const regex = /^[0-9\b]+$/; // Regular expression to match only numbers - if (ticketId && !ticketId.match(regex) || ticketId && ticketId.length > 9 || !ticketId) return + if ( (ticketId && !ticketId.match(regex)) || (ticketId && ticketId.length > 9) || !ticketId) return const socket = openSocket(process.env.REACT_APP_BACKEND_URL); @@ -241,9 +246,9 @@ const Ticket = () => { onClick={handleDrawerOpen} /> -
+ {/*
-
+
*/} { - + {/* */} +