const parsePositiveInteger = (value) => { const parsedValue = Number.parseInt(String(value ?? ""), 10); return Number.isInteger(parsedValue) && parsedValue > 0 ? parsedValue : null; }; const getPath = (route) => String(route?.path ?? ""); export const getAdminDepartmentIdFromRoute = (route) => { const path = getPath(route); const fromPath = parsePositiveInteger(path.match(/^\/admin\/(\d+)(?:\/|$)/)?.[1]); if (fromPath !== null) { return fromPath; } return path.startsWith("/admin") ? parsePositiveInteger(route?.params?.departmentId) : null; }; export const getLimitedBackofficeDepartmentIdFromRoute = (route) => { const path = getPath(route); const fromPath = parsePositiveInteger(path.match(/^\/backoffice\/departments\/(\d+)(?:\/|$)/)?.[1]); if (fromPath !== null) { return fromPath; } return path.startsWith("/backoffice/departments") ? parsePositiveInteger(route?.params?.departmentId) : null; }; export const getLimitedBackofficeDepartmentRoute = (departmentId) => `/backoffice/departments/${encodeURIComponent(String(departmentId))}/prices`; export const getAdminDepartmentRoute = (departmentId) => `/admin/${encodeURIComponent(String(departmentId))}`;