Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS Migration] Update EnvironmentContext default value #31824

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/EnvironmentBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function EnvironmentBadge() {
const {environment} = useEnvironment();

// If we are on production, don't show any badge
if (environment === CONST.ENVIRONMENT.PRODUCTION || environment === undefined) {
if (environment === CONST.ENVIRONMENT.PRODUCTION) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (environment === CONST.ENVIRONMENT.PRODUCTION) {
if (isProduction) {

NAB: I guess this can be simplified. we need to destruct isProduction from useEnvironment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fedirjh Done!

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
Loading