active links in nav, delete report, loaders in report, changes routes

This commit is contained in:
Mikola 2024-02-07 18:54:55 +03:00
parent b75b846335
commit 1fd6a73652
6 changed files with 51 additions and 30 deletions

View File

@ -9,7 +9,6 @@ import { urlForLocal } from "@utils/helper";
import avatarMok from "assets/images/avatarMok.png"; import avatarMok from "assets/images/avatarMok.png";
export const Navigation = () => { export const Navigation = () => {
const profileInfo = useSelector(getProfileInfo); const profileInfo = useSelector(getProfileInfo);
const currentPath = window.location.pathname; const currentPath = window.location.pathname;
const [user] = useState( const [user] = useState(
@ -81,7 +80,7 @@ export const Navigation = () => {
key={index} key={index}
end end
to={link.path === "/Quiz" ? link.path : `/profile${link.path}`} to={link.path === "/Quiz" ? link.path : `/profile${link.path}`}
className={currentPath. includes(link.path) ? 'active' : ''} className={currentPath.includes(link.path) ? "active" : ""}
> >
{link.name} {link.name}
</NavLink> </NavLink>

View File

@ -98,7 +98,9 @@ export const ProfileCalendarComponent = React.memo(
if (userId) { if (userId) {
return `/profile/calendar/view/${date.created_at}/${userId}`; return `/profile/calendar/view/${date.created_at}/${userId}`;
} }
return `/profile/calendar/view/${date.created_at}/${localStorage.getItem("id")}`; return `/profile/calendar/view/${
date.created_at
}/${localStorage.getItem("id")}`;
} }
} }
@ -282,15 +284,15 @@ export const ProfileCalendarComponent = React.memo(
? `${getCorrectDate(startDate)} - ${getCorrectDate(endDate)}` ? `${getCorrectDate(startDate)} - ${getCorrectDate(endDate)}`
: `${getCorrectDate(endDate)} - ${getCorrectDate(startDate)}` : `${getCorrectDate(endDate)} - ${getCorrectDate(startDate)}`
: activePeriod : activePeriod
? "Выберите диапазон на календаре" ? "Выберите диапазон на календаре"
: "Выбрать диапазон"} : "Выбрать диапазон"}
</span> </span>
<span> <span>
{totalRangeHours {totalRangeHours
? `${totalRangeHours} ${hourOfNum(totalRangeHours)}` ? `${totalRangeHours} ${hourOfNum(totalRangeHours)}`
: endDate : endDate
? "0 часов" ? "0 часов"
: ""} : ""}
</span> </span>
{endDate && ( {endDate && (
<BaseButton <BaseButton

View File

@ -87,12 +87,12 @@ const ReportForm = () => {
}; };
const handler = () => { const handler = () => {
setIsFetching(true) setIsFetching(true);
for (let input of inputs) { for (let input of inputs) {
if (!input.task || !input.hours_spent) { if (!input.task || !input.hours_spent) {
setReportSuccess("Заполните задачи"); setReportSuccess("Заполните задачи");
setTimeout(() => setReportSuccess(""), 2000); setTimeout(() => setReportSuccess(""), 2000);
setIsFetching(false) setIsFetching(false);
return; return;
} }
} }
@ -294,15 +294,16 @@ const ReportForm = () => {
<div className="row"> <div className="row">
<div className="col-12"> <div className="col-12">
<div className="report-form__footer"> <div className="report-form__footer">
{isFetching ? {isFetching ? (
<Loader style={'green'} /> : <Loader style={"green"} />
) : (
<button <button
className="report-form__footer-btn" className="report-form__footer-btn"
onClick={() => handler()} onClick={() => handler()}
> >
Отпаравить Отпаравить
</button> </button>
} )}
<p className="report-form__footer-text"> <p className="report-form__footer-text">
Всего за день:{" "} Всего за день:{" "}
<span> <span>

View File

@ -80,7 +80,9 @@ export const ShortReport = () => {
<h2 className="viewReport__title"> <h2 className="viewReport__title">
Ваши отчеты - <span>просмотр отчета за день</span> Ваши отчеты - <span>просмотр отчета за день</span>
</h2> </h2>
<Link to={`/profile/calendar/view/${dateCreate}`}>Посмотреть подробный отчет</Link> <Link to={`/profile/calendar/view/${dateCreate}`}>
Посмотреть подробный отчет
</Link>
</div> </div>
<div className="viewReport__bar"> <div className="viewReport__bar">

View File

@ -9,7 +9,11 @@ export const CardAvailableTest = ({ title, description, path, status }) => {
return ( return (
<div className="card-available-test"> <div className="card-available-test">
<Link <Link
to={status === 2 ? `/profile/quiz/report/${path}` : `/profile/quiz/test/${path}`} to={
status === 2
? `/profile/quiz/report/${path}`
: `/profile/quiz/test/${path}`
}
aria-disabled={true} aria-disabled={true}
className="card-available-test__container" className="card-available-test__container"
style={ style={

View File

@ -27,11 +27,11 @@ export const ViewReport = () => {
const [taskText, setTaskText] = useState([]); const [taskText, setTaskText] = useState([]);
const [difficulties, setDifficulties] = useState([]); const [difficulties, setDifficulties] = useState([]);
const [tomorrowTask, setTomorrowTask] = useState([]); const [tomorrowTask, setTomorrowTask] = useState([]);
const [taskId, setTaskId] = useState('') const [taskId, setTaskId] = useState("");
const [totalHours, setTotalHours] = useState(0); const [totalHours, setTotalHours] = useState(0);
const [currentDay] = useState(new Date()); const [currentDay] = useState(new Date());
const [loader, setLoader] = useState(false); const [loader, setLoader] = useState(false);
const [deleteLoader, setDeleteLoader] = useState(false) const [deleteLoader, setDeleteLoader] = useState(false);
function getReportFromDate(day) { function getReportFromDate(day) {
setLoader(true); setLoader(true);
@ -41,7 +41,7 @@ export const ViewReport = () => {
apiRequest(`reports/find-by-date?user_id=${params.id}&date=${day}`).then( apiRequest(`reports/find-by-date?user_id=${params.id}&date=${day}`).then(
(res) => { (res) => {
let spendTime = 0; let spendTime = 0;
setTaskId(res[0]?.id) setTaskId(res[0]?.id);
for (const item of res) { for (const item of res) {
if (item.difficulties) { if (item.difficulties) {
setDifficulties((prevArray) => [...prevArray, item.difficulties]); setDifficulties((prevArray) => [...prevArray, item.difficulties]);
@ -69,13 +69,13 @@ export const ViewReport = () => {
} }
function deleteReport() { function deleteReport() {
setDeleteLoader(true) setDeleteLoader(true);
apiRequest(`reports/delete?id=${taskId}`, { apiRequest(`reports/delete?id=${taskId}`, {
method: "DELETE" method: "DELETE"
}).then((res) => { }).then((res) => {
setDeleteLoader(false) setDeleteLoader(false);
if (res) { if (res) {
window.location.replace("/profile/calendar") window.location.replace("/profile/calendar");
} }
}); });
} }
@ -125,23 +125,32 @@ export const ViewReport = () => {
<img src={arrow} alt="#" /> <img src={arrow} alt="#" />
<p>Вернуться</p> <p>Вернуться</p>
</Link> </Link>
{localStorage.getItem("role_status") !== "18" && {localStorage.getItem("role_status") !== "18" && (
<div className="viewReport__bar"> <div className="viewReport__bar">
<button className="viewReport__bar__edit"> <button className="viewReport__bar__edit">Редактировать</button>
Редактировать {deleteLoader ? (
</button> <Loader style={"green"} />
{deleteLoader ? <Loader style={'green'} /> : ) : (
<button onClick={deleteReport} className={taskText.length ? "viewReport__bar__delete" : "viewReport__bar__delete disable"}> <button
onClick={deleteReport}
className={
taskText.length
? "viewReport__bar__delete"
: "viewReport__bar__delete disable"
}
>
Удалить отчет Удалить отчет
</button> </button>
} )}
</div> </div>
} )}
</div> </div>
<div className="viewReport__switch-date"> <div className="viewReport__switch-date">
<div onClick={() => previousDay()}> <div onClick={() => previousDay()}>
<Link <Link
to={`/profile/calendar/view/${getCreatedDate(previousReportDay)}/${params.id}`} to={`/profile/calendar/view/${getCreatedDate(
previousReportDay
)}/${params.id}`}
> >
<div className="viewReport__switch-date__prev switch-date"> <div className="viewReport__switch-date__prev switch-date">
<img src={arrowSwitchDate} alt="arrow" /> <img src={arrowSwitchDate} alt="arrow" />
@ -157,7 +166,11 @@ export const ViewReport = () => {
getCreatedDate(currentDay) === params.date ? "disable" : "" getCreatedDate(currentDay) === params.date ? "disable" : ""
}`} }`}
> >
<Link to={`/profile/calendar/view/${getCreatedDate(nextReportDay)}/${params.id}`}> <Link
to={`/profile/calendar/view/${getCreatedDate(nextReportDay)}/${
params.id
}`}
>
<div className={`viewReport__switch-date__next switch-date`}> <div className={`viewReport__switch-date__next switch-date`}>
<img src={arrowSwitchDate} alt="arrow" /> <img src={arrowSwitchDate} alt="arrow" />
</div> </div>