Correction des redirections
This commit is contained in:
1 parent
a8781a9f62
commit
eb961cbed4
7 files changed
+80
-26
No files matched your search
@@ -2,7 +2,7 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { usePagination } from '../hooks/usePagination.js';
|
||||
import Pagination from '../components/Pagination.jsx';
|
||||
import PageIcon from '../components/PageIcon.jsx';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { api } from '../api.js';
|
||||
import InvSelect from '../components/InvSelect.jsx';
|
||||
import { useInvestisseur } from '../context/InvestisseurContext.jsx';
|
||||
@@ -275,8 +275,9 @@ function dayOfMonth(isoDate) {
|
||||
export default function Investissements() {
|
||||
const { activeId, activeView, investisseurs } = useInvestisseur();
|
||||
const { displayMode } = useUi();
|
||||
const { search } = useLocation();
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const platsRef = useRef([]);
|
||||
const lastValidSouscriptionRef = useRef('');
|
||||
|
||||
@@ -286,12 +287,35 @@ export default function Investissements() {
|
||||
const [plats, setPlats] = useState([]);
|
||||
const [comptesCourants, setComptesCourants] = useState([]);
|
||||
const [comptesInvestisseur, setComptesInvestisseur] = useState([]);
|
||||
const [activeTab, setActiveTab] = useState('plateformes');
|
||||
/* activeTab, filter, platYear → URL params pour survivre au retour arrière */
|
||||
const activeTab = searchParams.get('tab') || 'plateformes';
|
||||
const setActiveTab = (tab) => setSearchParams(p => { const n = new URLSearchParams(p); n.set('tab', tab); return n; }, { replace: true });
|
||||
const [listFocused, setListFocused] = useState(false);
|
||||
const [filter, setFilter] = useState({ statut: '', plateforme_id: '', categorie_inv_id: '', secteur_inv_id: '', year: '', month: '' });
|
||||
const filter = {
|
||||
statut: searchParams.get('statut') || '',
|
||||
plateforme_id: searchParams.get('pid') || '',
|
||||
categorie_inv_id: searchParams.get('cat') || '',
|
||||
secteur_inv_id: searchParams.get('sect') || '',
|
||||
year: searchParams.get('yr') || '',
|
||||
month: searchParams.get('mo') || '',
|
||||
};
|
||||
const setFilter = (updater) => setSearchParams(p => {
|
||||
const cur = { statut: p.get('statut')||'', plateforme_id: p.get('pid')||'', categorie_inv_id: p.get('cat')||'', secteur_inv_id: p.get('sect')||'', year: p.get('yr')||'', month: p.get('mo')||'' };
|
||||
const nf = typeof updater === 'function' ? updater(cur) : updater;
|
||||
const n = new URLSearchParams(p);
|
||||
['statut','pid','cat','sect','yr','mo'].forEach(k => n.delete(k));
|
||||
if (nf.statut) n.set('statut', nf.statut);
|
||||
if (nf.plateforme_id) n.set('pid', nf.plateforme_id);
|
||||
if (nf.categorie_inv_id) n.set('cat', nf.categorie_inv_id);
|
||||
if (nf.secteur_inv_id) n.set('sect', nf.secteur_inv_id);
|
||||
if (nf.year) n.set('yr', nf.year);
|
||||
if (nf.month) n.set('mo', nf.month);
|
||||
return n;
|
||||
}, { replace: true });
|
||||
const [categoriesInv, setCategoriesInv] = useState([]);
|
||||
const [secteursInv, setSecteursInv] = useState([]);
|
||||
const [platYear, setPlatYear] = useState(String(new Date().getFullYear()));
|
||||
const platYear = searchParams.get('platYear') || String(new Date().getFullYear());
|
||||
const setPlatYear = (y) => setSearchParams(p => { const n = new URLSearchParams(p); n.set('platYear', y); return n; }, { replace: true });
|
||||
const [modalOpen, setModalOpen] = useState(false);
|
||||
const [editingId, setEditingId] = useState(null);
|
||||
const [form, setForm] = useState(empty);
|
||||
@@ -605,8 +629,8 @@ export default function Investissements() {
|
||||
/* ── Ouverture auto depuis le bouton global ── */
|
||||
const pendingNew = useRef(false);
|
||||
useEffect(() => {
|
||||
if (new URLSearchParams(search).get('new') !== '1') return;
|
||||
navigate('/investissements', { replace: true });
|
||||
if (searchParams.get('new') !== '1') return;
|
||||
navigate({ pathname: '/investissements', search: (() => { const n = new URLSearchParams(searchParams); n.delete('new'); return n.toString() ? '?' + n.toString() : ''; })() }, { replace: true });
|
||||
if (plats.length > 0) {
|
||||
setEditingId(null);
|
||||
setForm({ ...empty });
|
||||
@@ -615,7 +639,7 @@ export default function Investissements() {
|
||||
} else {
|
||||
pendingNew.current = true;
|
||||
}
|
||||
}, [search]); /* eslint-disable-next-line */
|
||||
}, [searchParams]); /* eslint-disable-next-line */
|
||||
|
||||
useEffect(() => {
|
||||
if (!pendingNew.current || !plats.length) return;
|
||||
@@ -746,7 +770,7 @@ export default function Investissements() {
|
||||
|
||||
const hasFilter = !!(filter.statut || filter.plateforme_id || filter.categorie_inv_id || filter.secteur_inv_id || filter.year || filter.month);
|
||||
const netMode = displayMode === 'net';
|
||||
const clearFilter = () => setFilter({ statut: '', plateforme_id: '', categorie_inv_id: '', secteur_inv_id: '', year: '', month: '' });
|
||||
const clearFilter = () => setSearchParams(p => { const n = new URLSearchParams(p); ['statut','pid','cat','sect','yr','mo'].forEach(k => n.delete(k)); return n; }, { replace: true });
|
||||
const multiDetenteur = new Set(plats.map(p => p.investisseur_id)).size > 1;
|
||||
|
||||
if (!loading && plats.length === 0) return (
|
||||
@@ -1186,7 +1210,7 @@ export default function Investissements() {
|
||||
const capRestant = Math.max(0, capInv - (r.capital_rembourse || 0));
|
||||
return (
|
||||
<tr key={r.id}
|
||||
onClick={() => navigate(`/investissements/${r.id}`)}
|
||||
onClick={() => navigate(`/investissements/${r.id}`, { state: { from: { path: '/investissements', search: location.search, label: 'Investissements' } } })}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onMouseEnter={e => e.currentTarget.style.opacity = '0.8'}
|
||||
onMouseLeave={e => e.currentTarget.style.opacity = '1'}
|
||||
|
||||
Reference in new issue
Block a user