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

Remove POC Form primitive #755

Merged
merged 5 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion packages/react/__tests__/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('@aws-amplify/ui-react', () => {
"FieldGroupIcon",
"FieldGroupIconButton",
"Flex",
"Form",
"Grid",
"Heading",
"Icon",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
} from '@aws-amplify/ui';

import { useAuthenticator } from '..';
import { Flex, Form, Heading } from '../../..';
import { Flex, Heading } from '../../..';
import { ConfirmationCodeInput, ConfirmSignInFooter } from '../shared';
import { isInputEventTarget } from '../../../helpers/utils';

export const ConfirmSignIn = (): JSX.Element => {
const { _state, error, submitForm, updateForm } = useAuthenticator();
Expand All @@ -29,12 +30,13 @@ export const ConfirmSignIn = (): JSX.Element => {
`Unexpected challengeName encountered in ConfirmSignIn: ${challengeName}`
);
}
const handleChange = (event: React.FormEvent<HTMLFormElement>) => {
if (isInputEventTarget(event.target)) {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;

updateForm({ name, value });
updateForm({ name, value });
}
};

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -43,7 +45,8 @@ export const ConfirmSignIn = (): JSX.Element => {
};

return (
<Form
<form
data-amplify-form=""
data-amplify-authenticator-confirmsignin=""
method="post"
onChange={handleChange}
Expand All @@ -58,6 +61,6 @@ export const ConfirmSignIn = (): JSX.Element => {

<ConfirmSignInFooter />
</Flex>
</Form>
</form>
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { translate } from '@aws-amplify/ui';

import { useAuthenticator } from '../..';
import { Button, Flex, Form, Heading } from '../../..';
import { Button, Flex, Heading } from '../../..';
import { isInputEventTarget } from '../../../helpers/utils';

import {
ConfirmationCodeInput,
ConfirmationCodeInputProps,
Expand All @@ -11,11 +13,13 @@ import {
export function ConfirmSignUp() {
const { isPending, resendCode, submitForm, updateForm } = useAuthenticator();

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;
const handleChange = (event: React.FormEvent<HTMLFormElement>) => {
if (isInputEventTarget(event.target)) {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;

updateForm({ name, value });
updateForm({ name, value });
}
};

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -30,7 +34,8 @@ export function ConfirmSignUp() {

return (
// TODO Automatically add these namespaces again from `useAmplify`
<Form
<form
data-amplify-form=""
data-amplify-authenticator-confirmsignup=""
method="post"
onChange={handleChange}
Expand Down Expand Up @@ -60,6 +65,6 @@ export function ConfirmSignUp() {
</Button>
</Flex>
</Flex>
</Form>
</form>
);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { getActorContext, SignInContext, translate } from '@aws-amplify/ui';

import { useAuthenticator } from '..';
import { Button, Flex, Form, Heading, PasswordField, Text } from '../../..';
import { Button, Flex, Heading, PasswordField, Text } from '../../..';
import { isInputEventTarget } from '../../../helpers/utils';

export const ForceNewPassword = (): JSX.Element => {
const { _state, error, isPending, toSignIn, submitForm, updateForm } =
useAuthenticator();
const { validationError } = getActorContext(_state) as SignInContext;

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;
const handleChange = (event: React.FormEvent<HTMLFormElement>) => {
if (isInputEventTarget(event.target)) {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;

updateForm({ name, value });
updateForm({ name, value });
}
};

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -21,7 +24,8 @@ export const ForceNewPassword = (): JSX.Element => {
};

return (
<Form
<form
data-amplify-form=""
data-amplify-authenticator-forcenewpassword=""
method="post"
onChange={handleChange}
Expand Down Expand Up @@ -83,6 +87,6 @@ export const ForceNewPassword = (): JSX.Element => {
{translate('Back to Sign In')}
</Button>
</Flex>
</Form>
</form>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
} from '@aws-amplify/ui';

import { useAuthenticator } from '..';
import { Flex, Form, Heading, PasswordField, Text } from '../../..';
import { Flex, Heading, PasswordField, Text } from '../../..';
import {
ConfirmationCodeInput,
RemoteErrorMessage,
TwoButtonSubmitFooter,
} from '../shared';
import { isInputEventTarget } from '../../../helpers/utils';

export const ConfirmResetPassword = (): JSX.Element => {
const { _state, submitForm, updateForm } = useAuthenticator();
Expand All @@ -20,11 +21,13 @@ export const ConfirmResetPassword = (): JSX.Element => {
const passwordText = translate('New password');
const confirmPasswordLabel = translate('Confirm Password');

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;
const handleChange = (event: React.FormEvent<HTMLFormElement>) => {
if (isInputEventTarget(event.target)) {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;

updateForm({ name, value });
updateForm({ name, value });
}
};

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -33,7 +36,8 @@ export const ConfirmResetPassword = (): JSX.Element => {
};

return (
<Form
<form
data-amplify-form=""
data-amplify-authenticator-confirmresetpassword=""
method="post"
onSubmit={handleSubmit}
Expand Down Expand Up @@ -77,6 +81,6 @@ export const ConfirmResetPassword = (): JSX.Element => {
cancelButtonText={translate('Resend Code')}
/>
</Flex>
</Form>
</form>
);
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { translate } from '@aws-amplify/ui';

import { useAuthenticator } from '..';
import { Flex, Form, Heading, TextField } from '../../..';
import { Flex, Heading, TextField } from '../../..';
import { RemoteErrorMessage, TwoButtonSubmitFooter } from '../shared';
import { isInputEventTarget } from '../../../helpers/utils';

export const ResetPassword = (): JSX.Element => {
const { isPending, submitForm, updateForm } = useAuthenticator();

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;
const handleChange = (event: React.FormEvent<HTMLFormElement>) => {
if (isInputEventTarget(event.target)) {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;

updateForm({ name, value });
updateForm({ name, value });
}
};

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -20,7 +23,8 @@ export const ResetPassword = (): JSX.Element => {
};

return (
<Form
<form
data-amplify-form=""
data-amplify-authenticator-resetpassword=""
method="post"
onChange={handleChange}
Expand Down Expand Up @@ -54,6 +58,6 @@ export const ResetPassword = (): JSX.Element => {
}
/>
</Flex>
</Form>
</form>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import QRCode from 'qrcode';
import { useEffect, useState } from 'react';

import { useAuthenticator } from '..';
import { Flex, Form, Heading, Image } from '../../..';
import { Flex, Heading, Image } from '../../..';
import { isInputEventTarget } from '../../../helpers/utils';

import {
ConfirmationCodeInput,
ConfirmSignInFooter,
Expand Down Expand Up @@ -44,11 +46,13 @@ export const SetupTOTP = (): JSX.Element => {
generateQRCode(user);
}, [user]);

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;
const handleChange = (event: React.FormEvent<HTMLFormElement>) => {
if (isInputEventTarget(event.target)) {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;

updateForm({ name, value });
updateForm({ name, value });
}
};

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -57,7 +61,8 @@ export const SetupTOTP = (): JSX.Element => {
};

return (
<Form
<form
data-amplify-form=""
data-amplify-authenticator-setup-totp=""
method="post"
onChange={handleChange}
Expand Down Expand Up @@ -85,6 +90,6 @@ export const SetupTOTP = (): JSX.Element => {

<ConfirmSignInFooter />
</Flex>
</Form>
</form>
);
};
18 changes: 11 additions & 7 deletions packages/react/src/components/Authenticator/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { translate } from '@aws-amplify/ui';

import { useAuthenticator } from '..';
import { Button, Flex, Form, Heading, PasswordField, View } from '../../..';
import { Button, Flex, PasswordField, View } from '../../..';
import { FederatedSignIn } from '../FederatedSignIn';
import { RemoteErrorMessage, UserNameAlias } from '../shared';
import { isInputEventTarget } from '../../../helpers/utils';

export function SignIn() {
const {
Expand All @@ -15,11 +16,13 @@ export function SignIn() {
updateForm,
} = useAuthenticator();

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;
const handleChange = (event: React.FormEvent<HTMLFormElement>) => {
if (isInputEventTarget(event.target)) {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;

updateForm({ name, value });
updateForm({ name, value });
}
};

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -31,7 +34,8 @@ export function SignIn() {
<View>
<Header />

<Form
<form
data-amplify-form=""
data-amplify-authenticator-signin=""
method="post"
onSubmit={handleSubmit}
Expand Down Expand Up @@ -66,7 +70,7 @@ export function SignIn() {
{translate('Sign in')}
</Button>
</Flex>
</Form>
</form>

<Footer />
</View>
Expand Down
18 changes: 11 additions & 7 deletions packages/react/src/components/Authenticator/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { translate } from '@aws-amplify/ui';

import { useAuthenticator } from '..';
import { Button, Flex, Form, View } from '../../..';
import { Button, Flex, View } from '../../..';
import { FederatedSignIn } from '../FederatedSignIn';
import { RemoteErrorMessage } from '../shared';
import { FormFields } from './FormFields';
import { isInputEventTarget } from '../../../helpers/utils';

export function SignUp() {
const { components, hasValidationErrors, isPending, submitForm, updateForm } =
Expand All @@ -20,11 +21,13 @@ export function SignUp() {

console.log({ components });

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;
const handleChange = (event: React.FormEvent<HTMLFormElement>) => {
if (isInputEventTarget(event.target)) {
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;

updateForm({ name, value });
updateForm({ name, value });
}
};

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -36,7 +39,8 @@ export function SignUp() {
<View>
<Header />

<Form
<form
data-amplify-form=""
data-amplify-authenticator-signup=""
method="post"
onChange={handleChange}
Expand All @@ -63,7 +67,7 @@ export function SignUp() {
{translate('Create Account')}
</Button>
</Flex>
</Form>
</form>

<Footer />
</View>
Expand Down
Loading