Browse Source

fix endline

pull/1/head
wahyu 1 year ago
parent
commit
3f4b3da3ff
  1. 650
      src/views/SimproV2/CreatedProyek/DialogForm.js

650
src/views/SimproV2/CreatedProyek/DialogForm.js

@ -1,325 +1,325 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap"; import { Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap";
import { Button, Form, FormGroup, Label, Input, Col, Row } from "reactstrap"; import { Button, Form, FormGroup, Label, Input, Col, Row } from "reactstrap";
import { DatePicker, Tooltip, Select } from "antd"; import { DatePicker, Tooltip, Select } from "antd";
import axios from "../../../const/interceptorApi"; import axios from "../../../const/interceptorApi";
import moment from "moment"; import moment from "moment";
import { import {
NotificationContainer, NotificationContainer,
NotificationManager, NotificationManager,
} from "react-notifications"; } from "react-notifications";
import "antd/dist/antd.css"; import "antd/dist/antd.css";
import { formatNumber } from "../../../const/CustomFunc"; import { formatNumber } from "../../../const/CustomFunc";
import { import {
TYPE_PROYEK, TYPE_PROYEK,
USER_LIST, USER_LIST,
BASE_SIMPRO_LUMEN, BASE_SIMPRO_LUMEN,
} from "../../../const/ApiConst"; } from "../../../const/ApiConst";
const { Option } = Select; const { Option } = Select;
const DialogForm = ({ const DialogForm = ({
openDialog, openDialog,
closeDialog, closeDialog,
toggleDialog, toggleDialog,
idTask, idTask,
dataTypeProyek, dataTypeProyek,
dataPM, dataPM,
}) => { }) => {
const token = localStorage.getItem("token"); const token = localStorage.getItem("token");
const HEADER = { const HEADER = {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
}; };
const [id, setId] = useState(0); const [id, setId] = useState(0);
const [name, setName] = useState(""); const [name, setName] = useState("");
const [shortName, setShortName] = useState(""); const [shortName, setShortName] = useState("");
const [description, setDescription] = useState(""); const [description, setDescription] = useState("");
const [biaya, setBiaya] = useState(""); const [biaya, setBiaya] = useState("");
const [typeProject, setTypeproject] = useState(null); const [typeProject, setTypeproject] = useState(null);
const [sdm, setSdm] = useState(0); const [sdm, setSdm] = useState(0);
const [pic, setPic] = useState(null); const [pic, setPic] = useState(null);
const [startDate, setStartDate] = useState(moment()); const [startDate, setStartDate] = useState(moment());
const [endDate, setEndDate] = useState(moment()); const [endDate, setEndDate] = useState(moment());
const [workArea, setWorkArea] = useState(""); const [workArea, setWorkArea] = useState("");
const [finance, setFinance] = useState(""); const [finance, setFinance] = useState("");
const [investor, setInvestor] = useState(""); const [investor, setInvestor] = useState("");
const [company, setCompany] = useState(""); const [company, setCompany] = useState("");
const handleGetdataIdproyek = async (id) => { const handleGetdataIdproyek = async (id) => {
const URL = `${BASE_SIMPRO_LUMEN}/project/edit/${id}`; const URL = `${BASE_SIMPRO_LUMEN}/project/edit/${id}`;
const result = await axios const result = await axios
.get(URL, HEADER) .get(URL, HEADER)
.then((res) => res) .then((res) => res)
.catch((err) => err.response); .catch((err) => err.response);
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
const val = result.data.data; const val = result.data.data;
setName(val.nama); setName(val.nama);
setShortName(val.kode_sortname); setShortName(val.kode_sortname);
setDescription(val.keterangan); setDescription(val.keterangan);
setBiaya(val.rencana_biaya ? formatNumber(val.rencana_biaya) : ""); setBiaya(val.rencana_biaya ? formatNumber(val.rencana_biaya) : "");
setTypeproject(val.type_proyek_id); setTypeproject(val.type_proyek_id);
setPic(val.pm_id); setPic(val.pm_id);
setStartDate(moment(val.mulai_proyek)); setStartDate(moment(val.mulai_proyek));
setEndDate(moment(val.akhir_proyek)); setEndDate(moment(val.akhir_proyek));
setWorkArea(val.area_kerja); setWorkArea(val.area_kerja);
setInvestor(val.investor); setInvestor(val.investor);
setCompany(val.company); setCompany(val.company);
setFinance(val.finance); setFinance(val.finance);
} else { } else {
NotificationManager.error(`Data proyek gagal di edit`, `Failed!!`); NotificationManager.error(`Data proyek gagal di edit`, `Failed!!`);
} }
}; };
const handleCLearData = () => { const handleCLearData = () => {
setName(""); setName("");
setShortName(""); setShortName("");
setBiaya(""); setBiaya("");
setTypeproject(null); setTypeproject(null);
setPic(null); setPic(null);
setStartDate(moment()); setStartDate(moment());
setEndDate(moment()); setEndDate(moment());
setDescription(""); setDescription("");
setInvestor(""); setInvestor("");
setFinance(""); setFinance("");
setWorkArea(""); setWorkArea("");
setCompany(""); setCompany("");
}; };
useEffect(() => { useEffect(() => {
if (idTask && idTask > 0) { if (idTask && idTask > 0) {
handleGetdataIdproyek(idTask); handleGetdataIdproyek(idTask);
} else { } else {
handleCLearData(); handleCLearData();
} }
}, [openDialog]); }, [openDialog]);
const handleSave = () => { const handleSave = () => {
let data = ""; let data = "";
if (idTask) { if (idTask) {
data = { data = {
id: idTask, id: idTask,
nama: name, nama: name,
kode_sortname: shortName, kode_sortname: shortName,
rencana_biaya: biaya.replace(".", ""), rencana_biaya: biaya.replace(".", ""),
mulai_proyek: startDate, mulai_proyek: startDate,
akhir_proyek: endDate, akhir_proyek: endDate,
type_proyek_id: parseInt(typeProject), type_proyek_id: parseInt(typeProject),
pm_id: pic, pm_id: pic,
investor, investor,
finance, finance,
company, company,
area_kerja: workArea, area_kerja: workArea,
keterangan: description, keterangan: description,
}; };
closeDialog("edit", data); closeDialog("edit", data);
} else { } else {
data = { data = {
nama: name, nama: name,
kode_sortname: shortName, kode_sortname: shortName,
rencana_biaya: biaya.replace(".", ""), rencana_biaya: biaya.replace(".", ""),
mulai_proyek: startDate, mulai_proyek: startDate,
akhir_proyek: endDate, akhir_proyek: endDate,
type_proyek_id: parseInt(typeProject), type_proyek_id: parseInt(typeProject),
pm_id: pic, pm_id: pic,
investor, investor,
finance, finance,
company, company,
area_kerja: workArea, area_kerja: workArea,
keterangan: description, keterangan: description,
}; };
closeDialog("add", data); closeDialog("add", data);
} }
handleCLearData(); handleCLearData();
}; };
const handleCancel = () => { const handleCancel = () => {
closeDialog("cancel", "none"); closeDialog("cancel", "none");
handleCLearData(); handleCLearData();
}; };
const onChangeTypeProject = (val) => { const onChangeTypeProject = (val) => {
setTypeproject(val); setTypeproject(val);
}; };
const onChangePm = (val) => { const onChangePm = (val) => {
setPic(val); setPic(val);
}; };
const handleDatePickerStart = (date, dateString) => { const handleDatePickerStart = (date, dateString) => {
setStartDate(date); setStartDate(date);
}; };
const handleDatePickerEnd = (date, dateString) => { const handleDatePickerEnd = (date, dateString) => {
setEndDate(date); setEndDate(date);
}; };
const renderForm = () => { const renderForm = () => {
return ( return (
<Form> <Form>
<Row> <Row>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">Project Name</Label> <Label className="capitalize">Project Name</Label>
<Input <Input
type="text" type="text"
value={name} value={name}
onChange={(e) => setName(e.target.value)} onChange={(e) => setName(e.target.value)}
placeholder={`Input project name...`} placeholder={`Input project name...`}
/> />
</FormGroup> </FormGroup>
</Col> </Col>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">Code / Short Name</Label> <Label className="capitalize">Code / Short Name</Label>
<Input <Input
type="text" type="text"
value={shortName} value={shortName}
onChange={(e) => setShortName(e.target.value)} onChange={(e) => setShortName(e.target.value)}
placeholder={`Input code / short name...`} placeholder={`Input code / short name...`}
/> />
</FormGroup> </FormGroup>
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">Project Type</Label> <Label className="capitalize">Project Type</Label>
<Select <Select
showSearch showSearch
value={typeProject} value={typeProject}
defaultValue={typeProject} defaultValue={typeProject}
onChange={onChangeTypeProject} onChange={onChangeTypeProject}
placeholder="Select project type" placeholder="Select project type"
style={{ width: "100%" }} style={{ width: "100%" }}
> >
{dataTypeProyek.map((res) => ( {dataTypeProyek.map((res) => (
<Option key={res.id} value={res.id}> <Option key={res.id} value={res.id}>
{res.name} {res.name}
</Option> </Option>
))} ))}
</Select> </Select>
</FormGroup> </FormGroup>
</Col> </Col>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">PM</Label> <Label className="capitalize">PM</Label>
<Select <Select
showSearch showSearch
value={pic} value={pic}
defaultValue={pic} defaultValue={pic}
onChange={onChangePm} onChange={onChangePm}
placeholder="Select PM" placeholder="Select PM"
style={{ width: "100%" }} style={{ width: "100%" }}
> >
{dataPM.map((res) => ( {dataPM.map((res) => (
<Option key={res.id} value={res.id}> <Option key={res.id} value={res.id}>
{res.name} {res.name}
</Option> </Option>
))} ))}
</Select> </Select>
</FormGroup> </FormGroup>
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">Start Date</Label> <Label className="capitalize">Start Date</Label>
<DatePicker <DatePicker
style={{ width: "100%" }} style={{ width: "100%" }}
value={startDate} value={startDate}
onChange={handleDatePickerStart} onChange={handleDatePickerStart}
/> />
</FormGroup> </FormGroup>
</Col> </Col>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">End Date</Label> <Label className="capitalize">End Date</Label>
<DatePicker <DatePicker
style={{ width: "100%" }} style={{ width: "100%" }}
value={endDate} value={endDate}
onChange={handleDatePickerEnd} onChange={handleDatePickerEnd}
/> />
</FormGroup> </FormGroup>
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">Work Area</Label> <Label className="capitalize">Work Area</Label>
<Input <Input
type="text" type="text"
value={workArea} value={workArea}
onChange={(e) => setWorkArea(e.target.value)} onChange={(e) => setWorkArea(e.target.value)}
placeholder={`Input work area...`} placeholder={`Input work area...`}
/> />
</FormGroup> </FormGroup>
</Col> </Col>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">Company</Label> <Label className="capitalize">Company</Label>
<Input <Input
type="text" type="text"
value={company} value={company}
onChange={(e) => setCompany(e.target.value)} onChange={(e) => setCompany(e.target.value)}
placeholder={`Input company...`} placeholder={`Input company...`}
/> />
</FormGroup> </FormGroup>
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">Budget</Label> <Label className="capitalize">Budget</Label>
<Input <Input
type="text" type="text"
value={biaya} value={biaya}
onChange={(e) => setBiaya(formatNumber(e.target.value))} onChange={(e) => setBiaya(formatNumber(e.target.value))}
placeholder={`Input planning cost...`} placeholder={`Input planning cost...`}
/> />
</FormGroup> </FormGroup>
</Col> </Col>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">Description</Label> <Label className="capitalize">Description</Label>
<Input <Input
type="textarea" type="textarea"
value={description} value={description}
onChange={(e) => setDescription(e.target.value)} onChange={(e) => setDescription(e.target.value)}
placeholder={`Input description...`} placeholder={`Input description...`}
/> />
</FormGroup> </FormGroup>
</Col> </Col>
</Row> </Row>
</Form> </Form>
); );
}; };
return ( return (
<> <>
<Modal size="lg" isOpen={openDialog} toggle={toggleDialog}> <Modal size="lg" isOpen={openDialog} toggle={toggleDialog}>
<ModalHeader className="capitalize" toggle={closeDialog}> <ModalHeader className="capitalize" toggle={closeDialog}>
{idTask ? `Update` : "Add"} Project {idTask ? `Update` : "Add"} Project
</ModalHeader> </ModalHeader>
<ModalBody>{renderForm()}</ModalBody> <ModalBody>{renderForm()}</ModalBody>
<ModalFooter> <ModalFooter>
<Button color="primary" onClick={() => handleSave()}> <Button color="primary" onClick={() => handleSave()}>
{idTask ? `Save` : "Add"} {idTask ? `Save` : "Add"}
</Button>{" "} </Button>{" "}
<Button <Button
className="capitalize" className="capitalize"
color="secondary" color="secondary"
onClick={() => handleCancel()} onClick={() => handleCancel()}
> >
Cancel Cancel
</Button> </Button>
</ModalFooter> </ModalFooter>
</Modal> </Modal>
</> </>
); );
}; };
export default DialogForm; export default DialogForm;

Loading…
Cancel
Save