diff --git a/Front-End/src/app/[locale]/admin/layout.js b/Front-End/src/app/[locale]/admin/layout.js
index d936ff8..9c6180b 100644
--- a/Front-End/src/app/[locale]/admin/layout.js
+++ b/Front-End/src/app/[locale]/admin/layout.js
@@ -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);
}}
/>
diff --git a/Front-End/src/app/[locale]/admin/subscriptions/page.js b/Front-End/src/app/[locale]/admin/subscriptions/page.js
index 0d208e5..ae63976 100644
--- a/Front-End/src/app/[locale]/admin/subscriptions/page.js
+++ b/Front-End/src/app/[locale]/admin/subscriptions/page.js
@@ -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: ,
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: ,
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 } }) {
),
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: [
diff --git a/Front-End/src/app/[locale]/parents/page.js b/Front-End/src/app/[locale]/parents/page.js
index b31b80a..c306638 100644
--- a/Front-End/src/app/[locale]/parents/page.js
+++ b/Front-End/src/app/[locale]/parents/page.js
@@ -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}`);
diff --git a/Front-End/src/components/ProfileSelector.js b/Front-End/src/components/ProfileSelector.js
index 973a9d8..ad1c3ae 100644
--- a/Front-End/src/components/ProfileSelector.js
+++ b/Front-End/src/components/ProfileSelector.js
@@ -4,24 +4,26 @@ import DropdownMenu from '@/components/DropdownMenu';
import { getRightStr } from '@/utils/rights';
import { ChevronDown } from 'lucide-react'; // Import de l'icône
-const ProfileSelector = ({ onEstablishmentChange, className = '' }) => {
+const ProfileSelector = ({ onRoleChange, className = '' }) => {
const {
establishments,
- selectedEstablishmentId,
+ selectedRoleId,
+ setSelectedRoleId,
setSelectedEstablishmentId,
setProfileRole,
+ user,
} = useEstablishment();
const [dropdownOpen, setDropdownOpen] = useState(false);
- const handleEstablishmentChange = (establishmentId) => {
- setSelectedEstablishmentId(establishmentId);
- const role = establishments.find(
- (est) => est.id === establishmentId
- )?.role_type;
+ const handleRoleChange = (roleId) => {
+ // Pas bon quand on a plusieur role pour le même établissement
+ setSelectedRoleId(roleId);
+ const role = user.roles[roleId].role_type;
setProfileRole(role);
-
- if (onEstablishmentChange) {
- onEstablishmentChange(establishmentId);
+ const establishmentId = user.roles[roleId].establishment__id;
+ setSelectedEstablishmentId(establishmentId);
+ if (onRoleChange) {
+ onRoleChange(roleId);
}
setDropdownOpen(false); // Fermer le menu après sélection
};
@@ -36,7 +38,7 @@ const ProfileSelector = ({ onEstablishmentChange, className = '' }) => {
}
const selectedEstablishment = establishments.find(
- (est) => est.id === selectedEstablishmentId
+ (est) => est.role_id === selectedRoleId
);
return (
@@ -70,7 +72,7 @@ const ProfileSelector = ({ onEstablishmentChange, className = '' }) => {
{establishment.name}
),
- onClick: () => handleEstablishmentChange(establishment.id),
+ onClick: () => handleRoleChange(establishment.role_id),
}))}
buttonClassName="w-full"
menuClassName="absolute mt-2 w-full bg-white border border-gray-200 rounded shadow-lg z-10"
diff --git a/Front-End/src/components/Sidebar.js b/Front-End/src/components/Sidebar.js
index 209b799..3888c63 100644
--- a/Front-End/src/components/Sidebar.js
+++ b/Front-End/src/components/Sidebar.js
@@ -17,7 +17,7 @@ const SidebarItem = ({ icon: Icon, text, active, url, onClick }) => (
);
-function Sidebar({ currentPage, items, onCloseMobile, onEstablishmentChange }) {
+function Sidebar({ currentPage, items, onCloseMobile, onRoleChange }) {
const router = useRouter();
const [selectedItem, setSelectedItem] = useState(currentPage);
@@ -37,10 +37,7 @@ function Sidebar({ currentPage, items, onCloseMobile, onEstablishmentChange }) {
return (