This commit is contained in:
Андрей Дувакин 2024-10-07 19:06:02 +05:00
parent 7e2799e1ac
commit 0b7743bb77

View File

@ -1,4 +1,4 @@
import React, { useState } from "react"; import React, { useState, useEffect } from "react";
import DatePicker from "react-datepicker"; import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css"; import "react-datepicker/dist/react-datepicker.css";
@ -7,6 +7,7 @@ const AddOrderModal = ({ show, onHide, onSubmit }) => {
const [robotsCount, setRobotsCount] = useState(100); const [robotsCount, setRobotsCount] = useState(100);
const [formError, setFormError] = useState(""); const [formError, setFormError] = useState("");
const getMinDate = () => {
const minDate = new Date(); const minDate = new Date();
minDate.setMonth(minDate.getMonth() + 1); minDate.setMonth(minDate.getMonth() + 1);
@ -14,6 +15,15 @@ const AddOrderModal = ({ show, onHide, onSubmit }) => {
minDate.setFullYear(minDate.getFullYear() + 1); minDate.setFullYear(minDate.getFullYear() + 1);
} }
return minDate;
};
useEffect(() => {
if (show) {
setDeadline(getMinDate());
}
}, [show]);
const handleSubmit = () => { const handleSubmit = () => {
if (!deadline || robotsCount < 100 || robotsCount % 100 !== 0) { if (!deadline || robotsCount < 100 || robotsCount % 100 !== 0) {
setFormError( setFormError(
@ -85,7 +95,7 @@ const AddOrderModal = ({ show, onHide, onSubmit }) => {
className="form-control" className="form-control"
dateFormat="P" dateFormat="P"
placeholderText="Выберите дату дедлайна" placeholderText="Выберите дату дедлайна"
minDate={minDate} minDate={getMinDate()}
/> />
</div> </div>
</div> </div>