@procore/labs-procore-environment
TypeScript icon, indicating that this package has built-in type declarations

5.0.0 • Public • Published

procore-environment

Disclaimer: Meant for Procore internal use only.

Description

Install

yarn add @procore/labs-procore-environment

Usage

Utility to provide Procore Environment for the decoupled frontend applications, aka "hydra clients".
As part of the initiative to move outside the monolith, this package provides functionality to fetch Procore Environment for a given client.

As of now, the provider accepts a optional config object that has projectId or companyId. If you are on the company level, you can pass in a config object that contains the companyId. If you are on the project level, you can pass in a config object that contains the projectId. However, if no config is passed in, the package will try to get the projectId or companyId by parsing the browser url. For example, if the current url is /23/company/directory, the package will use 23 as the companyId to fetch the Procore Environment.

Wrap your application with ProcoreEnvironmentProvider

import { render } from 'react-dom';
import { ProcoreEnvironmentProvider } from '@procore/labs-procore-environment';
import { Application } from './Application';
import CustomLoadingScreen from './CustomLoadingScreen';
import ErrorScreen from './ErrorScreen';

// Just need to pass either projectId or companyId, if both are passed in
// it will fallback to projectId. If no config is passed in, the package
// will parse the projectId or companyId from current browser url.
const config = isProject ? { projectId } : { companyId };

render(
  <ProcoreEnvironmentProvider
    config={config}
    loader={CustomLoadingScreen}
    errorFallback={ErrorScreen}
  >
    <Application />
  </ProcoreEnvironmentProvider>,
  document.getElementById('root')
);

To consume Procore Environment in your child components

import * as React from 'react';
import { useProcoreEnvironment } from '@procore/labs-procore-environment';

const YourComponent = () => {
  const procoreEnvironment = useProcoreEnvironment();

  return <div>{procoreEnvironment.currencySymbol}</div>;
};

Procore Environment Shape

The Procore Environment returned from the package could be different from the window.Procore.Environment, the new shape looks like:

type ProcoreEnvironment = {
  companyId: ID;
  companyName: string;
  currencySymbol: string;
  dateFormat: string;
  locale: string;
  projectId: ID | null;
  projectName: string | null;
  timeZone: string;
  userId: ID;
};

Props

Context

  • config ({ projectId?: number, companyId?: number }, default: undefined)
    The config object that contains either projectId or companyId for the package to fetch the procore environment. If config is not being passed, the projectId or companyId will be parsed from the current browser URL.

  • loader (React.ReactElement?, default: <Loading />)
    Customized loading screen while the package is fetching the Procore Environment. If not provided, it will fallback to a default one.

  • errorFallback (React.ReactElement?, default: null)
    Customized error screen when the package failed to fetch the Procore Environment. If not provided, the default behavior is to display an empty screen.

Readme

Keywords

none

Package Sidebar

Install

npm i @procore/labs-procore-environment

Weekly Downloads

724

Version

5.0.0

License

SEE LICENSE IN LICENSE

Unpacked Size

63 kB

Total Files

16

Last publish

