|
|
@@ -1,7 +1,7 @@
|
|
|
import React, { Component } from "react";
|
|
|
import ContentWrapper from "@/components/Layout/ContentWrapper";
|
|
|
import { Card, CardBody, CardHeader, CardTitle, Button, Row, Col, FormGroup, Input } from "reactstrap";
|
|
|
-import { getPelaporan, getOneLaporan, addStatus, removeLaporan, activeLaporan, changeRoleData } from "@/actions/pelaporan";
|
|
|
+import { getPelaporan, getOneLaporan, updateLaporan } from "@/actions/pelaporan";
|
|
|
import { updateJadwal } from "@/actions/penjadwalan";
|
|
|
import DetailLaporan from "@/components/Main/DetailLaporan";
|
|
|
import Link from "next/link";
|
|
|
@@ -67,10 +67,8 @@ class Calendar extends Component {
|
|
|
async componentDidMount() {
|
|
|
const { token, query } = this.props;
|
|
|
|
|
|
- const dataLaporan = await getPelaporan(token, { jadwal: true });
|
|
|
-
|
|
|
const laporan = await getOneLaporan(token, query.id);
|
|
|
-
|
|
|
+ const dataLaporan = await getPelaporan(token, { jadwal: true });
|
|
|
this.setState({ dataLaporan });
|
|
|
this.getDataEvent();
|
|
|
this.defaultStatus();
|
|
|
@@ -82,6 +80,10 @@ class Calendar extends Component {
|
|
|
this.setState({ externalEvents: [{ id: query.id, color, name: `Jadwal Pemeriksaan - No.Laporan : ${laporan.data.no_laporan} - ${laporan.data.pt.nama}`, allDay: true }] });
|
|
|
}
|
|
|
|
|
|
+ componentShouldUpdate(nextProps, nextState) {
|
|
|
+ return nextState.dataLaporan !== this.state.dataLaporan;
|
|
|
+ }
|
|
|
+
|
|
|
getStatus = () => (this.props.user.role.id === 2021 ? statusLLDIKTI : status);
|
|
|
|
|
|
getDataEvent = () => {
|
|
|
@@ -113,7 +115,7 @@ class Calendar extends Component {
|
|
|
};
|
|
|
|
|
|
handleEventCalendar = async (data) => {
|
|
|
- const { token, query } = this.props;
|
|
|
+ const { query, token } = this.props;
|
|
|
const { id } = query;
|
|
|
const { laporan } = this.state;
|
|
|
const warna = "#" + Math.floor(Math.random() * 16777215).toString(16);
|
|
|
@@ -131,13 +133,9 @@ class Calendar extends Component {
|
|
|
success: "Success",
|
|
|
error: "Error",
|
|
|
});
|
|
|
- // this.state.dataEvent.push({
|
|
|
- // title: data.judul,
|
|
|
- // start: new Date(data.dari_tanggal),
|
|
|
- // end: new Date(data.sampai_tanggal),
|
|
|
- // backgroundColor: warna,
|
|
|
- // borderColor: warna,
|
|
|
- // });
|
|
|
+ const dataLaporan = await getPelaporan(token, { jadwal: true });
|
|
|
+ this.setState({ dataLaporan });
|
|
|
+ this.getDataEvent();
|
|
|
};
|
|
|
|
|
|
defaultStatus = async () => {
|
|
|
@@ -148,26 +146,24 @@ class Calendar extends Component {
|
|
|
handleChangeSelect = (selectedOption) => this.setState({ selectedOption });
|
|
|
|
|
|
handleSimpan = async (e) => {
|
|
|
- const { selectedOption } = this.state;
|
|
|
- const { ptId, number } = this.props.query;
|
|
|
- this.setState({ selectedOption });
|
|
|
- const id = toast.loading("Please wait...");
|
|
|
- if (selectedOption.value === this.getStatus()[1].value) {
|
|
|
- const roleId = this.props.user.peran[0].peran.id;
|
|
|
- await changeRoleData({ number, ptId }, { role_data: roleId === 2021 ? "dikti" : "lldikti" });
|
|
|
- const statusData = roleId === 2021 ? status : statusLLDIKTI;
|
|
|
- await addStatus({ number, ptId }, { status: statusData[0].value });
|
|
|
- toast.update(id, { render: "All is good", type: "success", isLoading: false });
|
|
|
- Router.push("/app/penjadwalan");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (selectedOption.value === this.getStatus()[2].value) {
|
|
|
- await removeLaporan({ number, ptId });
|
|
|
- } else if (!this.state.laporan.data[0].active) {
|
|
|
- await activeLaporan({ number, ptId });
|
|
|
+ const toastid = toast.loading("Please wait...");
|
|
|
+ try {
|
|
|
+ const { selectedOption } = this.state;
|
|
|
+ const { user, token, query } = this.props;
|
|
|
+ const { id } = query;
|
|
|
+ this.setState({ selectedOption });
|
|
|
+ if (selectedOption.value === this.getStatus()[1].value) {
|
|
|
+ await updateLaporan(token, id, { role_data: user.role.id === 2020 ? "lldikti" : "dikti" });
|
|
|
+ Router.push("/app/penjadwalan");
|
|
|
+ }
|
|
|
+ if (selectedOption.value === this.getStatus()[2].value) {
|
|
|
+ await updateLaporan(token, id, { aktif: "false" });
|
|
|
+ Router.push("/app/penjadwalan");
|
|
|
+ }
|
|
|
+ toast.update(toastid, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
|
|
|
+ } catch (error) {
|
|
|
+ toast.update(toastid, { render: "All is not good", type: "error", isLoading: false, autoClose: true, closeButton: true });
|
|
|
}
|
|
|
- await addStatus({ number, ptId }, { status: selectedOption.value });
|
|
|
- toast.update(id, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
|
|
|
};
|
|
|
|
|
|
render() {
|
|
|
@@ -228,14 +224,14 @@ class Calendar extends Component {
|
|
|
<Formik
|
|
|
enableReinitialize={true}
|
|
|
initialValues={{
|
|
|
- judul: laporan.data?.jadwal.judul || "",
|
|
|
- dari_tanggal: moment(laporan.data?.jadwal.dari_tanggal) || new Date(),
|
|
|
- sampai_tanggal: moment(laporan.data?.jadwal.sampai_tanggal) || new Date(),
|
|
|
+ judul: laporan.data?.jadwal?.judul || "",
|
|
|
+ dari_tanggal: moment(laporan.data?.jadwal?.dari_tanggal) || "",
|
|
|
+ sampai_tanggal: moment(laporan.data?.jadwal?.sampai_tanggal) || "",
|
|
|
}}
|
|
|
validationSchema={jadwalSchema}
|
|
|
onSubmit={this.handleEventCalendar}
|
|
|
>
|
|
|
- {({ isSubmitting }) => (
|
|
|
+ {() => (
|
|
|
<Form>
|
|
|
<FormGroup>
|
|
|
<label className="col-form-label">Judul</label>
|
|
|
@@ -276,7 +272,7 @@ class Calendar extends Component {
|
|
|
</FormGroup>
|
|
|
<FormGroup row>
|
|
|
<div className="col-xl-12">
|
|
|
- <Button color="primary" block type="submit" disabled={isSubmitting}>
|
|
|
+ <Button color="primary" block type="submit">
|
|
|
Simpan Jadwal
|
|
|
</Button>
|
|
|
</div>
|