partner reg, fix employers bug, edit report

This commit is contained in:
Mikola
2024-02-09 17:59:19 +03:00
parent b43a6a1fcf
commit 4d2ccf91eb
9 changed files with 94 additions and 60 deletions

View File

@ -3,11 +3,11 @@ import React, { useEffect, useState } from "react";
import DatePicker, { registerLocale } from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import { useSelector } from "react-redux";
import { useDispatch } from "react-redux";
import { Link, Navigate, useNavigate } from "react-router-dom";
import { getReportDate, getEditReport } from "@redux/reportSlice";
import { getEditReport, getReportDate } from "@redux/reportSlice";
import { setEditReport } from "@redux/reportSlice";
import { useDispatch } from "react-redux";
import { apiRequest } from "@api/request";
@ -37,10 +37,9 @@ const ReportForm = () => {
}
const navigate = useNavigate();
const reportDate = useSelector(getReportDate);
const editReport = useSelector(getEditReport)
const editReport = useSelector(getEditReport);
const dispatch = useDispatch();
useEffect(() => {
initListeners();
}, []);
@ -48,15 +47,23 @@ const ReportForm = () => {
const [isFetching, setIsFetching] = useState(false);
const [reportSuccess, setReportSuccess] = useState("");
const [startDate, setStartDate] = useState(
reportDate || editReport ? new Date(reportDate ? reportDate._d : editReport.created_at) : new Date()
reportDate || editReport
? new Date(reportDate ? reportDate._d : editReport.created_at)
: new Date()
);
const [datePickerOpen, setDatePickerOpen] = useState(false);
const [inputs, setInputs] = useState(editReport ? editReport.task : [
{ task: "", hours_spent: "", minutes_spent: 0 }
]);
const [troublesInputValue, setTroublesInputValue] = useState(editReport ? editReport.difficulties :"");
const [scheduledInputValue, setScheduledInputValue] = useState(editReport ? editReport.tomorrow : "");
const [inputs, setInputs] = useState(
editReport
? editReport.task
: [{ task: "", hours_spent: "", minutes_spent: 0 }]
);
const [troublesInputValue, setTroublesInputValue] = useState(
editReport ? editReport.difficulties : ""
);
const [scheduledInputValue, setScheduledInputValue] = useState(
editReport ? editReport.tomorrow : ""
);
const addInput = () => {
setInputs((prev) => [
@ -118,7 +125,7 @@ const ReportForm = () => {
navigate("/profile/calendar");
}, 1000);
setIsFetching(false);
clearParams()
clearParams();
});
};
@ -148,17 +155,17 @@ const ReportForm = () => {
navigate("/profile/calendar");
}, 1000);
setIsFetching(false);
clearParams()
dispatch(setEditReport(""))
clearParams();
dispatch(setEditReport(""));
});
}
};
const clearParams = () => {
setInputs(() => []);
setTroublesInputValue("");
setScheduledInputValue("");
setInputs(() => [{ task: "", hours_spent: "", minutes_spent: 0 }]);
}
};
return (
<section className="report-form">
@ -173,7 +180,8 @@ const ReportForm = () => {
]}
/>
<h2 className="summary__title">
Ваши отчеты - <span>{editReport ? "редактировать отчет" : "добавить отчет"}</span>
Ваши отчеты -{" "}
<span>{editReport ? "редактировать отчет" : "добавить отчет"}</span>
</h2>
<div>
<div className="report__head">
@ -187,12 +195,14 @@ const ReportForm = () => {
<div className="report-form__content">
<div className="report-form__block">
<div className="report-form__block-title">
<h2>{editReport ? "Редактирование отчета за день" : "Добавление отчета за день"}</h2>
<h2>
{editReport
? "Редактирование отчета за день"
: "Добавление отчета за день"}
</h2>
<h3>Дата заполнения отчета:</h3>
</div>
<div
className="report-form__block-img"
>
<div className="report-form__block-img">
<img
className="report-form__calendar-icon"
src={calendarIcon}
@ -339,10 +349,10 @@ const ReportForm = () => {
<button
className="report-form__footer-btn"
onClick={() => {
if(editReport) {
handleEditReport()
if (editReport) {
handleEditReport();
} else {
handler()
handler();
}
}}
>