Skip to content

Commit

Permalink
Error => ErrorMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
wlee221 committed Dec 2, 2022
1 parent fd89223 commit 59dae77
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,16 @@ function ChangePassword({
const updatePasswordText = translate('Update password');

/* Subcomponents */
const { CurrentPassword, NewPassword, ConfirmPassword, SubmitButton, Error } =
React.useMemo(() => ({ ...DEFAULTS, ...(components ?? {}) }), [components]);
const {
CurrentPassword,
NewPassword,
ConfirmPassword,
SubmitButton,
ErrorMessage,
} = React.useMemo(
() => ({ ...DEFAULTS, ...(components ?? {}) }),
[components]
);

/* Event Handlers */
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -208,7 +216,7 @@ function ChangePassword({
<SubmitButton isDisabled={isDisabled} type="submit">
{updatePasswordText}
</SubmitButton>
{errorMessage ? <Error>{errorMessage}</Error> : null}
{errorMessage ? <ErrorMessage>{errorMessage}</ErrorMessage> : null}
</Flex>
</View>
);
Expand All @@ -218,6 +226,6 @@ ChangePassword.CurrentPassword = DEFAULTS.CurrentPassword;
ChangePassword.NewPassword = DEFAULTS.NewPassword;
ChangePassword.ConfirmPassword = DEFAULTS.ConfirmPassword;
ChangePassword.SubmitButton = DEFAULTS.SubmitButton;
ChangePassword.Error = DEFAULTS.Error;
ChangePassword.ErrorMessage = DEFAULTS.ErrorMessage;

export default ChangePassword;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Button, PasswordField } from '../../../primitives';
import { ValidationErrors } from '../../shared/ValidationErrors';
import { DefaultError } from '../shared/Defaults';
import { DefaultErrorMessage } from '../shared/Defaults';
import { PasswordFieldComponent } from '../types';
import { ChangePasswordComponents } from './types';

Expand All @@ -23,7 +23,7 @@ const DEFAULTS: Required<ChangePasswordComponents> = {
NewPassword: DefaultPasswordField,
ConfirmPassword: DefaultPasswordField,
SubmitButton: Button,
Error: DefaultError,
ErrorMessage: DefaultErrorMessage,
};

export default DEFAULTS;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InputEventType, ValidatorOptions } from '@aws-amplify/ui';
import {
ErrorComponent,
ErrorMessageComponent,
PasswordFieldComponent,
SubmitButtonComponent,
FormValues,
Expand All @@ -11,7 +11,7 @@ export interface ChangePasswordComponents {
NewPassword?: PasswordFieldComponent;
ConfirmPassword?: PasswordFieldComponent;
SubmitButton?: SubmitButtonComponent;
Error?: ErrorComponent;
ErrorMessage?: ErrorMessageComponent;
}

export type ValidateParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function DeleteUser({
const { user, isLoading } = useAuth();

// subcomponents
const { Error, DeleteButton, Warning } = React.useMemo(
const { ErrorMessage, DeleteButton, Warning } = React.useMemo(
() => ({ ...DEFAULTS, ...(components ?? {}) }),
[components]
);
Expand Down Expand Up @@ -101,12 +101,12 @@ function DeleteUser({
onConfirm={handleConfirmDelete}
/>
) : null}
{errorMessage ? <Error>{errorMessage}</Error> : null}
{errorMessage ? <ErrorMessage>{errorMessage}</ErrorMessage> : null}
</Flex>
);
}

DeleteUser.Error = DEFAULTS.Error;
DeleteUser.ErrorMessage = DEFAULTS.ErrorMessage;
DeleteUser.DeleteButton = DEFAULTS.DeleteButton;
DeleteUser.Warning = DEFAULTS.Warning;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const CustomDeleteButton = ({ onClick, isDisabled }) => {
);
};

const CustomError = ({ children }) => (
const CustomErrorMessage = ({ children }) => (
<>
<Heading>Custom Error Message</Heading>
<Text>{children}</Text>
Expand All @@ -47,7 +47,7 @@ const CustomError = ({ children }) => (
const components: DeleteUserComponents = {
DeleteButton: CustomDeleteButton,
Warning: CustomWarning,
Error: CustomError,
ErrorMessage: CustomErrorMessage,
};

describe('DeleteUser', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { translate } from '@aws-amplify/ui';

import { Button, Card, Flex, Text } from '../../../primitives';
import { DefaultError } from '../shared/Defaults';
import { DefaultErrorMessage } from '../shared/Defaults';
import { DeleteUserComponents, WarningComponent } from './types';

const DefaultWarning: WarningComponent = ({
Expand Down Expand Up @@ -40,7 +40,7 @@ const DefaultWarning: WarningComponent = ({
};

const DEFAULTS: Required<DeleteUserComponents> = {
Error: DefaultError,
ErrorMessage: DefaultErrorMessage,
DeleteButton: Button,
Warning: DefaultWarning,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import { AmplifyUser } from '@aws-amplify/ui';

import { ButtonComponent, ErrorComponent } from '../types';
import { ButtonComponent, ErrorMessageComponent } from '../types';

export interface WarningProps {
/** called when end user cancels account deletion */
Expand All @@ -25,7 +25,7 @@ export type DeleteUserState =
| 'ERROR';

export interface DeleteUserComponents {
Error?: ErrorComponent;
ErrorMessage?: ErrorMessageComponent;
DeleteButton?: ButtonComponent;
Warning?: WarningComponent;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Alert } from '../../../primitives';
import { ErrorComponent } from '../types';
import { ErrorMessageComponent } from '../types';

export const DefaultError: ErrorComponent = (props) => {
export const DefaultErrorMessage: ErrorMessageComponent = (props) => {
return <Alert variation="error" {...props} />;
};
2 changes: 1 addition & 1 deletion packages/react/src/components/AccountSettings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type SubmitButtonComponent<Props = {}> = React.ComponentType<
Props & CommonButtonProps<'submit'>
>;

export type ErrorComponent<Props = {}> = React.ComponentType<
export type ErrorMessageComponent<Props = {}> = React.ComponentType<
Props & CommonAlertProps
>;

Expand Down

0 comments on commit 59dae77

Please sign in to comment.