Skip to content

Commit

Permalink
Issue #PS-0000 fix: Review callback added for generic editor
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvick committed Jan 31, 2025
1 parent ce4770c commit 90afce8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/components/GenericEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import React, { useEffect, useState } from "react";

// Extend the Window interface to include ecEditor
declare global {
interface Window {
ecEditor?: any;
}
}
import { useRouter } from 'next/router';
import $ from 'jquery';
import _ from 'lodash';
Expand All @@ -7,6 +14,7 @@ import 'izimodal/js/iziModal.js';
import editorConfig from './editor.config.json';
import { getLocalStoredUserId, getLocalStoredUserName } from "@/services/LocalStorageService";
import { CHANNEL_ID, CONTENT_FRAMEWORK_ID, TENANT_ID } from "@/utils/app.config";
import { sendReviewNotification } from "@/services/notificationService";

const GenericEditor: React.FC = () => {
const router = useRouter();
Expand Down Expand Up @@ -112,10 +120,38 @@ const GenericEditor: React.FC = () => {
closeButton: true,
onClosing: () => {
closeModal();
},
onOpened: () => {
// Wait for iframe to be injected
const iframe = document.querySelector("#genericEditor iframe") as HTMLIFrameElement;

if (iframe) {
// Attach event listener when iframe loads
iframe.onload = () => {
console.log("Iframe loaded successfully!");

try {
const iframeWindow = iframe.contentWindow;

if (iframeWindow && iframeWindow.ecEditor) {
iframeWindow.ecEditor.addEventListener(
"org.ekstep.contenteditor:review",
(event: any) => {
console.log("Review Event triggered inside iframe!", event);
sendReviewNotification({contentId: identifier, creator: getLocalStoredUserName()});
}
);
}
} catch (error) {
console.error("Error accessing iframe content:", error);
}
};
}

}
});
}
};
};
}

// Set window context for the iframe
const setWindowContext = (data: any) => {
Expand Down Expand Up @@ -192,7 +228,7 @@ const GenericEditor: React.FC = () => {
return (
<div>
<div id="genericEditor"></div>
{showLoader && <div>Loading.....</div>}
{showLoader && <div>Loading Editor.....</div>}
</div>
);

Expand Down
4 changes: 4 additions & 0 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const sendReviewNotification = async (reviewData: any) => {
// Subject: Content Review Request
// Body: Hi {reviewerName}, {creatorName} has requested you to review the content {contentId}. Please review the content and provide your feedback.
}

0 comments on commit 90afce8

Please sign in to comment.