Skip to content

Commit

Permalink
feat(clerk-js,types,localizations): Add maintenance mode banner to Si…
Browse files Browse the repository at this point in the history
…gnIn and SignUp
  • Loading branch information
nikosdouvlis committed Apr 6, 2024
1 parent 064af2c commit 222acd8
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/polite-toys-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/localizations': patch
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Add maintenance mode banner to the SignIn and SignUp components. The text can be customized by updating the `maintenanceMode` localization key.
2 changes: 2 additions & 0 deletions packages/clerk-js/src/core/resources/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class Environment extends BaseResource implements EnvironmentResource {
displayConfig!: DisplayConfigResource;
userSettings!: UserSettingsResource;
organizationSettings!: OrganizationSettingsResource;
maintenanceMode!: boolean;

public static getInstance(): Environment {
if (!Environment.instance) {
Expand Down Expand Up @@ -71,6 +72,7 @@ export class Environment extends BaseResource implements EnvironmentResource {
this.displayConfig = new DisplayConfig(data.display_config);
this.userSettings = new UserSettings(data.user_settings);
this.organizationSettings = new OrganizationSettings(data.organization_settings);
this.maintenanceMode = data.maintenance_mode;
}
return this;
}
Expand Down
11 changes: 10 additions & 1 deletion packages/clerk-js/src/ui/elements/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { LocalizationKey } from '../customizables';
import { Alert as AlertCust, AlertIcon, Col, descriptors, Text } from '../customizables';
import type { PropsOfComponent } from '../styledSystem';
import { animations } from '../styledSystem';
import { colors } from '../utils';

type _AlertProps = {
variant?: 'danger' | 'warning';
Expand All @@ -24,7 +25,14 @@ export const Alert = (props: AlertProps): JSX.Element | null => {
<AlertCust
elementDescriptor={descriptors.alert}
elementId={descriptors.alert.setId(variant)}
align='start'
{...rest}
sx={[
t => ({
backgroundColor: variant === 'warning' ? colors.makeTransparent(t.colors.$warning500, 0.94) : undefined,
}),
rest.sx,
]}
>
<AlertIcon
elementId={descriptors.alert.setId(variant)}
Expand All @@ -41,9 +49,10 @@ export const Alert = (props: AlertProps): JSX.Element | null => {
<Text
elementDescriptor={descriptors.alertText}
elementId={descriptors.alert.setId(variant)}
colorScheme='neutral'
colorScheme={variant === 'danger' ? 'neutral' : 'warning'}
variant='smallRegular'
localizationKey={title}
sx={{ textAlign: 'left' }}
>
{children}
</Text>
Expand Down
14 changes: 13 additions & 1 deletion packages/clerk-js/src/ui/elements/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import React from 'react';

import { useEnvironment } from '../contexts';
import { descriptors, Flex, generateFlowPartClassname, Icon, useAppearance } from '../customizables';
import {
descriptors,
Flex,
generateFlowPartClassname,
Icon,
localizationKeys,
useAppearance,
useLocalizations,
} from '../customizables';
import type { ElementDescriptor } from '../customizables/elementDescriptors';
import { Close } from '../icons';
import type { PropsOfComponent, ThemableCssProp } from '../styledSystem';
import { mqu } from '../styledSystem';
import { CardAlert } from './Alert';
import { ApplicationLogo } from './ApplicationLogo';
import { useFlowMetadata } from './contexts';
import { IconButton } from './IconButton';
Expand All @@ -22,6 +31,8 @@ export const Card = React.forwardRef<HTMLDivElement, CardProps>((props, ref) =>
const appearance = useAppearance();
const flowMetadata = useFlowMetadata();
const { branded } = useEnvironment().displayConfig;
const { maintenanceMode } = useEnvironment();
const { t } = useLocalizations();

return (
<>
Expand Down Expand Up @@ -58,6 +69,7 @@ export const Card = React.forwardRef<HTMLDivElement, CardProps>((props, ref) =>
]}
ref={ref}
>
{maintenanceMode && <CardAlert variant='warning'>{t(localizationKeys('maintenanceMode'))}</CardAlert>}
{appearance.parsedLayout.logoPlacement === 'inside' && <ApplicationLogo sx={insideAppLogoSx} />}
{children}
{branded && <PoweredByClerkTag />}
Expand Down
4 changes: 2 additions & 2 deletions packages/clerk-js/src/ui/primitives/AlertIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExclamationCircle, ExclamationTriangle } from '../icons';
import { ExclamationTriangle } from '../icons';
import type { StyleVariants } from '../styledSystem';
import { createVariants } from '../styledSystem';

Expand All @@ -24,7 +24,7 @@ export type AlertIconProps = OwnProps & StyleVariants<typeof applyVariants>;

export const AlertIcon = (props: AlertIconProps): JSX.Element => {
const { variant, ...rest } = props;
const Icon = variant === 'warning' ? ExclamationCircle : ExclamationTriangle;
const Icon = ExclamationTriangle;
return (
<Icon
{...filterProps(rest)}
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/ui/primitives/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const { applyVariants, filterProps } = createVariants(theme => {
primary: { color: theme.colors.$colorText },
onPrimaryBg: { color: theme.colors.$colorTextOnPrimaryBackground },
danger: { color: theme.colors.$danger500 },
warning: { color: theme.colors.$warning500 },
success: { color: theme.colors.$success500 },
neutral: { color: theme.colors.$colorTextSecondary },
inherit: { color: 'inherit' },
Expand Down
2 changes: 2 additions & 0 deletions packages/localizations/src/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const commonTexts = {

export const enUS: LocalizationResource = {
locale: 'en-US',
maintenanceMode:
"We are currently undergoing maintenance, but don't worry, it shouldn't take more than a few minutes.",
socialButtonsBlockButton: 'Continue with {{provider|titleize}}',
dividerText: 'or',
formFieldLabel__emailAddress: 'Email address',
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface EnvironmentResource extends ClerkResource {
isProduction: () => boolean;
isDevelopmentOrStaging: () => boolean;
onWindowLocationHost: () => boolean;
maintenanceMode: boolean;
}
1 change: 1 addition & 0 deletions packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface EnvironmentJSON extends ClerkResourceJSON {
display_config: DisplayConfigJSON;
user_settings: UserSettingsJSON;
organization_settings: OrganizationSettingsJSON;
maintenance_mode: boolean;
}

export interface ClientJSON extends ClerkResourceJSON {
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ type _LocalizationResource = {
next6Days: LocalizationValue;
numeric: LocalizationValue;
};
maintenanceMode: LocalizationValue;
};

type WithParamName<T> = T &
Expand Down

0 comments on commit 222acd8

Please sign in to comment.