Correction des redirections
This commit is contained in:
@@ -27,7 +27,7 @@ const STATUT_FG = {
|
||||
cloture: 'var(--text-muted)',
|
||||
};
|
||||
|
||||
export default function InvMensuelTable({ rows, allRembs, allReinvests, year }) {
|
||||
export default function InvMensuelTable({ rows, allRembs, allReinvests, year, originFrom }) {
|
||||
const navigate = useNavigate();
|
||||
const currentYear = new Date().getFullYear();
|
||||
const currentMonth = new Date().getMonth() + 1;
|
||||
@@ -142,7 +142,7 @@ export default function InvMensuelTable({ rows, allRembs, allReinvests, year })
|
||||
{grid.map(({ inv, months }) => (
|
||||
<tr key={inv.id} className="tip-row-plat"
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => navigate(`/investissements/${inv.id}`)}>
|
||||
onClick={() => navigate(`/investissements/${inv.id}`, originFrom ? { state: { from: originFrom } } : undefined)}>
|
||||
|
||||
<td className="tip-td-name" style={{ whiteSpace: 'normal', maxWidth: '40ch', wordBreak: 'break-word' }}>
|
||||
{inv.nom_projet || '—'}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { NavLink, Outlet, useNavigate } from 'react-router-dom';
|
||||
import { NavLink, Outlet, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { api } from '../api.js';
|
||||
import { useInvestisseur } from '../context/InvestisseurContext.jsx';
|
||||
import { useUi } from '../context/UiContext.jsx';
|
||||
@@ -64,6 +64,7 @@ const IconPanelExpand = () => (
|
||||
/* ── Recherche rapide de projet ─────────────────────────────── */
|
||||
function ProjectSearch() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { activeId, activeView } = useInvestisseur();
|
||||
const [query, setQuery] = useState('');
|
||||
const [allInv, setAllInv] = useState([]);
|
||||
@@ -118,9 +119,25 @@ function ProjectSearch() {
|
||||
setActiveIdx(-1);
|
||||
}, [results.length, query]); /* eslint-disable-line */
|
||||
|
||||
const PAGE_LABELS = {
|
||||
'/': 'Tableau de bord',
|
||||
'/investissements': 'Investissements',
|
||||
'/remboursements': 'Remboursements',
|
||||
'/depots-retraits': 'Dépôts / Retraits',
|
||||
'/2778-sd': 'Fiscalité',
|
||||
'/plateformes': 'Plateformes',
|
||||
'/taxreport': 'Fiscalité',
|
||||
'/settings': 'Paramètres',
|
||||
'/compte': 'Mon compte',
|
||||
'/admin': 'Administration',
|
||||
};
|
||||
const currentLabel = PAGE_LABELS[location.pathname] ?? 'Recherche';
|
||||
|
||||
const goTo = (inv) => {
|
||||
setQuery(''); setOpen(false);
|
||||
navigate(`/investissements/${inv.id}`);
|
||||
navigate(`/investissements/${inv.id}`, {
|
||||
state: { from: { path: location.pathname, search: location.search, label: currentLabel } },
|
||||
});
|
||||
};
|
||||
|
||||
const handleKeyDown = (e) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { api } from '../api.js';
|
||||
import { useInvestisseur } from '../context/InvestisseurContext.jsx';
|
||||
import { fmtDate } from '../utils/format.js';
|
||||
@@ -52,6 +52,7 @@ const MODULE_LABEL = {
|
||||
export default function Imports() {
|
||||
const { activeId } = useInvestisseur();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
// ── Import classique (xlsx/csv/json) ──────────────────────────
|
||||
const [module, setModule] = useState('depots_retraits');
|
||||
@@ -444,7 +445,7 @@ function DossierImport({
|
||||
{' '}
|
||||
<button
|
||||
style={{ marginLeft: 8, fontSize: 'var(--fs-xs)', padding: '2px 8px' }}
|
||||
onClick={() => navigate(`/investissements/${dossierResult.investissementId}`)}
|
||||
onClick={() => navigate(`/investissements/${dossierResult.investissementId}`, { state: { from: { path: location.pathname, search: location.search, label: 'Imports' } } })}
|
||||
>
|
||||
Ouvrir le dossier →
|
||||
</button>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
||||
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
||||
import { api } from '../api.js';
|
||||
import { useInvestisseur } from '../context/InvestisseurContext.jsx';
|
||||
import { useUi } from '../context/UiContext.jsx';
|
||||
@@ -103,6 +103,8 @@ function xirr(cashflows) {
|
||||
export default function InvestissementDetail() {
|
||||
const { id } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const navOrigin = location.state?.from ?? null;
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const { activeId, investisseurs } = useInvestisseur();
|
||||
const { displayMode } = useUi();
|
||||
@@ -806,8 +808,11 @@ export default function InvestissementDetail() {
|
||||
<span style={{ color: 'var(--text-muted, #6b7280)', fontWeight: 300, fontSize: '0.85em' }}>·</span>
|
||||
<span>{inv.nom_projet}</span>
|
||||
</h2>
|
||||
<button onClick={() => navigate('/investissements')} style={{ whiteSpace: 'nowrap', flexShrink: 0 }}>
|
||||
← Investissements
|
||||
<button
|
||||
onClick={() => navOrigin ? navigate({ pathname: navOrigin.path, search: navOrigin.search || '' }) : navigate('/investissements')}
|
||||
style={{ whiteSpace: 'nowrap', flexShrink: 0 }}
|
||||
>
|
||||
← {navOrigin?.label ?? 'Investissements'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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'}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Fragment, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { api } from '../api.js';
|
||||
import { useInvestisseur } from '../context/InvestisseurContext.jsx';
|
||||
import { useUi } from '../context/UiContext.jsx';
|
||||
@@ -272,6 +272,8 @@ export default function Plateformes() {
|
||||
const { activeId, activeView, investisseurs } = useInvestisseur();
|
||||
const { displayMode, chartInterets, chartCapital, chartCashback } = useUi();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
|
||||
/* ── État données ── */
|
||||
const [allRows, setAllRows] = useState([]);
|
||||
@@ -283,7 +285,9 @@ export default function Plateformes() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
/* ── État sélecteurs ── */
|
||||
const [selectedPlatName, setSelectedPlatName] = useState(null);
|
||||
/* selectedPlatName et activeTab sont dans l'URL pour survivre au retour arrière */
|
||||
const selectedPlatName = searchParams.get('plat') || null;
|
||||
const setSelectedPlatName = (nom) => setSearchParams(p => { const n = new URLSearchParams(p); n.set('plat', nom); return n; }, { replace: true });
|
||||
const [selectedDetenteurId, setSelectedDetenteurId] = useState('all');
|
||||
const [selectedYear, setSelectedYear] = useState(String(new Date().getFullYear()));
|
||||
const [windowStart, setWindowStart] = useState(0);
|
||||
@@ -320,7 +324,8 @@ export default function Plateformes() {
|
||||
const [pfuRates, setPfuRates] = useState([]);
|
||||
|
||||
/* ── État UI ── */
|
||||
const [activeTab, setActiveTab] = useState('depots-retraits');
|
||||
const activeTab = searchParams.get('tab') || 'depots-retraits';
|
||||
const setActiveTab = (tab) => setSearchParams(p => { const n = new URLSearchParams(p); n.set('tab', tab); return n; }, { replace: true });
|
||||
const [listFocused, setListFocused] = useState(false);
|
||||
|
||||
/* ── Chargement ── */
|
||||
@@ -1020,7 +1025,7 @@ export default function Plateformes() {
|
||||
const rowTotal = months.reduce((s, v) => s + (v?.value ?? 0), 0);
|
||||
return (
|
||||
<tr key={inv.id} className="tip-row-plat" style={{ cursor: 'pointer' }}
|
||||
onClick={() => navigate(`/investissements/${inv.id}`)}>
|
||||
onClick={() => navigate(`/investissements/${inv.id}`, { state: { from: { path: location.pathname, search: location.search, label: 'Plateformes' } } })}>
|
||||
<td className="tip-td-name" style={{ whiteSpace: 'normal', maxWidth: '40ch', wordBreak: 'break-word' }}>
|
||||
{inv.nom_projet || '—'}
|
||||
</td>
|
||||
@@ -1423,6 +1428,7 @@ export default function Plateformes() {
|
||||
allRembs={allRembs}
|
||||
allReinvests={allReinvests}
|
||||
year={selectedYear}
|
||||
originFrom={{ path: location.pathname, search: location.search, label: 'Plateformes' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1473,7 +1479,7 @@ export default function Plateformes() {
|
||||
: (rembParInv[r.id]?.interets_bruts || 0);
|
||||
return (
|
||||
<tr key={r.id} style={{ cursor: 'pointer' }}
|
||||
onClick={() => navigate(`/investissements/${r.id}`)}>
|
||||
onClick={() => navigate(`/investissements/${r.id}`, { state: { from: { path: location.pathname, search: location.search, label: 'Plateformes' } } })}>
|
||||
<td style={{ fontWeight: 500 }}>{r.nom_projet}</td>
|
||||
<td className="text-muted" style={{ fontSize: 'var(--fs-sm)' }}>{r.emetteur || '—'}</td>
|
||||
<td className="num" style={{ fontSize: 'var(--fs-sm)', color: 'var(--text-muted)' }}>{fmtDate(r.date_souscription)}</td>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { api } from '../../api.js';
|
||||
import { fmtDate } from '../../utils/format.js';
|
||||
import { useInvestisseur } from '../../context/InvestisseurContext.jsx';
|
||||
@@ -239,7 +239,7 @@ function DossierImport({
|
||||
{' '}
|
||||
<button
|
||||
style={{ marginLeft: 8, fontSize: 'var(--fs-xs)', padding: '2px 8px' }}
|
||||
onClick={() => navigate(`/investissements/${dossierResult.investissementId}`)}
|
||||
onClick={() => navigate(`/investissements/${dossierResult.investissementId}`, { state: { from: { path: location.pathname, search: location.search, label: 'Imports' } } })}
|
||||
>
|
||||
Ouvrir le dossier →
|
||||
</button>
|
||||
@@ -253,6 +253,7 @@ function DossierImport({
|
||||
export default function ImportsSection() {
|
||||
const { activeId } = useInvestisseur();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
const [module, setModule] = useState('depots_retraits');
|
||||
const [file, setFile] = useState(null);
|
||||
|
||||
Reference in New Issue
Block a user