diff --git a/src/components/GenericEditor.tsx b/src/components/GenericEditor.tsx index 4f194e0..cfce0c3 100644 --- a/src/components/GenericEditor.tsx +++ b/src/components/GenericEditor.tsx @@ -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'; @@ -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(); @@ -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) => { @@ -192,7 +228,7 @@ const GenericEditor: React.FC = () => { return (
- {showLoader &&
Loading.....
} + {showLoader &&
Loading Editor.....
}
); diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts new file mode 100644 index 0000000..da7dffd --- /dev/null +++ b/src/services/notificationService.ts @@ -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. +} \ No newline at end of file