All files / src/Context AddCompanyContext.tsx

100% Statements 10/10
100% Branches 2/2
100% Functions 3/3
100% Lines 7/7

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 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 4733x                         33x                     124x     143x 124x                   124x             837x  
import React, { useMemo } from 'react';
import { VendorConfigurableFieldSets } from '../shared/types';
 
interface AddCompanyContextProviderProps {
  companyId: number;
  businessId: string;
  vendorConfigurableFieldSets: VendorConfigurableFieldSets;
  projectId?: string;
  canCreateAndEditCompanies: boolean;
  children: React.ReactNode;
  companyCountryCode?: string;
}
 
export const AddCompanyContext = React.createContext<
  Omit<AddCompanyContextProviderProps, 'children'>
>({
  companyId: 0,
  businessId: '',
  vendorConfigurableFieldSets: {} as VendorConfigurableFieldSets,
  projectId: '',
  canCreateAndEditCompanies: false,
  companyCountryCode: '',
});
 
export function AddCompanyContextProvider(
  props: Readonly<AddCompanyContextProviderProps>
) {
  const value = useMemo(() => {
    return {
      companyId: props.companyId,
      businessId: props.businessId,
      vendorConfigurableFieldSets: props.vendorConfigurableFieldSets,
      projectId: props.projectId,
      canCreateAndEditCompanies: props.canCreateAndEditCompanies,
      companyCountryCode: props.companyCountryCode || 'US',
    };
  }, [props]);
 
  return (
    <AddCompanyContext.Provider value={value}>
      {props.children}
    </AddCompanyContext.Provider>
  );
}
 
export const useAddCompanyContext = () => React.useContext(AddCompanyContext);