diff --git a/src/views/Dashboard/DashboardProject.js b/src/views/Dashboard/DashboardProject.js index 760e08f..42cb383 100644 --- a/src/views/Dashboard/DashboardProject.js +++ b/src/views/Dashboard/DashboardProject.js @@ -20,10 +20,10 @@ const { TextArea } = Input; const styles = { cardContainer: { backgroundColor: '#F8F8F8', margin: 2, paddingLeft: 20, paddingRight: 20, paddingTop: 10 }, - cardHeaderContainer: { display: 'flex', flexDirection: 'row', marginBottom: 10 }, - cardChartContainer: { position: 'relative', height: '21vh', margin: 'auto', paddingBottom: 10, justifyContent: 'center' }, - cardTitle: { color: '#444444', fontSize: 16, fontWeight: 'bold' }, - cardSubtitle: { color: '#888888', fontSize: 12 } + cardHeaderContainer: { display: 'flex', flexDirection: 'row', marginBottom: 10 }, + cardChartContainer: { position: 'relative', height: '21vh', margin: 'auto', paddingBottom: 10, justifyContent: 'center' }, + cardTitle: { color: '#444444', fontSize: 16, fontWeight: 'bold' }, + cardSubtitle: { color: '#888888', fontSize: 12 } } const center = { @@ -32,13 +32,13 @@ const center = { } const DashboardProject = () => { - const token = localStorage.getItem("token") - const HEADER = { - headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${token}` - } - } + const token = localStorage.getItem("token") + const HEADER = { + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + } + } const { PROJECT_ID, GANTT_ID } = useParams(); const URL_GANTT = `https://adw-gantt.ospro.id/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${GANTT_ID}&proyek_id=${PROJECT_ID}&token=${token}&ro=1`; const mapRef = useRef() @@ -80,7 +80,7 @@ const DashboardProject = () => { const [healthBySchedule, setHealthBySchedule] = useState('-') const [healthByBudget, setHealthByBudget] = useState('-') const [reportDistribution, setReportDistribution] = useState([]); - let history = useHistory(); + let history = useHistory(); useEffect(() => { @@ -101,17 +101,17 @@ const DashboardProject = () => { }, [activeTabIdx]); useEffect(() => { - let deviation = 0; - if(plannedCost && totalCost){ - deviation = plannedCost - totalCost; - } - setRemToComplete(deviation.toString()) + let deviation = 0; + if (plannedCost && totalCost) { + deviation = plannedCost - totalCost; + } + setRemToComplete(deviation.toString()) }, [plannedCost, totalCost]); - const handleRedirect = () => { - history.push("/projects/"+GANTT_ID+"/"+PROJECT_ID+"/gantt"); - } + const handleRedirect = () => { + history.push("/projects/" + GANTT_ID + "/" + PROJECT_ID + "/gantt"); + } const getProjectDetail = async () => { setIsReadyProjectDetail(false); @@ -121,17 +121,17 @@ const DashboardProject = () => { if (!result) { NotificationManager.error(`Could not connect to internet.`, "Failed"); setIsReadyProjectDetail(true); - return; + return; } if (result.status !== 200) { - NotificationManager.error(`Get project detail failed, ${result.data.message}`, "Failed"); + NotificationManager.error(`Get project detail failed, ${result.data.message}`, "Failed"); setIsReadyProjectDetail(true); - return; - } + return; + } else if (result.status == 200 && result.data.data) { console.log(result.data.data); - // setComments(result.data.data); + // setComments(result.data.data); setProjectName(result.data.data.nama ? result.data.data.nama : '-'); setProjectManagerName(result.data.data.projectManager ? result.data.data.projectManager : '-'); setCustomerName(result.data.data.company ? result.data.data.company : '-') @@ -145,7 +145,7 @@ const DashboardProject = () => { if (result.data.data.kode_sortname && result.data.data.kode_sortname !== '') { getIntegrationInvoice(result.data.data.kode_sortname) } - } + } } const getSCurve = async () => { @@ -157,18 +157,17 @@ const DashboardProject = () => { // "end_date": moment(new Date()).format('YYYY-MM-DD') } const result = await axios.post(URL, payload, HEADER).then(res => res).catch(err => err.response) - console.log('getSCurve', result); if (!result) { NotificationManager.error(`Could not connect to internet.`, "Failed"); setIsReadySCurve(true); - return; + return; } if (result.status !== 200) { - NotificationManager.error(`Get S Curve failed, ${result.data.message}`, "Failed"); + NotificationManager.error(`Get S Curve failed, ${result.data.message}`, "Failed"); setIsReadySCurve(true); - return; - } + return; + } else if (result.status == 200 && result.data.data) { let selisihProgress = 0; let planningProgress = 0; @@ -184,11 +183,11 @@ const DashboardProject = () => { setCostDeviation(result.data.data[0].data.budget_control.cost_deviation?.toString()) } if (result.data.data.length > 0 && result.data.data[0].data?.percentagePlan && result.data.data[0].data?.percentagePlan.length > 0) { - planningProgress = result.data.data[0].data?.percentagePlan[result.data.data[0].data?.percentagePlan.length-1]; + planningProgress = result.data.data[0].data?.percentagePlan[result.data.data[0].data?.percentagePlan.length - 1]; setPlanningProgress(planningProgress); } if (result.data.data.length > 0 && result.data.data[0].data?.percentageReal && result.data.data[0].data?.percentageReal.length > 0) { - actualProgress = result.data.data[0].data?.percentageReal[result.data.data[0].data?.percentageReal.length-1]; + actualProgress = result.data.data[0].data?.percentageReal[result.data.data[0].data?.percentageReal.length - 1]; setActualProgress(actualProgress); } @@ -202,7 +201,7 @@ const DashboardProject = () => { setHealthBySchedule(statusHealthBySchedule) setIsReadySCurve(true); - } + } } const getOverdueActivities = async () => { @@ -217,21 +216,21 @@ const DashboardProject = () => { if (!result) { NotificationManager.error(`Could not connect to internet.`, "Failed"); setIsReadyOverdueActivities(true); - return; + return; } if (result.status !== 200) { - NotificationManager.error(`Get Overdue Activities failed, ${result.data.message}`, "Failed"); + NotificationManager.error(`Get Overdue Activities failed, ${result.data.message}`, "Failed"); setIsReadyOverdueActivities(true); - return; - } + return; + } else if (result.status == 200 && result.data.data) { if (result.data.data.overdueActivities) { setOverdueActivities(result.data.data.overdueActivities) } setHealthByBudget(result.data.data.budget_health) setIsReadyOverdueActivities(true); - } + } } const getIntegrationInvoice = async (kode_sortname) => { @@ -245,16 +244,15 @@ const DashboardProject = () => { if (!result) { NotificationManager.error(`Could not connect to internet.`, "Failed"); setIsReadyIntegrationInvoice(true); - return; + return; } if (result.status !== 200) { - NotificationManager.error(`Get integration invoice failed, ${result.data.message}`, "Failed"); + NotificationManager.error(`Get integration invoice failed, ${result.data.message}`, "Failed"); setIsReadyIntegrationInvoice(true); - return; - } + return; + } else if (result.status == 200 && result.data.data) { - // console.log() if (result.data.data.data) { let total_invoice = result.data.data.data.total_invoice_amount; let cash_in = result.data.data.data.total_invoice_paid_amount; @@ -262,12 +260,12 @@ const DashboardProject = () => { let outstanding_balance = total_invoice - cash_in; setTotalInvoice(total_invoice ? total_invoice.toString() : null); setCashIn(cash_in ? cash_in.toString() : null) - total_cost = total_cost.toString().split('.')[0] - setTotalCost(total_cost? total_cost.toString() : null) + total_cost = total_cost.toString().split('.')[0] + setTotalCost(total_cost ? total_cost.toString() : null) setOutstandingBalance(outstanding_balance ? outstanding_balance.toString() : null); } setIsReadyIntegrationInvoice(true); - } + } } const getReportDistribution = async () => { @@ -283,66 +281,66 @@ const DashboardProject = () => { if (!result) { NotificationManager.error(`Could not connect to internet.`, "Failed"); setIsReadyReportDistribution(true); - return; + return; } if (result.status !== 200) { - NotificationManager.error(`Get report distribution failed, ${result.data.message}`, "Failed"); + NotificationManager.error(`Get report distribution failed, ${result.data.message}`, "Failed"); setIsReadyReportDistribution(true); - return; - } + return; + } else if (result.status == 200 && result.data.data) { setReportDistribution(result.data.data); setIsReadyReportDistribution(true); - } + } } const getComments = async () => { setIsReadyComments(false); const URL = `${BASE_OSPRO}/api/project-comment/search`; const payload = { - columns: [ - { - name: "project_id", - logic_operator: "=", - value: PROJECT_ID.toString(), - operator: "AND", - }, + columns: [ + { + name: "project_id", + logic_operator: "=", + value: PROJECT_ID.toString(), + operator: "AND", + }, + { + name: "gantt_id", + logic_operator: "=", + value: GANTT_ID.toString(), + operator: "AND", + } + ], + joins: [ { - name: "gantt_id", - logic_operator: "=", - value: GANTT_ID.toString(), - operator: "AND", - } - ], - joins: [ - { - name: "m_users", - column_join: "sender_id", - column_results: ["name", "username"], - } - ], - orders: { columns: ["created_at"], ascending: false }, - paging: { start: 0, length: -1 }, - }; + name: "m_users", + column_join: "sender_id", + column_results: ["name", "username"], + } + ], + orders: { columns: ["created_at"], ascending: false }, + paging: { start: 0, length: -1 }, + }; const result = await axios.post(URL, payload, HEADER).then(res => res).catch(err => err.response) console.log('getComments', result); if (!result) { NotificationManager.error(`Could not connect to internet.`, "Failed"); setIsReadyComments(true); - return; + return; } if (result.status !== 200) { - NotificationManager.error(`Get comments failed, ${result.data.message}`, "Failed"); + NotificationManager.error(`Get comments failed, ${result.data.message}`, "Failed"); setIsReadyComments(true); - return; - } + return; + } else if (result.status == 200 && result.data.data) { - setComments(result.data.data); + setComments(result.data.data); setIsReadyComments(true); - } + } } const handleSendComment = async () => { @@ -365,14 +363,14 @@ const DashboardProject = () => { if (!result) { NotificationManager.error(`Could not connect to internet.`, "Failed"); setIsSendingComment(false); - return; + return; } if (result.status !== 200) { - NotificationManager.error(`Post comment failed, ${result.data.message}`, "Failed"); + NotificationManager.error(`Post comment failed, ${result.data.message}`, "Failed"); setIsSendingComment(false); - return; - } + return; + } else if (result.status === 200) { NotificationManager.success(`Post comment success`, "Success"); resetInputComment(); @@ -392,7 +390,7 @@ const DashboardProject = () => { }); setMymap(mymap); - L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: '© OpenStreetMap contributors'}).addTo(mymap); + L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' }).addTo(mymap); } useEffect(() => { @@ -406,36 +404,36 @@ const DashboardProject = () => { }, [mymap, reportDistribution]) const RenderGantt = useMemo(() => ( - - ), [activeTabIdx]) + + ), [activeTabIdx]) const RenderComments = useMemo(() => { return ( <> -