From 0b7743bb77e8ab70d1a3f60b4c0aeadb9c17bffe Mon Sep 17 00:00:00 2001 From: andrei Date: Mon, 7 Oct 2024 19:06:02 +0500 Subject: [PATCH] ._. --- src/components/AddOrderModal.jsx | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/components/AddOrderModal.jsx b/src/components/AddOrderModal.jsx index 3187c66..ec7f7e2 100644 --- a/src/components/AddOrderModal.jsx +++ b/src/components/AddOrderModal.jsx @@ -1,18 +1,28 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import DatePicker from "react-datepicker"; import "react-datepicker/dist/react-datepicker.css"; const AddOrderModal = ({ show, onHide, onSubmit }) => { const [deadline, setDeadline] = useState(new Date()); - const [robotsCount, setRobotsCount] = useState(100); + const [robotsCount, setRobotsCount] = useState(100); const [formError, setFormError] = useState(""); - const minDate = new Date(); - minDate.setMonth(minDate.getMonth() + 1); + const getMinDate = () => { + const minDate = new Date(); + minDate.setMonth(minDate.getMonth() + 1); - if (minDate.getMonth() === 0) { - minDate.setFullYear(minDate.getFullYear() + 1); - } + if (minDate.getMonth() === 0) { + minDate.setFullYear(minDate.getFullYear() + 1); + } + + return minDate; + }; + + useEffect(() => { + if (show) { + setDeadline(getMinDate()); + } + }, [show]); const handleSubmit = () => { if (!deadline || robotsCount < 100 || robotsCount % 100 !== 0) { @@ -85,7 +95,7 @@ const AddOrderModal = ({ show, onHide, onSubmit }) => { className="form-control" dateFormat="P" placeholderText="Выберите дату дедлайна" - minDate={minDate} + minDate={getMinDate()} />