B6: SPA navigation after case creation (useNavigate instead of window.location.href)
B7: stop AdminDashboard refetching the case list on selection change selectedCaseId was both read and written inside the list-loading effect and listed in its deps, causing a second fetch on first render and after every filter reset. Auto-select now uses a functional state update, so the effect no longer depends on selectedCaseId; editForm stays in sync via the existing selectedCase effect.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import React, { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import Step1Child from "./Step1Child";
|
||||
import Step2Health from "./Step2Health";
|
||||
import Step2bPsychotype from "./Step2bPsychotype";
|
||||
@@ -16,6 +17,7 @@ const INITIAL_DATA = {
|
||||
};
|
||||
|
||||
const CaseForm = ({ isMobile = false }) => {
|
||||
const navigate = useNavigate();
|
||||
const [currentStep, setCurrentStep] = useState(1);
|
||||
const [formData, setFormData] = useState(INITIAL_DATA);
|
||||
const [errors, setErrors] = useState([]);
|
||||
@@ -116,10 +118,11 @@ const CaseForm = ({ isMobile = false }) => {
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
// Перенаправляем на страницу анализа с ID карточки
|
||||
window.location.href = `/analysis/${result.id}`;
|
||||
|
||||
|
||||
// Перенаправляем на страницу анализа с ID карточки.
|
||||
// SPA-переход: полная перезагрузка теряла состояние приложения.
|
||||
navigate(`/analysis/${result.id}`);
|
||||
|
||||
} catch (err) {
|
||||
setErrors([err.message || "Ошибка при отправке данных"]);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user