Skip to content

Commit

Permalink
Merge pull request #31824 from VickyStash/ts-migration/update-environ…
Browse files Browse the repository at this point in the history
…ment-context

[TS Migration] Update EnvironmentContext default value
  • Loading branch information
Julesssss authored Nov 28, 2023
2 parents 540bedd + afea2b2 commit 6bfef02
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/EnvironmentBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const ENVIRONMENT_SHORT_FORM = {

function EnvironmentBadge() {
const styles = useThemeStyles();
const {environment} = useEnvironment();
const {environment, isProduction} = useEnvironment();

// If we are on production, don't show any badge
if (environment === CONST.ENVIRONMENT.PRODUCTION || environment === undefined) {
if (isProduction) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/ExpensifyWordmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function ExpensifyWordmark({isSmallScreenWidth, style}: ExpensifyWordmarkProps)
const styles = useThemeStyles();
const {environment} = useEnvironment();
// PascalCase is required for React components, so capitalize the const here
const LogoComponent = environment ? logoComponents[environment] : AdHocLogo;
const LogoComponent = logoComponents[environment];

return (
<>
Expand Down
7 changes: 5 additions & 2 deletions src/components/withEnvironment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ type EnvironmentContextValue = {
environmentURL: string;
};

const EnvironmentContext = createContext<EnvironmentContextValue | null>(null);
const EnvironmentContext = createContext<EnvironmentContextValue>({
environment: CONST.ENVIRONMENT.PRODUCTION,
environmentURL: CONST.NEW_EXPENSIFY_URL,
});

function EnvironmentProvider({children}: EnvironmentProviderProps): ReactElement {
const [environment, setEnvironment] = useState<EnvironmentValue>(CONST.ENVIRONMENT.PRODUCTION);
Expand Down Expand Up @@ -47,7 +50,7 @@ export default function withEnvironment<TProps extends EnvironmentContextValue,
WrappedComponent: ComponentType<TProps & RefAttributes<TRef>>,
): (props: Omit<TProps, keyof EnvironmentContextValue> & React.RefAttributes<TRef>) => ReactElement | null {
function WithEnvironment(props: Omit<TProps, keyof EnvironmentContextValue>, ref: ForwardedRef<TRef>): ReactElement {
const {environment, environmentURL} = useContext(EnvironmentContext) ?? {};
const {environment, environmentURL} = useContext(EnvironmentContext);
return (
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {EnvironmentContext} from '@components/withEnvironment';
import type {EnvironmentContextValue} from '@components/withEnvironment';
import CONST from '@src/CONST';

type UseEnvironment = Partial<EnvironmentContextValue> & {
type UseEnvironment = EnvironmentContextValue & {
isProduction: boolean;
isDevelopment: boolean;
};

export default function useEnvironment(): UseEnvironment {
const {environment, environmentURL} = useContext(EnvironmentContext) ?? {};
const {environment, environmentURL} = useContext(EnvironmentContext);
return {
environment,
environmentURL,
Expand Down
2 changes: 1 addition & 1 deletion src/styles/StyleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ function getBorderColorStyle(borderColor: string): ViewStyle {
/**
* Returns the width style for the wordmark logo on the sign in page
*/
function getSignInWordmarkWidthStyle(isSmallScreenWidth: boolean, environment?: ValueOf<typeof CONST.ENVIRONMENT>): ViewStyle {
function getSignInWordmarkWidthStyle(isSmallScreenWidth: boolean, environment: ValueOf<typeof CONST.ENVIRONMENT>): ViewStyle {
if (environment === CONST.ENVIRONMENT.DEV) {
return isSmallScreenWidth ? {width: variables.signInLogoWidthPill} : {width: variables.signInLogoWidthLargeScreenPill};
}
Expand Down

0 comments on commit 6bfef02

Please sign in to comment.