added message passing from article detail
This commit is contained in:
parent
9296a4ec4e
commit
10f64409bd
@ -1,10 +1,21 @@
|
|||||||
import './ArticleDetail.css';
|
import './ArticleDetail.css';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
function ArticleDetail({ article, onBack, onEdit, onDelete, currentUser }) {
|
function ArticleDetail({ article, onBack, onEdit, onDelete, currentUser }) {
|
||||||
if (!article) {
|
if (!article) {
|
||||||
return <div>No article selected</div>
|
return <div>No article selected</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (window.parent !== window) {
|
||||||
|
window.parent.postMessage({
|
||||||
|
type: 'ka-viewed',
|
||||||
|
kaNumber: article.ka_number,
|
||||||
|
title: article.title
|
||||||
|
}, '*');
|
||||||
|
}
|
||||||
|
}, [article])
|
||||||
|
|
||||||
const canEdit = currentUser?.role === 'Admin' || currentUser?.role === 'Editor';
|
const canEdit = currentUser?.role === 'Admin' || currentUser?.role === 'Editor';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -1,23 +1,30 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
let currentKA = null;
|
let currentKA = null;
|
||||||
|
|
||||||
|
console.log('Freshdesk app loaded');
|
||||||
|
|
||||||
// Listen for messages from the KB iframe
|
// Listen for messages from the KB iframe
|
||||||
window.addEventListener('message', function(event) {
|
window.addEventListener('message', function(event) {
|
||||||
if (event.origin !== 'https://kb.jv.com') {
|
console.log('Received message:', event.origin, event.data);
|
||||||
|
|
||||||
|
if (event.origin !== 'https://jvis.freshdesk.com') {
|
||||||
|
console.log('Ignoring message from wrong origin');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.data.type === 'ka-viewed') {
|
if (event.data.type === 'ka-viewed') {
|
||||||
currentKA = event.data.kaNumber;
|
currentKA = event.data.kaNumber;
|
||||||
console.log('Current KA:', currentKA);
|
console.log('Current KA set to:', currentKA);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.initialized()
|
app.initialized()
|
||||||
.then(function (client) {
|
.then(function (client) {
|
||||||
console.log('KB initialized');
|
console.log('KB app initialized');
|
||||||
|
|
||||||
document.getElementById('insert-ka-btn').addEventListener('click', function() {
|
document.getElementById('insert-ka-btn').addEventListener('click', function() {
|
||||||
|
console.log('Insert button clicked, currentKA:', currentKA);
|
||||||
|
|
||||||
if (!currentKA) {
|
if (!currentKA) {
|
||||||
client.interface.trigger('showNotify', {
|
client.interface.trigger('showNotify', {
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
@ -33,7 +40,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
return client.interface.trigger('showNotify', {
|
return client.interface.trigger('showNotify', {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: currentKA + ' attached to ticket'
|
message: 'KA# ' + currentKA + ' attached'
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user