fix: back button uses browser history instead of hardcoded /dashboard

This commit is contained in:
root 2026-05-27 14:06:54 +00:00
parent db555bbf55
commit 0930ea9c26
1 changed files with 13 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import React from "react";
import { useNavigate, useParams } from "react-router-dom";
import { useNavigate, useParams, useLocation } from "react-router-dom";
import { OrderDetailPanel } from "../components/orders/OrderDetailPanel";
import { Button } from "../components/UI/Button";
import { Panel } from "../components/UI/Panel";
@ -10,6 +10,7 @@ import { useOrderGroups } from "../hooks/useOrderGroups";
export const GroupDetailPage = () => {
const { groupId } = useParams();
const navigate = useNavigate();
const location = useLocation();
const { user } = useAuth();
const userRole = user?.role;
@ -48,10 +49,19 @@ export const GroupDetailPage = () => {
allOrderGroups.find((g) => g.id === selectedOrderGroupId) ||
null;
// Preserve the tab the user came from when going back
const handleGoBack = React.useCallback(() => {
if (window.history.length > 1) {
navigate(-1);
} else {
navigate("/dashboard");
}
}, [navigate]);
return (
<div className="mx-auto w-full max-w-3xl space-y-5">
<div className="flex items-center justify-between">
<Button variant="ghost" onClick={() => navigate("/dashboard")} className="text-sm">
<Button variant="ghost" onClick={handleGoBack} className="text-sm">
Назад к списку
</Button>
</div>
@ -74,4 +84,4 @@ export const GroupDetailPage = () => {
)}
</div>
);
};
};