added message passing from article detail
This commit is contained in:
parent
9296a4ec4e
commit
10f64409bd
@ -1,10 +1,21 @@
|
||||
import './ArticleDetail.css';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
function ArticleDetail({ article, onBack, onEdit, onDelete, currentUser }) {
|
||||
if (!article) {
|
||||
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';
|
||||
|
||||
return (
|
||||
|
||||
@ -1,23 +1,30 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
let currentKA = null;
|
||||
|
||||
console.log('Freshdesk app loaded');
|
||||
|
||||
// Listen for messages from the KB iframe
|
||||
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;
|
||||
}
|
||||
|
||||
if (event.data.type === 'ka-viewed') {
|
||||
currentKA = event.data.kaNumber;
|
||||
console.log('Current KA:', currentKA);
|
||||
console.log('Current KA set to:', currentKA);
|
||||
}
|
||||
});
|
||||
|
||||
app.initialized()
|
||||
.then(function (client) {
|
||||
console.log('KB initialized');
|
||||
console.log('KB app initialized');
|
||||
|
||||
document.getElementById('insert-ka-btn').addEventListener('click', function() {
|
||||
console.log('Insert button clicked, currentKA:', currentKA);
|
||||
|
||||
if (!currentKA) {
|
||||
client.interface.trigger('showNotify', {
|
||||
type: 'warning',
|
||||
@ -33,7 +40,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
.then(function(data) {
|
||||
return client.interface.trigger('showNotify', {
|
||||
type: 'success',
|
||||
message: currentKA + ' attached to ticket'
|
||||
message: 'KA# ' + currentKA + ' attached'
|
||||
});
|
||||
})
|
||||
.catch(function(error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user