All files / apps/web/src/utils organization.js

100% Statements 5/5
100% Branches 7/7
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14          3x 3x     1x 4x 4x    
import { useOrganizationStore } from '../store/organizationStore';
 
// Fallback : extraire l'orgId depuis l'URL si le store n'est pas encore chargé
// (évite les requêtes 404 en attendant l'initialisation du store)
function getOrgIdFromPath() {
  const parts = window.location.pathname.split('/').filter(Boolean);
  return parts[0] && /^[0-9a-f]{24}$/.test(parts[0]) ? parts[0] : null;
}
 
export const getOrganizationId = () => {
  const store = useOrganizationStore.getState();
  return store.currentOrganization?.id || getOrgIdFromPath() || null;
};