fix: correction des redirections vers la login page

This commit is contained in:
Luc SORIGNET
2025-04-17 17:23:17 +02:00
parent f7666c894b
commit 2e0fe86c71
6 changed files with 44 additions and 48 deletions

View File

@ -30,7 +30,6 @@ import {
} from '@/utils/Url';
import { disconnect } from '@/app/actions/authAction';
import { useSession } from 'next-auth/react';
import ProtectedRoute from '@/components/ProtectedRoute';
import { getGravatarUrl } from '@/utils/gravatar';
import Footer from '@/components/Footer';
@ -41,9 +40,8 @@ import { useEstablishment } from '@/context/EstablishmentContext';
export default function Layout({ children }) {
const t = useTranslations('sidebar');
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
const { data: session } = useSession();
const {
selectedEstablishmentId,
setSelectedRoleId,
setSelectedEstablishmentId,
profileRole,
setProfileRole,
@ -163,17 +161,17 @@ export default function Layout({ children }) {
currentPage={currentPage}
items={Object.values(sidebarItems)}
onCloseMobile={toggleSidebar}
onEstablishmentChange={(establishmentId) => {
const parsedEstablishmentId = parseInt(establishmentId, 10);
setSelectedEstablishmentId(parsedEstablishmentId);
let roleIndex = session.user.roles.findIndex(
(role) => role.establishment__id === parsedEstablishmentId
);
if (roleIndex === -1) {
roleIndex = 0;
onRoleChange={(roleId) => {
let parsedRoleId = parseInt(roleId, 10);
if (parsedRoleId === -1) {
parsedRoleId = 0;
}
const role = session.user.roles[roleIndex].role_type;
const role = user.roles[parsedRoleId].role_type;
const establishmentId =
user.roles[parsedRoleId].establishment__id;
setProfileRole(role);
setSelectedRoleId(parsedRoleId);
setSelectedEstablishmentId(establishmentId);
}}
/>
</div>

View File

@ -8,6 +8,7 @@ import { Search } from 'lucide-react';
import Popup from '@/components/Popup';
import Loader from '@/components/Loader';
import AlertWithModal from '@/components/AlertWithModal';
import { useRouter } from 'next/navigation';
import DropdownMenu from '@/components/DropdownMenu';
import {
MoreVertical,
@ -112,6 +113,7 @@ export default function Page({ params: { locale } }) {
const [isOpenAddGuardian, setIsOpenAddGuardian] = useState(false);
const csrfToken = useCsrfToken();
const router = useRouter();
const { selectedEstablishmentId } = useEstablishment();
const openModal = () => {
@ -670,7 +672,9 @@ export default function Page({ params: { locale } }) {
{
icon: <Edit className="w-5 h-5 text-blue-500 hover:text-blue-700" />,
onClick: () =>
(window.location.href = `${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}&id=1`),
router.push(
`${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}`
),
},
{
icon: (
@ -688,7 +692,9 @@ export default function Page({ params: { locale } }) {
{
icon: <Edit className="w-5 h-5 text-blue-500 hover:text-blue-700" />,
onClick: () =>
(window.location.href = `${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}&id=1`),
router.push(
`${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}`
),
},
],
3: [
@ -697,7 +703,9 @@ export default function Page({ params: { locale } }) {
<CircleCheck className="w-5 h-5 text-green-500 hover:text-green-700" />
),
onClick: () =>
(window.location.href = `${FE_ADMIN_SUBSCRIPTIONS_VALIDATE_URL}?studentId=${row.student.id}&firstName=${row.student.first_name}&lastName=${row.student.last_name}&paymentMode=${row.registration_payment}&file=${row.registration_file}`),
router.push(
`${FE_ADMIN_SUBSCRIPTIONS_VALIDATE_URL}?studentId=${row.student.id}&firstName=${row.student.first_name}&lastName=${row.student.last_name}&paymentMode=${row.registration_payment}&file=${row.registration_file}`
),
},
],
5: [

View File

@ -14,13 +14,7 @@ export default function ParentHomePage() {
const [children, setChildren] = useState([]);
const [userId, setUserId] = useState(null);
const [currentPage, setCurrentPage] = useState(1);
const {
user,
setProfileRole,
selectedEstablishmentId,
setSelectedEstablishmentId,
establishments,
} = useEstablishment();
const { user, selectedEstablishmentId } = useEstablishment();
const router = useRouter();
@ -33,14 +27,6 @@ export default function ParentHomePage() {
});
}, [selectedEstablishmentId]);
const handleEstablishmentChange = (e) => {
const establishmentId = parseInt(e.target.value, 10);
setSelectedEstablishmentId(establishmentId);
const role = establishments.find(
(est) => est.id === establishmentId
)?.role_type;
setProfileRole(role);
};
function handleEdit(eleveId) {
// Logique pour éditer le dossier de l'élève
logger.debug(`Edit dossier for student id: ${eleveId}`);