2024-07-04 16:54:34 +03:00
|
|
|
import axios from "axios";
|
2024-07-04 22:59:20 +03:00
|
|
|
import { format } from "date-fns";
|
2024-07-04 16:54:34 +03:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import DatePicker from "react-datepicker";
|
|
|
|
import "react-datepicker/dist/react-datepicker.css";
|
|
|
|
|
2024-07-04 18:04:28 +03:00
|
|
|
import { apiRequest } from "@api/request";
|
|
|
|
|
2024-07-04 16:54:34 +03:00
|
|
|
import BaseButton from "@components/Common/BaseButton/BaseButton";
|
|
|
|
|
|
|
|
import "./modalTicketToReport.scss";
|
|
|
|
|
|
|
|
const ModalTicketToReport = ({ show, onClose, additionalData }) => {
|
|
|
|
const [date, setDate] = useState(new Date());
|
|
|
|
|
|
|
|
const handleSubmit = async () => {
|
2024-07-04 22:59:20 +03:00
|
|
|
const formattedDate = format(date, "yyyy-MM-dd");
|
2024-07-04 16:54:34 +03:00
|
|
|
const data = {
|
2024-07-04 22:59:20 +03:00
|
|
|
created_at: formattedDate,
|
2024-07-04 16:54:34 +03:00
|
|
|
...additionalData
|
|
|
|
};
|
2024-07-04 22:59:20 +03:00
|
|
|
console.log(data);
|
2024-07-04 16:54:34 +03:00
|
|
|
|
|
|
|
try {
|
2024-07-04 22:59:20 +03:00
|
|
|
await apiRequest("https://back.itguild.info/api/reports/create", {
|
|
|
|
method: "POST",
|
|
|
|
data: data
|
|
|
|
});
|
2024-07-04 16:54:34 +03:00
|
|
|
} catch (error) {
|
|
|
|
console.error("Error:", error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={`modal-report-backdrop ${show ? "show" : ""}`}
|
|
|
|
onClick={onClose}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className="modal-report-content"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
>
|
|
|
|
<div className="modal-report-close" onClick={onClose}></div>
|
|
|
|
<h2>Выгрузка в отчет</h2>
|
|
|
|
<div className="modal-report-date-picker">
|
|
|
|
<DatePicker
|
|
|
|
className="datePicker"
|
|
|
|
locale="ru"
|
|
|
|
selected={date}
|
|
|
|
onChange={(date) => setDate(date)}
|
|
|
|
dateFormat="dd/MM/yyyy"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="modal-report__buttons">
|
|
|
|
<BaseButton
|
|
|
|
styles={"button-add add-person-btn "}
|
|
|
|
onClick={handleSubmit}
|
|
|
|
>
|
|
|
|
Выгрузить в отчет
|
|
|
|
</BaseButton>
|
|
|
|
<BaseButton
|
|
|
|
styles={`button-add add-person-btn ${show ? "" : "disable"}`}
|
|
|
|
onClick={handleSubmit}
|
|
|
|
>
|
|
|
|
Выгрузить и перейти в отчет
|
|
|
|
</BaseButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ModalTicketToReport;
|