Novas alterações para possibilitar abrir links

adriano 2023-06-13 16:21:08 -03:00
parent 9f2d574251
commit e88bd10244
5 changed files with 39 additions and 24 deletions

View File

@ -18,9 +18,12 @@ interface Response {
const ListMessagesService = async ({ const ListMessagesService = async ({
pageNumber = "1", pageNumber = "1",
ticketId ticketId
}: Request): Promise<Response> => { }: Request): Promise<Response> => {
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 { return {
messages: [], messages: [],
ticket: new Ticket, ticket: new Ticket,

View File

@ -42,7 +42,7 @@ const CreateTicketService = async ({
console.log('Create contact service........') console.log('Create contact service........')
const defaultWhatsapp = await GetDefaultWhatsApp(userId); const defaultWhatsapp = await GetDefaultWhatsApp(userId);
const user = await User.findByPk(userId, { raw: true, }) const user = await User.findByPk(userId, { raw: true, })
console.log('user.profile: ', user?.profile) console.log('user.profile: ', user?.profile)
@ -70,10 +70,16 @@ const CreateTicketService = async ({
if (!ticket) { if (!ticket) {
throw new AppError("ERR_CREATING_TICKET"); throw new AppError("ERR_CREATING_TICKET");
} }
if (msg.length > 0) { if (msg.length > 0) {
sendWhatsAppMessageSocket(ticket, msg)
setTimeout(async () => {
sendWhatsAppMessageSocket(ticket, msg)
}, 3000)
} }

View File

@ -83,14 +83,14 @@ const Ticket = () => {
const [contact, setContact] = useState({}); const [contact, setContact] = useState({});
const [ticket, setTicket] = useState({}); const [ticket, setTicket] = useState({});
const [statusChatEnd, setStatusChatEnd] = useState({}) const [statusChatEnd, setStatusChatEnd] = useState({})
useEffect(() => { useEffect(() => {
setLoading(true); setLoading(true);
const delayDebounceFn = setTimeout(() => { const delayDebounceFn = setTimeout(() => {
const fetchTicket = async () => { const fetchTicket = async () => {
try { try {
// maria julia // maria julia
const { data } = await api.get("/tickets/" + ticketId); const { data } = await api.get("/tickets/" + ticketId);
@ -101,7 +101,7 @@ const Ticket = () => {
setContact(data.contact.contact); setContact(data.contact.contact);
setTicket(data.contact); setTicket(data.contact);
setStatusChatEnd(data.statusChatEnd) setStatusChatEnd(data.statusChatEnd)
setLoading(false); setLoading(false);
} catch (err) { } catch (err) {
@ -115,9 +115,9 @@ const Ticket = () => {
}, [ticketId, history]); }, [ticketId, history]);
useEffect(() => { useEffect(() => {
const regex = /^[0-9\b]+$/; // Regular expression to match only numbers 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); const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
@ -176,7 +176,7 @@ const Ticket = () => {
/> />
</div> </div>
<div className={classes.ticketActionButtons}> <div className={classes.ticketActionButtons}>
<TicketActionButtons ticket={ticket} statusChatEnd={statusChatEnd}/> <TicketActionButtons ticket={ticket} statusChatEnd={statusChatEnd} />
</div> </div>
</TicketHeader> </TicketHeader>
<ReplyMessageProvider> <ReplyMessageProvider>

View File

@ -12,7 +12,7 @@ import ContactDrawer from "../../../components/ContactDrawer";
import MessageInput from "../../../components/MessageInput"; import MessageInput from "../../../components/MessageInput";
import TicketHeader from "../../../components/TicketHeader"; import TicketHeader from "../../../components/TicketHeader";
import TicketInfo from "../../../components/TicketInfo"; import TicketInfo from "../../../components/TicketInfo";
import TicketActionButtons from "../../../components/TicketActionButtons"; // import TicketActionButtons from "../../../components/TicketActionButtons";
import MessagesList from "../../../components/MessagesList"; import MessagesList from "../../../components/MessagesList";
import api from "../../../services/api"; import api from "../../../services/api";
import { ReplyMessageProvider } from "../../../context/ReplyingMessage/ReplyingMessageContext"; import { ReplyMessageProvider } from "../../../context/ReplyingMessage/ReplyingMessageContext";
@ -89,7 +89,7 @@ const Ticket = () => {
const [contact, setContact] = useState({}); const [contact, setContact] = useState({});
const [ticket, setTicket] = useState({}); const [ticket, setTicket] = useState({});
const [statusChatEnd, setStatusChatEnd] = useState({}) // const [statusChatEnd, setStatusChatEnd] = useState({})
useEffect(() => { useEffect(() => {
setLoading(true); setLoading(true);
@ -105,6 +105,10 @@ const Ticket = () => {
link = window.location.href link = window.location.href
console.log('>>>>>>>>>>>>>>>>>>>>> link: ', link )
// alert('LINK: '+link)
if (link.includes('/https://wa.me/')) { if (link.includes('/https://wa.me/')) {
link = window.location.href.split('/https://wa.me/') link = window.location.href.split('/https://wa.me/')
@ -112,7 +116,8 @@ const Ticket = () => {
number = link[1].split('?text=')[0] number = link[1].split('?text=')[0]
msg = link[1].split('?text=')[1] || '' 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=') let aux = link.split('?phone=')
@ -127,14 +132,14 @@ const Ticket = () => {
msg = msg.split('&type=')[0] msg = msg.split('&type=')[0]
} }
} }
if (msg && msg.trim().length > 0) { if (msg && msg.trim().length > 0) {
msg = decodeURIComponent(msg); 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" }, }); const { data: data0 } = await api.get("/contacts/", { params: { searchParam: number, pageNumber: "1" }, });
if (data0 && data0.contacts.length > 0) { if (data0 && data0.contacts.length > 0) {
@ -183,7 +188,7 @@ const Ticket = () => {
useEffect(() => { useEffect(() => {
const regex = /^[0-9\b]+$/; // Regular expression to match only numbers 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); const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
@ -241,9 +246,9 @@ const Ticket = () => {
onClick={handleDrawerOpen} onClick={handleDrawerOpen}
/> />
</div> </div>
<div className={classes.ticketActionButtons}> {/* <div className={classes.ticketActionButtons}>
<TicketActionButtons ticket={ticket} statusChatEnd={statusChatEnd} /> <TicketActionButtons ticket={ticket} statusChatEnd={statusChatEnd} />
</div> </div> */}
</TicketHeader> </TicketHeader>
<ReplyMessageProvider> <ReplyMessageProvider>
<MessagesList <MessagesList

View File

@ -37,7 +37,8 @@ const Routes = () => {
<Route exact path="/tickets/:ticketId?" component={Tickets} isPrivate /> <Route exact path="/tickets/:ticketId?" component={Tickets} isPrivate />
<Route exact path="/tickets/https://wa.me/:ticketId?" component={WhatsLink} isPrivate /> <Route exact path="/tickets/https://wa.me/:ticketId?" component={WhatsLink} isPrivate />
<Route exact path="/tickets/https://web.whatsapp.com/send/:ticketId?" component={WhatsLink} isPrivate /> {/* <Route exact path="/tickets/https://web.whatsapp.com/send/:ticketId?" component={WhatsLink} isPrivate /> */}
<Route exact path="/tickets/https://web.whatsapp.com/:ticketId?" component={WhatsLink} isPrivate />
<Route exact path="/connections" component={Connections} isPrivate /> <Route exact path="/connections" component={Connections} isPrivate />