File size: 745 Bytes
518343a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { createContext, useContext, useState } from 'react';
import type { ReactNode } from 'react';

export type OrgId = 'szl' | 'acme' | 'northwind';

interface OrgContextType {
  currentOrg: OrgId;
  setOrg: (org: OrgId) => void;
}

const OrgContext = createContext<OrgContextType | undefined>(undefined);

export function OrgProvider({ children }: { children: ReactNode }) {
  const [currentOrg, setOrg] = useState<OrgId>('szl');

  return (
    <OrgContext.Provider value={{ currentOrg, setOrg }}>
      {children}
    </OrgContext.Provider>
  );
}

export function useOrg() {
  const context = useContext(OrgContext);
  if (context === undefined) {
    throw new Error('useOrg must be used within an OrgProvider');
  }
  return context;
}