Skip to content

Commit

Permalink
chore(AccountSettings): update subcomponent names and types (#3134)
Browse files Browse the repository at this point in the history
* chore(AccountSettings): update subcomponent names and types

* Update packages/react/src/components/AccountSettings/types.ts

Co-authored-by: William Lee <43682783+wlee221@users.noreply.github.com>

Co-authored-by: William Lee <43682783+wlee221@users.noreply.github.com>
  • Loading branch information
calebpollman and wlee221 authored Dec 5, 2022
1 parent 6b30ffa commit a19b117
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ function ChangePassword({

/* Subcomponents */
const {
CurrentPassword,
NewPassword,
ConfirmPassword,
CurrentPasswordField,
NewPasswordField,
ConfirmPasswordField,
SubmitButton,
ErrorMessage,
} = React.useMemo(
Expand Down Expand Up @@ -192,31 +192,31 @@ function ChangePassword({
onSubmit={handleSubmit}
>
<Flex direction="column">
<CurrentPassword
<CurrentPasswordField
autoComplete="current-password"
isRequired
label={currentPasswordLabel}
name="currentPassword"
onBlur={handleBlur}
onChange={handleChange}
/>
<NewPassword
<NewPasswordField
autoComplete="new-password"
fieldValidationErrors={validationError?.newPassword}
isRequired
label={newPasswordLabel}
name="newPassword"
onBlur={handleBlur}
onChange={handleChange}
validationErrors={validationError?.newPassword}
/>
<ConfirmPassword
<ConfirmPasswordField
autoComplete="new-password"
fieldValidationErrors={validationError?.confirmPassword}
isRequired
label={confirmPasswordLabel}
name="confirmPassword"
onBlur={handleBlur}
onChange={handleChange}
validationErrors={validationError?.confirmPassword}
/>
<SubmitButton isDisabled={isDisabled} type="submit">
{updatePasswordText}
Expand All @@ -227,9 +227,9 @@ function ChangePassword({
);
}

ChangePassword.CurrentPassword = DEFAULTS.CurrentPassword;
ChangePassword.NewPassword = DEFAULTS.NewPassword;
ChangePassword.ConfirmPassword = DEFAULTS.ConfirmPassword;
ChangePassword.CurrentPasswordField = DEFAULTS.CurrentPasswordField;
ChangePassword.NewPasswordField = DEFAULTS.NewPasswordField;
ChangePassword.ConfirmPasswordField = DEFAULTS.ConfirmPasswordField;
ChangePassword.SubmitButton = DEFAULTS.SubmitButton;
ChangePassword.ErrorMessage = DEFAULTS.ErrorMessage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { ChangePasswordComponents } from '../types';
import { ComponentClassName } from '../../constants';

const components: ChangePasswordComponents = {
CurrentPassword: (props) => (
<ChangePassword.CurrentPassword
CurrentPasswordField: (props) => (
<ChangePassword.CurrentPasswordField
{...props}
label="Custom Current Password"
/>
),
NewPassword: (props) => (
<ChangePassword.NewPassword {...props} label="Custom New Password" />
NewPasswordField: (props) => (
<ChangePassword.NewPasswordField {...props} label="Custom New Password" />
),
ConfirmPassword: (props) => (
<ChangePassword.ConfirmPassword
ConfirmPasswordField: (props) => (
<ChangePassword.ConfirmPasswordField
{...props}
label="Custom Confirm Password"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import { PasswordFieldComponent } from '../types';
import { ChangePasswordComponents } from './types';

const DefaultPasswordField: PasswordFieldComponent = ({
fieldValidationErrors,
label,
validationErrors,
...rest
}) => {
return (
<>
<PasswordField label={label} {...rest} />
<ValidationErrors errors={validationErrors} />
<PasswordField {...rest} label={label} />
<ValidationErrors errors={fieldValidationErrors} />
</>
);
};

const DEFAULTS: Required<ChangePasswordComponents> = {
CurrentPassword: DefaultPasswordField,
NewPassword: DefaultPasswordField,
ConfirmPassword: DefaultPasswordField,
CurrentPasswordField: DefaultPasswordField,
NewPasswordField: DefaultPasswordField,
ConfirmPasswordField: DefaultPasswordField,
SubmitButton: Button,
ErrorMessage: DefaultErrorMessage,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { InputEventType, ValidatorOptions } from '@aws-amplify/ui';
import {
SubmitButtonComponent,
ErrorMessageComponent,
PasswordFieldComponent,
SubmitButtonComponent,
FormValues,
} from '../types';

export interface ChangePasswordComponents {
CurrentPassword?: PasswordFieldComponent;
NewPassword?: PasswordFieldComponent;
ConfirmPassword?: PasswordFieldComponent;
SubmitButton?: SubmitButtonComponent;
ConfirmPasswordField?: PasswordFieldComponent;
CurrentPasswordField?: PasswordFieldComponent;
ErrorMessage?: ErrorMessageComponent;
NewPasswordField?: PasswordFieldComponent;
SubmitButton?: SubmitButtonComponent;
}

export type ValidateParams = {
export interface ValidateParams {
formValues: FormValues;
eventType: InputEventType;
};
}

export interface ChangePasswordProps {
/** callback once password is successfully updated */
onSuccess?: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function DeleteUser({
const { user, isLoading } = useAuth();

// subcomponents
const { ErrorMessage, DeleteButton, Warning } = React.useMemo(
const { ErrorMessage, DeleteButton, WarningView } = React.useMemo(
() => ({ ...DEFAULTS, ...(components ?? {}) }),
[components]
);
Expand Down Expand Up @@ -96,7 +96,7 @@ function DeleteUser({
{deleteAccountText}
</DeleteButton>
{state === 'CONFIRMATION' || state === 'DELETING' ? (
<Warning
<WarningView
onCancel={handleCancel}
isDisabled={state === 'DELETING'}
onConfirm={handleConfirmDelete}
Expand All @@ -109,6 +109,6 @@ function DeleteUser({

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

export default DeleteUser;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jest.mock('../../../../internal', () => ({

const deleteUserSpy = jest.spyOn(UIModule, 'deleteUser');

function CustomWarning({ onCancel, onConfirm }) {
function CustomWarningView({ onCancel, onConfirm }) {
return (
<Flex direction="column">
<Text variation="warning">Custom Warning Message</Text>
Expand Down Expand Up @@ -47,7 +47,7 @@ const CustomErrorMessage = ({ children }) => (

const components: DeleteUserComponents = {
DeleteButton: CustomDeleteButton,
Warning: CustomWarning,
WarningView: CustomWarningView,
ErrorMessage: CustomErrorMessage,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { translate } from '@aws-amplify/ui';

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

const DefaultWarning: WarningComponent = ({
const DefaultWarningView: WarningViewComponent = ({
onCancel,
onConfirm,
isDisabled,
Expand Down Expand Up @@ -42,7 +42,7 @@ const DefaultWarning: WarningComponent = ({
const DEFAULTS: Required<DeleteUserComponents> = {
ErrorMessage: DefaultErrorMessage,
DeleteButton: Button,
Warning: DefaultWarning,
WarningView: DefaultWarningView,
};

export default DEFAULTS;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AmplifyUser } from '@aws-amplify/ui';

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

export interface WarningProps {
export interface WarningViewProps {
/** called when end user cancels account deletion */
onCancel: () => void;
/** called when user acknowledges account deletion */
Expand All @@ -13,8 +13,8 @@ export interface WarningProps {
isDisabled: boolean;
}

export type WarningComponent<Props = {}> = React.ComponentType<
Props & WarningProps
export type WarningViewComponent<Props = {}> = React.ComponentType<
Props & WarningViewProps
>;

export type DeleteUserState =
Expand All @@ -27,7 +27,7 @@ export type DeleteUserState =
export interface DeleteUserComponents {
ErrorMessage?: ErrorMessageComponent;
DeleteButton?: ButtonComponent;
Warning?: WarningComponent;
WarningView?: WarningViewComponent;
}

export interface DeleteUserProps {
Expand Down
14 changes: 9 additions & 5 deletions packages/react/src/components/AccountSettings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ type AlertPrimitiveProps = PrimitiveProps<AlertProps, 'div'>;
* Any essential props for overriding components are marked as required.
*/
type CommonPasswordFieldProps = Partial<PasswordFieldPrimitiveProps> &
Required<Pick<PasswordFieldPrimitiveProps, 'onBlur' | 'onChange' | 'name'>>;
Required<
Pick<PasswordFieldPrimitiveProps, 'onBlur' | 'onChange' | 'name'>
> & { fieldValidationErrors?: string[] };

type CommonAlertProps = Partial<PrimitiveProps<AlertProps, 'div'>> &
Required<Pick<AlertPrimitiveProps, 'children'>>;
type CommonButtonProps<T = 'submit' | 'default'> =

type CommonButtonProps<T extends 'submit' | 'default' = 'default'> =
Partial<ButtonPrimitiveProps> &
Required<
Pick<
Expand All @@ -35,14 +39,14 @@ type CommonButtonProps<T = 'submit' | 'default'> =

/*
* These are component override types.
* Usage of `Props` generic allows additional props passed on override components
*/
export type PasswordFieldComponent<Props = {}> = React.ComponentType<
// `Props` generic allows additional props passed on override components
Props & CommonPasswordFieldProps & { validationErrors?: string[] }
Props & CommonPasswordFieldProps
>;

export type ButtonComponent<Props = {}> = React.ComponentType<
Props & CommonButtonProps<'default'>
Props & CommonButtonProps
>;

export type SubmitButtonComponent<Props = {}> = React.ComponentType<
Expand Down

0 comments on commit a19b117

Please sign in to comment.