Collaborators

  • yzhou2024
  • alyelashram_procore
  • melch-procore
  • peterknif
  • moaz-ashraf
  • attachi
  • a.elbadawei
  • hyogman
  • dmitri_wm
  • stephanie.brereton
  • procore-oss-user
  • stevenkang3
  • max.helmetag
  • codyrobertsprocore
  • miguel.garcia-procore
  • magdyyx
  • atoaima
  • mustafa-abdelrahman
  • elewando-procore
  • ahmed.ghorab
  • lnspatz914
  • richard.bunn
  • omar.wagdy
  • mona.khairbek
  • mbartlett413
  • cody_schindler_procore
  • yoasyo25
  • ritchlee
  • andersontr15
  • steven.hinkle
  • jamie-dugan-procore
  • hgouhierprocore
  • denzylbalram
  • sarah.freitas
  • alan.bresani
  • amyprocore
  • yoyis3000
  • elijah.procore
  • mike-arndt-procore
  • jnhoang1
  • pam-whisenhunt
  • shradha.khard
  • david-christensen-procore
  • javio-procore
  • chance.eakin.procore
  • gideon-procore
  • ihor.diachenko_procore
  • justinmwatts
  • tedyang
  • jyang-procore
  • pwhisenhunt-procore
  • fairchild
  • rodayna.ehab
  • neil1023
  • scottstern
  • brian.smith1
  • g2mitchell
  • dlameter-procore
  • kylepietz
  • abhijit-procore
  • lhuang325
  • jake-pitkin
  • erikthoreson
  • simona.iancu
  • decha-sanson
  • aberkowitz
  • asamay
  • mustafa-u-abdelrahman
  • rajatmenhdiratta
  • jacksonleach-procore
  • pmfrawley
  • phunguyen-pcor
  • tatsiana.clifton
  • deiab
  • srichaitanya.peddinti
  • kenny.foisy
  • matheusprocore
  • jgreene_procore
  • hectorthiele
  • etokarev
  • daniel.ferreira-contractor
  • dmccraw-procore
  • cyrille.bai
  • greg.sparks
  • fabiomelo513
  • phil.custer
  • bbreyel921
  • amir-iskander
  • neil.mckeeman
  • nickprocore
  • lzhou888
  • davidshure
  • stevenliprocore
  • ramysaid2
  • refaiepcn
  • jgentes
  • faraz.hanif
  • mostafaeltazy
  • agamaleldin
  • andrew.isaac
  • saranahal2
  • rodrigo.dejuana
  • kellen.stewart
  • bill-wagner
  • ezrasimeloff
  • jeffgiaquinto
  • gturkadze
  • sean.spearman.procore
  • kylemartinez-procore
  • roobo-romeski
  • andres-mendez-procore
  • gaurav.sharma.procore
  • tracy.otto
  • sarah.heredia
  • victorbendeck-pc
  • cbathgate
  • davidkangpro
  • kyle.liu
  • amin.jaipuri
  • grafffffff
  • mishaelowoyemi
  • evan.cerwonka.procore
  • ilya.dryha-contractor
  • varomir
  • yogevfine1
  • timofeee
  • matt.harris0223
  • winson.chu
  • andersonbispoprocore
  • scorgiat-procore
  • ladavarga
  • procore_halzy
  • enyaga
  • willpankonien
  • sateesh-kadiyala-procore
  • chris.berber
  • txin1
  • epalinprocore
  • mehrdad-panahandeh
  • tyler.wasden.procore
  • jeremy.lund
  • dineshkumar.jayak
  • ryanfuentesprocore
  • stajics
  • brocktillotsonprocore
  • kyle.williams
  • dtorres-procore
  • noor.ali
  • ari-procore
  • alanprocore
  • jl4ever
  • james.lawson
  • ajaykumar-procore
  • dennis.heckman
  • tara.chambers
  • lalovar-procore
  • james.cleary
  • chadryder
  • devin.cunningham.procore
  • abhijit.patwardhan
  • lydiahara
  • sherylnapigkit
  • changprocore
  • apcarroll_procore
  • andy.mayer
  • bob.laskowski
  • vinaya-procore
  • kahliholmes
  • andrew.wheeler
  • leandro-proc
  • yadhu.prakash
  • jason-kaye
  • jesse.olsen
  • patrick.lardin
  • brad.urani
  • allenanle.procore
  • brookyboy009
  • uddhavjoglekar
  • dancingshell
  • rysmithprocore
  • robbiegprocore
  • jadamsss
  • jeremy.bouzigard
  • timdoherty
  • b.bookout
  • jalyng
  • htael
  • dev-account-admin
  • sseanwang
  • bhargavrnd
  • farismmk
  • dannyporrello
  • danny.ou
  • messanjah
  • eyvettesou
  • jgee67
  • cagmz
  • mariah_delaney
  • lukenispel
  • kimhin267
  • juliana.hernandez
  • judy-lu-pc
  • procore-it-support
  • andrewburke-pc
  • jkleintech
  • rachel.arkebauer
  • procore-npm-bot
  • james.dabbs-procore
  • laurenbrandsteinprocore
  • scottbieser-procore
  • zach.mckenzie.procore
  • shayonj_procore
  • heplayskeys
  • mike.south
  • thomasoboyle
  • dischorde
  • derek-carter-procore
  • dlgasser
  • cfprocore
  • evan.waits
  • jeremy-marcus
  • jmejia-fsl
  • ersgonzalo
  • stephan-procore
  • aleclarsenprocore
  • yihai.zweifel
  • jay-rajan
  • jacky-lei
  • peter.jin