Browse Source

Prevent moving page

pull/2/head
Wahyu Ramadhan 1 year ago
parent
commit
63797ecf83
  1. 28
      src/views/SimproV2/Gantt/GanttFrame.js

28
src/views/SimproV2/Gantt/GanttFrame.js

@ -1,10 +1,36 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
import { BASE_SIMPRO_LUMEN } from '../../../const/ApiConst';
const GanttFrame = React.memo((props) => {
const history = useHistory();
const { versionGanttId, idProject, token, ro, timestamp } = props;
const iframeSrc = `https://adw-gantt.ospro.id/edit-mode/index.html?base_url=${BASE_SIMPRO_LUMEN}&gantt_id=${versionGanttId}&proyek_id=${idProject}&token=${token}&ro=${ro}&timestamp=${timestamp}`;
const [batchEntityData, setBatchEntityData] = useState(null);
useEffect(() => {
const handleMessage = (event) => {
if (event.data && event.data.batchEntity) {
setBatchEntityData(event.data.batchEntity);
}
};
window.addEventListener('message', handleMessage);
}, []);
useEffect(()=>{
const handleNavigation = (event) => {
if (batchEntityData && batchEntityData !== '') {
const message = 'You have unsaved changes. Are you sure you want to leave this page?';
return message;
}
};
history.block(handleNavigation);
}, [batchEntityData])
return (
<iframe
id="frame-gantt"

Loading…
Cancel
Save