Watiah11
8 months ago
5 changed files with 70 additions and 6 deletions
@ -0,0 +1,60 @@
|
||||
import React, { useEffect, useState } from 'react'; |
||||
import { useHistory, withRouter } from 'react-router-dom'; |
||||
import { BASE_SIMPRO_LUMEN } from '../../../const/ApiConst'; |
||||
|
||||
const GanttFrame = React.memo((props) => { |
||||
let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = ''; |
||||
if (props.location.state && props.location.state.role_id && props.location.state.user_id) { |
||||
role_id = props.location.state.role_id; |
||||
user_id = props.location.state.user_id; |
||||
isLogin = props.location.state.isLogin; |
||||
token = props.location.state.token; |
||||
} else { |
||||
role_id = localStorage.getItem("role_id"); |
||||
proyek_id = localStorage.getItem("proyek_id"); |
||||
user_id = localStorage.getItem("user_id"); |
||||
isLogin = localStorage.getItem("isLogin"); |
||||
token = localStorage.getItem("token"); |
||||
} |
||||
const history = useHistory(); |
||||
<<<<<<< HEAD |
||||
const { versionGanttId, idProject, ro, timestamp } = props; |
||||
const iframeSrc = `https://project-gantt.ospro.id/edit-mode/index.html?base_url=${BASE_SIMPRO_LUMEN}&gantt_id=${versionGanttId}&proyek_id=${idProject}&token=${token}&ro=${ro}×tamp=${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" |
||||
src={iframeSrc} |
||||
style={{ |
||||
width: '100%', |
||||
height: '95vh', |
||||
}} |
||||
scrolling="no" |
||||
frameBorder="0" |
||||
allow="fullscreen" |
||||
></iframe> |
||||
); |
||||
}); |
||||
|
||||
export default withRouter(GanttFrame); |
Loading…
Reference in new issue