|
|
@ -1,12 +1,12 @@ |
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
import { Modal, ModalHeader, ModalBody, ModalFooter,Row,Col } from 'reactstrap'; |
|
|
|
import { Modal, ModalHeader, ModalBody, ModalFooter, Row, Col } from 'reactstrap'; |
|
|
|
import { Button, Form, FormGroup, Label, Input } from 'reactstrap'; |
|
|
|
import { Button, Form, FormGroup, Label, Input } from 'reactstrap'; |
|
|
|
import { Select,DatePicker } from 'antd'; |
|
|
|
import { Select, DatePicker } from 'antd'; |
|
|
|
import moment from 'moment'; |
|
|
|
import moment from 'moment'; |
|
|
|
import 'antd/dist/antd.css'; |
|
|
|
import 'antd/dist/antd.css'; |
|
|
|
const proyekId = localStorage.getItem('proyek_id'); |
|
|
|
const proyekId = localStorage.getItem('proyek_id'); |
|
|
|
const { Option } = Select; |
|
|
|
const { Option } = Select; |
|
|
|
const DialogProyek = ({openDialog, closeDialog, toggleDialog, dataWaspangProyek, dataProyek, waspangId}) => { |
|
|
|
const DialogProyek = ({ openDialog, closeDialog, toggleDialog, dataWaspangProyek, dataProyek, waspangId }) => { |
|
|
|
const [id, setId] = useState(0) |
|
|
|
const [id, setId] = useState(0) |
|
|
|
const [proyek_id, setProyekId] = useState(null) |
|
|
|
const [proyek_id, setProyekId] = useState(null) |
|
|
|
const [user_id, setUserId] = useState(null) |
|
|
|
const [user_id, setUserId] = useState(null) |
|
|
@ -18,54 +18,53 @@ const DialogProyek = ({openDialog, closeDialog, toggleDialog, dataWaspangProyek, |
|
|
|
const [role_id, setRoleId] = useState(localStorage.getItem('role_id')) |
|
|
|
const [role_id, setRoleId] = useState(localStorage.getItem('role_id')) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if(waspangId){ |
|
|
|
if (waspangId) { |
|
|
|
setUserIdAdd(waspangId) |
|
|
|
setUserIdAdd(waspangId) |
|
|
|
} |
|
|
|
} |
|
|
|
},[waspangId]) |
|
|
|
}, [waspangId]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(()=> { |
|
|
|
useEffect(() => { |
|
|
|
let data = dataWaspangProyek || [] |
|
|
|
let data = dataWaspangProyek || [] |
|
|
|
console.log("waspang id", waspangId) |
|
|
|
console.log("waspang id", waspangId) |
|
|
|
console.log("role_id", role_id) |
|
|
|
console.log("role_id", role_id) |
|
|
|
if(data.length > 0){ |
|
|
|
if (data.length > 0) { |
|
|
|
console.log("cek data waspang proyek",data) |
|
|
|
|
|
|
|
let dataObj = data[0] |
|
|
|
let dataObj = data[0] |
|
|
|
setType("edit") |
|
|
|
setType("edit") |
|
|
|
setProyekId(dataObj.proyek_id) |
|
|
|
setProyekId(dataObj.proyek_id) |
|
|
|
if(dataObj.mulai){ |
|
|
|
if (dataObj.mulai) { |
|
|
|
setStartDate(moment(moment(dataObj.mulai))) |
|
|
|
setStartDate(moment(moment(dataObj.mulai))) |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
setStartDate(moment(moment())) |
|
|
|
setStartDate(moment(moment())) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(dataObj.mulai){ |
|
|
|
if (dataObj.mulai) { |
|
|
|
setEndDate(moment(moment(dataObj.akhir))) |
|
|
|
setEndDate(moment(moment(dataObj.akhir))) |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
setEndDate(moment(moment())) |
|
|
|
setEndDate(moment(moment())) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setUserId(dataObj.user_id) |
|
|
|
setUserId(dataObj.user_id) |
|
|
|
setId(dataObj.id) |
|
|
|
setId(dataObj.id) |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
setProyekId(null) |
|
|
|
setProyekId(null) |
|
|
|
setStartDate(moment(moment())) |
|
|
|
setStartDate(moment(moment())) |
|
|
|
setEndDate(moment(moment())) |
|
|
|
setEndDate(moment(moment())) |
|
|
|
setType("add") |
|
|
|
setType("add") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(parseInt(role_id)===2){ |
|
|
|
if (parseInt(role_id) === 2) { |
|
|
|
setProyekId(parseInt(proyekId)) |
|
|
|
setProyekId(parseInt(proyekId)) |
|
|
|
setDisableSelectProyek(true) |
|
|
|
setDisableSelectProyek(true) |
|
|
|
} |
|
|
|
} |
|
|
|
},[dataWaspangProyek,openDialog]) |
|
|
|
}, [dataWaspangProyek, openDialog]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if(parseInt(role_id)===2){ |
|
|
|
if (parseInt(role_id) === 2) { |
|
|
|
setProyekId(parseInt(proyekId)) |
|
|
|
setProyekId(parseInt(proyekId)) |
|
|
|
setDisableSelectProyek(true) |
|
|
|
setDisableSelectProyek(true) |
|
|
|
} |
|
|
|
} |
|
|
|
},[role_id]) |
|
|
|
}, [role_id]) |
|
|
|
const handleCancel = () => { |
|
|
|
const handleCancel = () => { |
|
|
|
closeDialog('cancel', 'none') |
|
|
|
closeDialog('cancel', 'none') |
|
|
|
setId(0) |
|
|
|
setId(0) |
|
|
@ -77,10 +76,10 @@ const DialogProyek = ({openDialog, closeDialog, toggleDialog, dataWaspangProyek, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const setupOption = () => { |
|
|
|
const setupOption = () => { |
|
|
|
return( |
|
|
|
return ( |
|
|
|
<> |
|
|
|
<> |
|
|
|
{dataProyek.map((val, index)=> { |
|
|
|
{dataProyek.map((val, index) => { |
|
|
|
return( |
|
|
|
return ( |
|
|
|
<Option key={index} value={val.id}>{val.nama}</Option> |
|
|
|
<Option key={index} value={val.id}>{val.nama}</Option> |
|
|
|
) |
|
|
|
) |
|
|
|
})} |
|
|
|
})} |
|
|
@ -97,19 +96,19 @@ const DialogProyek = ({openDialog, closeDialog, toggleDialog, dataWaspangProyek, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const handleSave = () => { |
|
|
|
const handleSave = () => { |
|
|
|
let data ={ |
|
|
|
let data = { |
|
|
|
type, |
|
|
|
type, |
|
|
|
mulai:startDate, |
|
|
|
mulai: startDate, |
|
|
|
akhir:endDate, |
|
|
|
akhir: endDate, |
|
|
|
proyek_id, |
|
|
|
proyek_id, |
|
|
|
user_id |
|
|
|
user_id |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(type==="add"){ |
|
|
|
if (type === "add") { |
|
|
|
data['user_id'] = userIdAdd |
|
|
|
data['user_id'] = userIdAdd |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(type==="edit"){ |
|
|
|
if (type === "edit") { |
|
|
|
data['id'] = id |
|
|
|
data['id'] = id |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -117,22 +116,22 @@ const DialogProyek = ({openDialog, closeDialog, toggleDialog, dataWaspangProyek, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const renderForm = () => { |
|
|
|
const renderForm = () => { |
|
|
|
return( |
|
|
|
return ( |
|
|
|
<Form> |
|
|
|
<Form> |
|
|
|
<FormGroup> |
|
|
|
<FormGroup> |
|
|
|
<Label className="capitalize">Proyek</Label> |
|
|
|
<Label className="capitalize">Proyek</Label> |
|
|
|
{/* <Input type="text" value={alias} onChange={(e)=> setAlias(e.target.value)} placeholder={`Icon..`} /> */} |
|
|
|
{/* <Input type="text" value={alias} onChange={(e)=> setAlias(e.target.value)} placeholder={`Icon..`} /> */} |
|
|
|
<Select showSearch value={proyek_id} onChange={onChangeParent} placeholder="Select Proyek .." style={{width:'100%'}} disabled={disableSelectProyek}> |
|
|
|
<Select showSearch value={proyek_id} onChange={onChangeParent} placeholder="Select Proyek .." style={{ width: '100%' }} disabled={disableSelectProyek}> |
|
|
|
{setupOption()} |
|
|
|
{setupOption()} |
|
|
|
</Select> |
|
|
|
</Select> |
|
|
|
</FormGroup> |
|
|
|
</FormGroup> |
|
|
|
<FormGroup> |
|
|
|
<FormGroup> |
|
|
|
<Label className="capitalize">Tanggal Mulai</Label> |
|
|
|
<Label className="capitalize">Tanggal Mulai</Label> |
|
|
|
<DatePicker style={{width:"100%"}} value={startDate} onChange={handleStartDate} allowClear={false} /> |
|
|
|
<DatePicker style={{ width: "100%" }} value={startDate} onChange={handleStartDate} allowClear={false} /> |
|
|
|
</FormGroup> |
|
|
|
</FormGroup> |
|
|
|
<FormGroup> |
|
|
|
<FormGroup> |
|
|
|
<Label className="capitalize">Tanggal</Label> |
|
|
|
<Label className="capitalize">Tanggal</Label> |
|
|
|
<DatePicker style={{width:"100%"}} value={endDate} onChange={handleEndDate} allowClear={false} /> |
|
|
|
<DatePicker style={{ width: "100%" }} value={endDate} onChange={handleEndDate} allowClear={false} /> |
|
|
|
</FormGroup> |
|
|
|
</FormGroup> |
|
|
|
</Form> |
|
|
|
</Form> |
|
|
|
) |
|
|
|
) |
|
|
@ -141,7 +140,7 @@ const DialogProyek = ({openDialog, closeDialog, toggleDialog, dataWaspangProyek, |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<Modal isOpen={openDialog} toggle={toggleDialog}> |
|
|
|
<Modal isOpen={openDialog} toggle={toggleDialog}> |
|
|
|
<ModalHeader className="capitalize" toggle={() =>closeDialog("none", "none")}>Save User Proyek</ModalHeader> |
|
|
|
<ModalHeader className="capitalize" toggle={() => closeDialog("none", "none")}>Save User Proyek</ModalHeader> |
|
|
|
<ModalBody> |
|
|
|
<ModalBody> |
|
|
|
{renderForm()} |
|
|
|
{renderForm()} |
|
|
|
</ModalBody> |
|
|
|
</ModalBody> |
|
|
|