* feat(backoffice): create a boilerplate page for Hackathon dashboard - Create an empty page for Hackathon dashboard - Comment out and hide the existing backoffice sidebar * feat(backoffice): Create a nested/dropdown sidebar list - Create a dropdown sidebar list - Show back the old navigation and group them - Make the sidebar responsive for mobile view * test datatable with mock data * base UI for Hackathon backoffice TODO: - Organize table schema for users, teams, and submissions management - Create API Contract for additional back-end endpoint * feat(hackathon): draft data table column & API Contract * update endpoint * feat(backoffice): update page hackathon user management - update data table component - update filtering & pagination - add modal display to edit and add user - hide notification icon in backoffice wrapper * feat(backoffice): add API contract for hackathon users * feat(backoffice): little adjustment in hackathon users management UI and API contract * feat(backoffice): update hackathon team management page - add modal for manage team, add new team, and view project submission - reorganize the table column and data table * feat(backoffice): add searchable city filter - add component for city filter - apply to user management and team management pages * feat(backoffice): improve hackathon team modal UI and add API contract - Add feature to select city in team detail modal using CityFilterSelect component - Add feature to change team logo and banner - Add API contract documentation for hackathon teams in backoffice * feat(backoffice): authentication middleware, error pages, and 404 page * feat(backoffice): hackathon dashboard integration * feat(backoffice): users page integration - Get users data from API - Set up server-side pagination and match URL params - Hide filter that doesn't exist in back-end * feat(backoffice): teams page integration - Get teams data from API - Hide filter that doesn't exists in back-end - Simplify modal according to the back-end * feat(backoffice): submission page integration - Fetch submissions data from API - Move submission modal to hackathon-submissions page
109 lines
2.5 KiB
TypeScript
109 lines
2.5 KiB
TypeScript
import {
|
|
PERMISSIONS,
|
|
SessionToken,
|
|
SessionUser,
|
|
} from '@imphnen-frontend-service/utils';
|
|
import { LoaderFunctionArgs, redirect } from 'react-router';
|
|
|
|
const mappingPublicRoutes = [
|
|
'/auth/login',
|
|
'/auth/forgot',
|
|
'/auth/new-password',
|
|
];
|
|
|
|
const mappingRoutePermissions = [
|
|
{
|
|
path: '/dashboard',
|
|
permissions: [],
|
|
},
|
|
{
|
|
path: '/users',
|
|
permissions: [PERMISSIONS.USERS.READ_LIST],
|
|
},
|
|
{
|
|
path: '/users/create',
|
|
permissions: [PERMISSIONS.USERS.CREATE],
|
|
},
|
|
{
|
|
path: '/users/update',
|
|
permissions: [PERMISSIONS.USERS.UPDATE],
|
|
},
|
|
{
|
|
path: '/users/detail',
|
|
permissions: [PERMISSIONS.USERS.READ_DETAIL],
|
|
},
|
|
{
|
|
path: '/roles',
|
|
permissions: [PERMISSIONS.ROLES.READ_LIST],
|
|
},
|
|
{
|
|
path: '/roles/create',
|
|
permissions: [PERMISSIONS.ROLES.CREATE],
|
|
},
|
|
{
|
|
path: '/roles/update',
|
|
permissions: [PERMISSIONS.ROLES.UPDATE],
|
|
},
|
|
{
|
|
path: '/roles/detail',
|
|
permissions: [PERMISSIONS.ROLES.READ_DETAIL],
|
|
},
|
|
{
|
|
path: '/permissions',
|
|
permissions: [PERMISSIONS.PERMISSIONS.READ_LIST],
|
|
},
|
|
{
|
|
path: '/permissions/create',
|
|
permissions: [PERMISSIONS.PERMISSIONS.CREATE],
|
|
},
|
|
{
|
|
path: '/permissions/update',
|
|
permissions: [PERMISSIONS.PERMISSIONS.UPDATE],
|
|
},
|
|
{
|
|
path: '/permissions/detail',
|
|
permissions: [PERMISSIONS.PERMISSIONS.READ_DETAIL],
|
|
},
|
|
];
|
|
|
|
//TODO : Fix this later
|
|
// const redirectToFirstAccessibleRoute = (userPermissions: string[]) => {
|
|
// const fallback = mappingRoutePermissions.find((route) =>
|
|
// route.permissions.some((perm) => userPermissions.includes(perm))
|
|
// );
|
|
// return redirect(fallback?.path ?? '/auth/login');
|
|
// };
|
|
|
|
export const middleware = async ({ request }: LoaderFunctionArgs) => {
|
|
const url = new URL(request.url);
|
|
const pathname = url.pathname;
|
|
const session = SessionUser.get();
|
|
const session_token = SessionToken.get();
|
|
const token = session_token?.token?.access_token;
|
|
const userPermissions =
|
|
session?.role?.permissions?.map?.((perm) => perm?.name) ?? [];
|
|
|
|
if (mappingPublicRoutes.includes(pathname)) {
|
|
if (token) return redirect('/hackathon-dashboard');
|
|
return null;
|
|
}
|
|
|
|
if (!session) return redirect('/auth/login');
|
|
|
|
const matchedRoute = mappingRoutePermissions.find(
|
|
(route) => route.path === pathname
|
|
);
|
|
|
|
if (matchedRoute) {
|
|
const hasPermission =
|
|
!matchedRoute.permissions ||
|
|
matchedRoute.permissions.some((perm) => userPermissions.includes(perm));
|
|
|
|
if (!hasPermission) {
|
|
return '/hackathon-dashboard';
|
|
}
|
|
}
|
|
|
|
return null;
|
|
};
|