diff --git a/client/kb-frontend/src/App.jsx b/client/kb-frontend/src/App.jsx index 26b7fd4..3adcc2a 100644 --- a/client/kb-frontend/src/App.jsx +++ b/client/kb-frontend/src/App.jsx @@ -38,6 +38,26 @@ function App() { } }, [isLoggedIn, token]); + useEffect(() => { + const handleMessage = (event) => { + if (event.data.type === 'navigate-to-ka') { + const kaNumber = event.data.kaNumber; + console.log('Navigating to KA:', kaNumber); + + const article = articles.find(a => a.ka_number === kaNumber); + if (article) { + handleArticleClick(article); + } + } + }; + + window.addEventListener('message', handleMessage); + + return () => { + window.removeEventListener('message', handleMessage); + } + }, [articles]); + const handleLoginSuccess = (user, authToken) => { setCurrentUser(user); setToken(authToken); diff --git a/fd-client/app/scripts/app.js b/fd-client/app/scripts/app.js index a1cff6d..a23dd7a 100644 --- a/fd-client/app/scripts/app.js +++ b/fd-client/app/scripts/app.js @@ -7,7 +7,7 @@ document.addEventListener('DOMContentLoaded', function () { window.addEventListener('message', function(event) { console.log('Received message:', event.origin, event.data); - if (event.origin !== 'https://jvis.freshdesk.com') { + if (event.origin !== 'https://kb.jv.com') { console.log('Ignoring message from wrong origin'); return; } @@ -22,6 +22,25 @@ document.addEventListener('DOMContentLoaded', function () { .then(function (client) { console.log('KB app initialized'); + // Check if ticket already has a KA number and navigate to it + client.data.get('ticket') + .then(function(data) { + const existingKA = data.ticket.custom_fields.cf_ka_number; + console.log('Existing KA in ticket:', existingKA); + + if (existingKA) { + // Send message to KB iframe to navigate to this article + const iframe = document.getElementById('kb-iframe'); + iframe.contentWindow.postMessage({ + type: 'navigate-to-ka', + kaNumber: existingKA + }, 'https://kb.jv.com'); + } + }) + .catch(function(error) { + console.error('Error reading ticket:', error); + }); + document.getElementById('insert-ka-btn').addEventListener('click', function() { console.log('Insert button clicked, currentKA:', currentKA); @@ -40,7 +59,7 @@ document.addEventListener('DOMContentLoaded', function () { .then(function(data) { return client.interface.trigger('showNotify', { type: 'success', - message: 'KA# ' + currentKA + ' attached' + message: currentKA + ' attached to ticket' }); }) .catch(function(error) {