|
|
|
@ -1,12 +1,12 @@
|
|
|
|
|
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 { Select,DatePicker } from 'antd'; |
|
|
|
|
import { Select, DatePicker } from 'antd'; |
|
|
|
|
import moment from 'moment'; |
|
|
|
|
import 'antd/dist/antd.css'; |
|
|
|
|
const proyekId = localStorage.getItem('proyek_id'); |
|
|
|
|
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 [proyek_id, setProyekId] = 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')) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if(waspangId){ |
|
|
|
|
setUserIdAdd(waspangId) |
|
|
|
|
if (waspangId) { |
|
|
|
|
setUserIdAdd(waspangId) |
|
|
|
|
} |
|
|
|
|
},[waspangId]) |
|
|
|
|
}, [waspangId]) |
|
|
|
|
|
|
|
|
|
useEffect(()=> { |
|
|
|
|
useEffect(() => { |
|
|
|
|
let data = dataWaspangProyek || [] |
|
|
|
|
console.log("waspang id", waspangId) |
|
|
|
|
console.log("role_id", role_id) |
|
|
|
|
if(data.length > 0){ |
|
|
|
|
console.log("cek data waspang proyek",data) |
|
|
|
|
let dataObj = data[0] |
|
|
|
|
setType("edit") |
|
|
|
|
setProyekId(dataObj.proyek_id) |
|
|
|
|
if(dataObj.mulai){ |
|
|
|
|
setStartDate(moment(moment(dataObj.mulai))) |
|
|
|
|
}else{ |
|
|
|
|
setStartDate(moment(moment())) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(dataObj.mulai){ |
|
|
|
|
setEndDate(moment(moment(dataObj.akhir))) |
|
|
|
|
}else{ |
|
|
|
|
setEndDate(moment(moment())) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setUserId(dataObj.user_id) |
|
|
|
|
setId(dataObj.id) |
|
|
|
|
}else{ |
|
|
|
|
setProyekId(null) |
|
|
|
|
if (data.length > 0) { |
|
|
|
|
let dataObj = data[0] |
|
|
|
|
setType("edit") |
|
|
|
|
setProyekId(dataObj.proyek_id) |
|
|
|
|
if (dataObj.mulai) { |
|
|
|
|
setStartDate(moment(moment(dataObj.mulai))) |
|
|
|
|
} else { |
|
|
|
|
setStartDate(moment(moment())) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (dataObj.mulai) { |
|
|
|
|
setEndDate(moment(moment(dataObj.akhir))) |
|
|
|
|
} else { |
|
|
|
|
setEndDate(moment(moment())) |
|
|
|
|
setType("add") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setUserId(dataObj.user_id) |
|
|
|
|
setId(dataObj.id) |
|
|
|
|
} else { |
|
|
|
|
setProyekId(null) |
|
|
|
|
setStartDate(moment(moment())) |
|
|
|
|
setEndDate(moment(moment())) |
|
|
|
|
setType("add") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(parseInt(role_id)===2){ |
|
|
|
|
setProyekId(parseInt(proyekId)) |
|
|
|
|
setDisableSelectProyek(true) |
|
|
|
|
|
|
|
|
|
if (parseInt(role_id) === 2) { |
|
|
|
|
setProyekId(parseInt(proyekId)) |
|
|
|
|
setDisableSelectProyek(true) |
|
|
|
|
} |
|
|
|
|
},[dataWaspangProyek,openDialog]) |
|
|
|
|
}, [dataWaspangProyek, openDialog]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if(parseInt(role_id)===2){ |
|
|
|
|
setProyekId(parseInt(proyekId)) |
|
|
|
|
setDisableSelectProyek(true) |
|
|
|
|
if (parseInt(role_id) === 2) { |
|
|
|
|
setProyekId(parseInt(proyekId)) |
|
|
|
|
setDisableSelectProyek(true) |
|
|
|
|
} |
|
|
|
|
},[role_id]) |
|
|
|
|
}, [role_id]) |
|
|
|
|
const handleCancel = () => { |
|
|
|
|
closeDialog('cancel', 'none') |
|
|
|
|
setId(0) |
|
|
|
@ -77,13 +76,13 @@ const DialogProyek = ({openDialog, closeDialog, toggleDialog, dataWaspangProyek,
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const setupOption = () => { |
|
|
|
|
return( |
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
{dataProyek.map((val, index)=> { |
|
|
|
|
return( |
|
|
|
|
<Option key={index} value={val.id}>{val.nama}</Option> |
|
|
|
|
) |
|
|
|
|
})} |
|
|
|
|
{dataProyek.map((val, index) => { |
|
|
|
|
return ( |
|
|
|
|
<Option key={index} value={val.id}>{val.nama}</Option> |
|
|
|
|
) |
|
|
|
|
})} |
|
|
|
|
</> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
@ -97,53 +96,53 @@ const DialogProyek = ({openDialog, closeDialog, toggleDialog, dataWaspangProyek,
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleSave = () => { |
|
|
|
|
let data ={ |
|
|
|
|
type, |
|
|
|
|
mulai:startDate, |
|
|
|
|
akhir:endDate, |
|
|
|
|
proyek_id, |
|
|
|
|
user_id |
|
|
|
|
} |
|
|
|
|
let data = { |
|
|
|
|
type, |
|
|
|
|
mulai: startDate, |
|
|
|
|
akhir: endDate, |
|
|
|
|
proyek_id, |
|
|
|
|
user_id |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(type==="add"){ |
|
|
|
|
data['user_id'] = userIdAdd |
|
|
|
|
} |
|
|
|
|
if (type === "add") { |
|
|
|
|
data['user_id'] = userIdAdd |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(type==="edit"){ |
|
|
|
|
data['id'] = id |
|
|
|
|
} |
|
|
|
|
if (type === "edit") { |
|
|
|
|
data['id'] = id |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
closeDialog("save", data) |
|
|
|
|
closeDialog("save", data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const renderForm = () => { |
|
|
|
|
return( |
|
|
|
|
<Form>
|
|
|
|
|
return ( |
|
|
|
|
<Form> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Proyek</Label> |
|
|
|
|
{/* <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}> |
|
|
|
|
{setupOption()} |
|
|
|
|
</Select> |
|
|
|
|
</FormGroup> |
|
|
|
|
<Label className="capitalize">Proyek</Label> |
|
|
|
|
{/* <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}> |
|
|
|
|
{setupOption()} |
|
|
|
|
</Select> |
|
|
|
|
</FormGroup> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Tanggal Mulai</Label> |
|
|
|
|
<DatePicker style={{width:"100%"}} value={startDate} onChange={handleStartDate} allowClear={false} /> |
|
|
|
|
<Label className="capitalize">Tanggal Mulai</Label> |
|
|
|
|
<DatePicker style={{ width: "100%" }} value={startDate} onChange={handleStartDate} allowClear={false} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Tanggal</Label> |
|
|
|
|
<DatePicker style={{width:"100%"}} value={endDate} onChange={handleEndDate} allowClear={false} /> |
|
|
|
|
<Label className="capitalize">Tanggal</Label> |
|
|
|
|
<DatePicker style={{ width: "100%" }} value={endDate} onChange={handleEndDate} allowClear={false} /> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Form> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<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> |
|
|
|
|
{renderForm()} |
|
|
|
|
{renderForm()} |
|
|
|
|
</ModalBody> |
|
|
|
|
<ModalFooter> |
|
|
|
|
<Button color="primary" onClick={() => handleSave()}>Save</Button>{' '} |
|
|
|
@ -151,7 +150,7 @@ const DialogProyek = ({openDialog, closeDialog, toggleDialog, dataWaspangProyek,
|
|
|
|
|
</ModalFooter> |
|
|
|
|
</Modal> |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default DialogProyek; |