@aws-amplify/ui-react-native 2.4.4 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Authenticator/Authenticator.d.ts +33 -0
- package/dist/Authenticator/Authenticator.js +5 -1
- package/dist/Authenticator/Defaults/SelectMfaType/SelectMfaType.d.ts +14 -0
- package/dist/Authenticator/Defaults/SelectMfaType/SelectMfaType.js +39 -0
- package/dist/Authenticator/Defaults/SelectMfaType/index.d.ts +1 -0
- package/dist/Authenticator/Defaults/SelectMfaType/index.js +1 -0
- package/dist/Authenticator/Defaults/SetupEmail/SetupEmail.d.ts +14 -0
- package/dist/Authenticator/Defaults/SetupEmail/SetupEmail.js +39 -0
- package/dist/Authenticator/Defaults/SetupEmail/index.d.ts +1 -0
- package/dist/Authenticator/Defaults/SetupEmail/index.js +1 -0
- package/dist/Authenticator/Defaults/VerifyUser/VerifyUser.js +2 -2
- package/dist/Authenticator/Defaults/index.d.ts +3 -1
- package/dist/Authenticator/Defaults/index.js +2 -0
- package/dist/Authenticator/Defaults/types.d.ts +42 -0
- package/dist/Authenticator/common/DefaultContainer/index.d.ts +1 -1
- package/dist/Authenticator/common/DefaultFormFields/DefaultSelectMfaTypeFormFields.d.ts +7 -0
- package/dist/Authenticator/common/DefaultFormFields/DefaultSelectMfaTypeFormFields.js +12 -0
- package/dist/Authenticator/common/DefaultFormFields/{DefaultRadioFormFields.d.ts → DefaultVerifyUserFormFields.d.ts} +2 -2
- package/dist/Authenticator/common/DefaultFormFields/{DefaultRadioFormFields.js → DefaultVerifyUserFormFields.js} +7 -5
- package/dist/Authenticator/common/DefaultFormFields/index.d.ts +2 -1
- package/dist/Authenticator/common/DefaultFormFields/index.js +2 -1
- package/dist/Authenticator/hooks/useFieldValues/useFieldValues.js +52 -19
- package/dist/Authenticator/hooks/useFieldValues/utils.d.ts +2 -1
- package/dist/Authenticator/hooks/useFieldValues/utils.js +26 -3
- package/dist/Authenticator/index.d.ts +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/primitives/RadioGroup/RadioGroup.d.ts +1 -0
- package/dist/primitives/RadioGroup/RadioGroup.js +2 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/lib/Authenticator/Authenticator.js +4 -0
- package/lib/Authenticator/Defaults/SelectMfaType/SelectMfaType.js +42 -0
- package/lib/Authenticator/Defaults/SelectMfaType/index.js +8 -0
- package/lib/Authenticator/Defaults/SetupEmail/SetupEmail.js +42 -0
- package/lib/Authenticator/Defaults/SetupEmail/index.js +8 -0
- package/lib/Authenticator/Defaults/VerifyUser/VerifyUser.js +1 -1
- package/lib/Authenticator/Defaults/index.js +5 -1
- package/lib/Authenticator/common/DefaultFormFields/DefaultSelectMfaTypeFormFields.js +15 -0
- package/lib/Authenticator/common/DefaultFormFields/{DefaultRadioFormFields.js → DefaultVerifyUserFormFields.js} +7 -5
- package/lib/Authenticator/common/DefaultFormFields/index.js +5 -3
- package/lib/Authenticator/hooks/useFieldValues/useFieldValues.js +51 -18
- package/lib/Authenticator/hooks/useFieldValues/utils.js +29 -5
- package/lib/primitives/RadioGroup/RadioGroup.js +3 -1
- package/lib/version.js +1 -1
- package/package.json +4 -4
- package/src/Authenticator/Authenticator.tsx +6 -0
- package/src/Authenticator/Defaults/SelectMfaType/SelectMfaType.tsx +87 -0
- package/src/Authenticator/Defaults/SelectMfaType/index.ts +1 -0
- package/src/Authenticator/Defaults/SetupEmail/SetupEmail.tsx +86 -0
- package/src/Authenticator/Defaults/SetupEmail/index.ts +1 -0
- package/src/Authenticator/Defaults/VerifyUser/VerifyUser.tsx +2 -2
- package/src/Authenticator/Defaults/index.ts +18 -1
- package/src/Authenticator/Defaults/types.ts +42 -0
- package/src/Authenticator/common/DefaultContainer/index.ts +1 -1
- package/src/Authenticator/common/DefaultFormFields/DefaultSelectMfaTypeFormFields.tsx +35 -0
- package/src/Authenticator/common/DefaultFormFields/{DefaultRadioFormFields.tsx → DefaultVerifyUserFormFields.tsx} +8 -7
- package/src/Authenticator/common/DefaultFormFields/index.ts +2 -1
- package/src/Authenticator/hooks/useFieldValues/useFieldValues.ts +65 -21
- package/src/Authenticator/hooks/useFieldValues/utils.ts +40 -5
- package/src/Authenticator/index.ts +15 -0
- package/src/index.ts +12 -0
- package/src/primitives/RadioGroup/RadioGroup.tsx +7 -1
- package/src/version.ts +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
+
const ui_1 = require("@aws-amplify/ui");
|
|
6
|
+
const common_1 = require("../../common");
|
|
7
|
+
const hooks_1 = require("../../hooks");
|
|
8
|
+
const COMPONENT_NAME = 'SelectMfaType';
|
|
9
|
+
const { getSelectMfaTypeByChallengeName, getBackToSignInText, getConfirmText, getConfirmingText, } = ui_1.authenticatorTextUtil;
|
|
10
|
+
const SelectMfaType = ({ challengeName, fields, handleBlur, handleChange, handleSubmit, isPending, toSignIn, validationErrors, ...rest }) => {
|
|
11
|
+
const { disableFormSubmit: disabled, fields: fieldsWithHandlers, fieldValidationErrors, handleFormSubmit, } = (0, hooks_1.useFieldValues)({
|
|
12
|
+
componentName: COMPONENT_NAME,
|
|
13
|
+
fields,
|
|
14
|
+
handleBlur,
|
|
15
|
+
handleChange,
|
|
16
|
+
handleSubmit,
|
|
17
|
+
validationErrors,
|
|
18
|
+
});
|
|
19
|
+
const headerText = getSelectMfaTypeByChallengeName(challengeName);
|
|
20
|
+
const primaryButtonText = isPending ? getConfirmingText() : getConfirmText();
|
|
21
|
+
const secondaryButtonText = getBackToSignInText();
|
|
22
|
+
const buttons = (0, react_1.useMemo)(() => ({
|
|
23
|
+
primary: {
|
|
24
|
+
children: primaryButtonText,
|
|
25
|
+
disabled,
|
|
26
|
+
onPress: handleFormSubmit,
|
|
27
|
+
},
|
|
28
|
+
links: [{ children: secondaryButtonText, onPress: toSignIn }],
|
|
29
|
+
}), [
|
|
30
|
+
disabled,
|
|
31
|
+
handleFormSubmit,
|
|
32
|
+
primaryButtonText,
|
|
33
|
+
secondaryButtonText,
|
|
34
|
+
toSignIn,
|
|
35
|
+
]);
|
|
36
|
+
return (<common_1.DefaultContent {...rest} buttons={buttons} headerText={headerText} fields={fieldsWithHandlers} isPending={isPending} validationErrors={fieldValidationErrors}/>);
|
|
37
|
+
};
|
|
38
|
+
SelectMfaType.Footer = common_1.DefaultFooter;
|
|
39
|
+
SelectMfaType.FormFields = common_1.DefaultSelectMfaTypeFormFields;
|
|
40
|
+
SelectMfaType.Header = common_1.DefaultHeader;
|
|
41
|
+
SelectMfaType.displayName = COMPONENT_NAME;
|
|
42
|
+
exports.default = SelectMfaType;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SelectMfaType = void 0;
|
|
7
|
+
var SelectMfaType_1 = require("./SelectMfaType");
|
|
8
|
+
Object.defineProperty(exports, "SelectMfaType", { enumerable: true, get: function () { return __importDefault(SelectMfaType_1).default; } });
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
+
const ui_1 = require("@aws-amplify/ui");
|
|
6
|
+
const common_1 = require("../../common");
|
|
7
|
+
const hooks_1 = require("../../hooks");
|
|
8
|
+
const COMPONENT_NAME = 'SetupEmail';
|
|
9
|
+
const { getBackToSignInText, getConfirmText, getConfirmingText, getSetupEmailText, } = ui_1.authenticatorTextUtil;
|
|
10
|
+
const SetupEmail = ({ fields, handleBlur, handleChange, handleSubmit, isPending, toSignIn, validationErrors, ...rest }) => {
|
|
11
|
+
const { disableFormSubmit: disabled, fields: fieldsWithHandlers, fieldValidationErrors, handleFormSubmit, } = (0, hooks_1.useFieldValues)({
|
|
12
|
+
componentName: COMPONENT_NAME,
|
|
13
|
+
fields,
|
|
14
|
+
handleBlur,
|
|
15
|
+
handleChange,
|
|
16
|
+
handleSubmit,
|
|
17
|
+
validationErrors,
|
|
18
|
+
});
|
|
19
|
+
const headerText = getSetupEmailText();
|
|
20
|
+
const primaryButtonText = isPending ? getConfirmingText() : getConfirmText();
|
|
21
|
+
const secondaryButtonText = getBackToSignInText();
|
|
22
|
+
const buttons = (0, react_1.useMemo)(() => ({
|
|
23
|
+
primary: {
|
|
24
|
+
children: primaryButtonText,
|
|
25
|
+
disabled,
|
|
26
|
+
onPress: handleFormSubmit,
|
|
27
|
+
},
|
|
28
|
+
links: [{ children: secondaryButtonText, onPress: toSignIn }],
|
|
29
|
+
}), [
|
|
30
|
+
disabled,
|
|
31
|
+
handleFormSubmit,
|
|
32
|
+
primaryButtonText,
|
|
33
|
+
secondaryButtonText,
|
|
34
|
+
toSignIn,
|
|
35
|
+
]);
|
|
36
|
+
return (<common_1.DefaultContent {...rest} buttons={buttons} headerText={headerText} fields={fieldsWithHandlers} isPending={isPending} validationErrors={fieldValidationErrors}/>);
|
|
37
|
+
};
|
|
38
|
+
SetupEmail.Footer = common_1.DefaultFooter;
|
|
39
|
+
SetupEmail.FormFields = common_1.DefaultTextFormFields;
|
|
40
|
+
SetupEmail.Header = common_1.DefaultHeader;
|
|
41
|
+
SetupEmail.displayName = COMPONENT_NAME;
|
|
42
|
+
exports.default = SetupEmail;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SetupEmail = void 0;
|
|
7
|
+
var SetupEmail_1 = require("./SetupEmail");
|
|
8
|
+
Object.defineProperty(exports, "SetupEmail", { enumerable: true, get: function () { return __importDefault(SetupEmail_1).default; } });
|
|
@@ -27,7 +27,7 @@ const VerifyUser = ({ fields, handleBlur, handleChange, handleSubmit, skipVerifi
|
|
|
27
27
|
return (<common_1.DefaultContent {...rest} body={bodyText} buttons={buttons} fields={fieldsWithHandlers} headerText={headerText} validationErrors={fieldValidationErrors}/>);
|
|
28
28
|
};
|
|
29
29
|
VerifyUser.Footer = common_1.DefaultFooter;
|
|
30
|
-
VerifyUser.FormFields = common_1.
|
|
30
|
+
VerifyUser.FormFields = common_1.DefaultVerifyUserFormFields;
|
|
31
31
|
VerifyUser.Header = common_1.DefaultHeader;
|
|
32
32
|
VerifyUser.displayName = COMPONENT_NAME;
|
|
33
33
|
exports.default = VerifyUser;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VerifyUser = exports.SignUp = exports.SignIn = exports.SetupTotp = exports.ForgotPassword = exports.ForceNewPassword = exports.ConfirmVerifyUser = exports.ConfirmSignUp = exports.ConfirmSignIn = exports.ConfirmResetPassword = void 0;
|
|
3
|
+
exports.SetupEmail = exports.SelectMfaType = exports.VerifyUser = exports.SignUp = exports.SignIn = exports.SetupTotp = exports.ForgotPassword = exports.ForceNewPassword = exports.ConfirmVerifyUser = exports.ConfirmSignUp = exports.ConfirmSignIn = exports.ConfirmResetPassword = void 0;
|
|
4
4
|
var ConfirmResetPassword_1 = require("./ConfirmResetPassword");
|
|
5
5
|
Object.defineProperty(exports, "ConfirmResetPassword", { enumerable: true, get: function () { return ConfirmResetPassword_1.ConfirmResetPassword; } });
|
|
6
6
|
var ConfirmSignIn_1 = require("./ConfirmSignIn");
|
|
@@ -21,3 +21,7 @@ var SignUp_1 = require("./SignUp");
|
|
|
21
21
|
Object.defineProperty(exports, "SignUp", { enumerable: true, get: function () { return SignUp_1.SignUp; } });
|
|
22
22
|
var VerifyUser_1 = require("./VerifyUser");
|
|
23
23
|
Object.defineProperty(exports, "VerifyUser", { enumerable: true, get: function () { return VerifyUser_1.VerifyUser; } });
|
|
24
|
+
var SelectMfaType_1 = require("./SelectMfaType");
|
|
25
|
+
Object.defineProperty(exports, "SelectMfaType", { enumerable: true, get: function () { return SelectMfaType_1.SelectMfaType; } });
|
|
26
|
+
var SetupEmail_1 = require("./SetupEmail");
|
|
27
|
+
Object.defineProperty(exports, "SetupEmail", { enumerable: true, get: function () { return SetupEmail_1.SetupEmail; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
|
+
const RadioGroup_1 = require("../../../primitives/RadioGroup");
|
|
6
|
+
const Radio_1 = require("../../../primitives/Radio");
|
|
7
|
+
const DefaultSelectMfaTypeFormFields = ({ fields = [], fieldContainerStyle, fieldLabelStyle, isPending, style, }) => {
|
|
8
|
+
// set initial value for radio field based on selected bool
|
|
9
|
+
const initialValue = fields.find((field) => !!field.selected)?.value;
|
|
10
|
+
return (<RadioGroup_1.RadioGroup disabled={isPending} style={style} initialValue={initialValue}>
|
|
11
|
+
{fields.map(({ value, label, ...props }) => (<Radio_1.Radio {...props} key={value} value={value} label={label} labelStyle={fieldLabelStyle} style={fieldContainerStyle}/>))}
|
|
12
|
+
</RadioGroup_1.RadioGroup>);
|
|
13
|
+
};
|
|
14
|
+
DefaultSelectMfaTypeFormFields.displayName = 'FormFields';
|
|
15
|
+
exports.default = DefaultSelectMfaTypeFormFields;
|
|
@@ -8,9 +8,11 @@ const attributeMap = {
|
|
|
8
8
|
email: 'Email',
|
|
9
9
|
phone_number: 'Phone Number',
|
|
10
10
|
};
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const DefaultVerifyUserFormFields = ({ fields = [], fieldContainerStyle, fieldLabelStyle, isPending, style, }) => {
|
|
12
|
+
// set initial value for radio field based on selected bool
|
|
13
|
+
const initialValue = fields.find((field) => !!field.selected)?.name;
|
|
14
|
+
return (<primitives_1.RadioGroup disabled={isPending} style={style} initialValue={initialValue}>
|
|
15
|
+
{fields.map(({ name, value, ...props }) => {
|
|
14
16
|
const attributeType = attributeMap[name];
|
|
15
17
|
return (<primitives_1.Radio {...props} key={value}
|
|
16
18
|
// value has to be name, because Auth is only interested in the
|
|
@@ -19,5 +21,5 @@ const DefaultRadioFormFields = ({ fields, fieldContainerStyle, fieldLabelStyle,
|
|
|
19
21
|
})}
|
|
20
22
|
</primitives_1.RadioGroup>);
|
|
21
23
|
};
|
|
22
|
-
|
|
23
|
-
exports.default =
|
|
24
|
+
DefaultVerifyUserFormFields.displayName = 'FormFields';
|
|
25
|
+
exports.default = DefaultVerifyUserFormFields;
|
|
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
var DefaultRadioFormFields_1 = require("./DefaultRadioFormFields");
|
|
8
|
-
Object.defineProperty(exports, "DefaultRadioFormFields", { enumerable: true, get: function () { return __importDefault(DefaultRadioFormFields_1).default; } });
|
|
6
|
+
exports.DefaultSelectMfaTypeFormFields = exports.DefaultVerifyUserFormFields = exports.DefaultTextFormFields = void 0;
|
|
9
7
|
var DefaultTextFormFields_1 = require("./DefaultTextFormFields");
|
|
10
8
|
Object.defineProperty(exports, "DefaultTextFormFields", { enumerable: true, get: function () { return __importDefault(DefaultTextFormFields_1).default; } });
|
|
9
|
+
var DefaultVerifyUserFormFields_1 = require("./DefaultVerifyUserFormFields");
|
|
10
|
+
Object.defineProperty(exports, "DefaultVerifyUserFormFields", { enumerable: true, get: function () { return __importDefault(DefaultVerifyUserFormFields_1).default; } });
|
|
11
|
+
var DefaultSelectMfaTypeFormFields_1 = require("./DefaultSelectMfaTypeFormFields");
|
|
12
|
+
Object.defineProperty(exports, "DefaultSelectMfaTypeFormFields", { enumerable: true, get: function () { return __importDefault(DefaultSelectMfaTypeFormFields_1).default; } });
|
|
@@ -5,29 +5,68 @@ const utils_1 = require("aws-amplify/utils");
|
|
|
5
5
|
const utils_2 = require("./utils");
|
|
6
6
|
const logger = new utils_1.ConsoleLogger('Authenticator');
|
|
7
7
|
function useFieldValues({ componentName, fields = [], handleBlur, handleChange, handleSubmit, validationErrors, }) {
|
|
8
|
-
const [values, setValues] = (0, react_1.useState)({});
|
|
9
8
|
const [touched, setTouched] = (0, react_1.useState)({});
|
|
10
9
|
const [fieldValidationErrors, setFieldValidationErrors] = (0, react_1.useState)({});
|
|
11
|
-
const
|
|
10
|
+
const isVerifyUserRoute = componentName === 'VerifyUser';
|
|
11
|
+
const isSelectMfaTypeRoute = componentName === 'SelectMfaType';
|
|
12
|
+
const isRadioFieldComponent = isVerifyUserRoute || isSelectMfaTypeRoute;
|
|
13
|
+
// initialize values based on route
|
|
14
|
+
// select mfa type screen should auto select first radio option
|
|
15
|
+
const [values, setValues] = (0, react_1.useState)(() => {
|
|
16
|
+
const result = {};
|
|
17
|
+
if (isSelectMfaTypeRoute) {
|
|
18
|
+
const initialValue = fields[0]?.value;
|
|
19
|
+
if (initialValue) {
|
|
20
|
+
result.mfa_type = initialValue;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (isVerifyUserRoute) {
|
|
24
|
+
const initialValue = fields[0]?.name;
|
|
25
|
+
if (initialValue) {
|
|
26
|
+
result.unverifiedAttr = initialValue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
});
|
|
12
31
|
const sanitizedFields = (0, react_1.useMemo)(() => {
|
|
13
32
|
if (!Array.isArray(fields)) {
|
|
14
33
|
logger.warn(`Invalid fields type of ${typeof fields} passed to ${componentName}. fields must be of type array.`);
|
|
15
34
|
return [];
|
|
16
35
|
}
|
|
17
|
-
if (
|
|
18
|
-
return (0, utils_2.
|
|
36
|
+
if (isVerifyUserRoute) {
|
|
37
|
+
return (0, utils_2.getSanitizedVerifyUserFields)(fields);
|
|
38
|
+
}
|
|
39
|
+
if (isSelectMfaTypeRoute) {
|
|
40
|
+
return (0, utils_2.getSanitizedSelectMfaTypeFields)(fields);
|
|
19
41
|
}
|
|
20
42
|
return (0, utils_2.getSanitizedTextFields)(fields, componentName);
|
|
21
|
-
}, [componentName, fields,
|
|
43
|
+
}, [componentName, fields, isVerifyUserRoute, isSelectMfaTypeRoute]);
|
|
22
44
|
const fieldsWithHandlers = sanitizedFields.map((field) => {
|
|
23
45
|
if ((0, utils_2.isRadioFieldOptions)(field)) {
|
|
24
46
|
const onChange = (value) => {
|
|
25
47
|
// call `onChange` passed as radio `field` option
|
|
26
48
|
field.onChange?.(value);
|
|
27
|
-
// set `name` as value of 'unverifiedAttr'
|
|
28
|
-
|
|
49
|
+
// on VerifyUser route, set `name` as value of 'unverifiedAttr'
|
|
50
|
+
// on SelectMfaTYpe route, set `name` as value of 'mfa_type'
|
|
51
|
+
const fieldName = isVerifyUserRoute
|
|
52
|
+
? 'unverifiedAttr'
|
|
53
|
+
: isSelectMfaTypeRoute
|
|
54
|
+
? 'mfa_type'
|
|
55
|
+
: field.name;
|
|
56
|
+
setValues((prev) => ({ ...prev, [fieldName]: value }));
|
|
29
57
|
};
|
|
30
|
-
|
|
58
|
+
const result = {
|
|
59
|
+
...field,
|
|
60
|
+
onChange,
|
|
61
|
+
};
|
|
62
|
+
// bind selected boolean attribute for radio field
|
|
63
|
+
if (isSelectMfaTypeRoute) {
|
|
64
|
+
result.selected = values.mfa_type === field.value;
|
|
65
|
+
}
|
|
66
|
+
if (isVerifyUserRoute) {
|
|
67
|
+
result.selected = values.unverifiedAttr === field.name;
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
31
70
|
}
|
|
32
71
|
const { name, label, labelHidden, ...rest } = field;
|
|
33
72
|
const onBlur = (event) => {
|
|
@@ -63,17 +102,11 @@ function useFieldValues({ componentName, fields = [], handleBlur, handleChange,
|
|
|
63
102
|
value: values[name],
|
|
64
103
|
};
|
|
65
104
|
});
|
|
66
|
-
const disableFormSubmit =
|
|
105
|
+
const disableFormSubmit = isVerifyUserRoute
|
|
67
106
|
? !values.unverifiedAttr
|
|
68
|
-
:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
if (value) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
});
|
|
107
|
+
: isSelectMfaTypeRoute
|
|
108
|
+
? !values.mfa_type
|
|
109
|
+
: fieldsWithHandlers.some(({ required, value }) => required && !value);
|
|
77
110
|
const handleFormSubmit = () => {
|
|
78
111
|
const submitValue = isRadioFieldComponent
|
|
79
112
|
? values
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runFieldValidation = exports.getRouteTypedFields = exports.getTypedFields = exports.getTypedField = exports.getSanitizedTextFields = exports.
|
|
3
|
+
exports.runFieldValidation = exports.getRouteTypedFields = exports.getTypedFields = exports.getTypedField = exports.getSanitizedTextFields = exports.getSanitizedSelectMfaTypeFields = exports.getSanitizedVerifyUserFields = exports.isRadioFieldOptions = void 0;
|
|
4
4
|
const utils_1 = require("aws-amplify/utils");
|
|
5
5
|
const ui_1 = require("@aws-amplify/ui");
|
|
6
6
|
const ui_react_core_1 = require("@aws-amplify/ui-react-core");
|
|
@@ -9,11 +9,11 @@ const logger = new utils_1.ConsoleLogger('Authenticator');
|
|
|
9
9
|
const { getInvalidEmailText, getRequiredFieldText } = ui_1.authenticatorTextUtil;
|
|
10
10
|
const isRadioFieldOptions = (field) => field?.type === 'radio';
|
|
11
11
|
exports.isRadioFieldOptions = isRadioFieldOptions;
|
|
12
|
-
const
|
|
12
|
+
const getSanitizedVerifyUserFields = (fields) => {
|
|
13
13
|
const values = {};
|
|
14
14
|
return fields.filter((field) => {
|
|
15
15
|
if (!(0, exports.isRadioFieldOptions)(field)) {
|
|
16
|
-
logger.warn(
|
|
16
|
+
logger.warn(`VerifyUser component does not support text fields. field with type ${field.type} has been ignored.`);
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
19
|
const { name, value } = field;
|
|
@@ -34,7 +34,28 @@ const getSanitizedRadioFields = (fields, componentName) => {
|
|
|
34
34
|
return true;
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
exports.
|
|
37
|
+
exports.getSanitizedVerifyUserFields = getSanitizedVerifyUserFields;
|
|
38
|
+
const getSanitizedSelectMfaTypeFields = (fields) => {
|
|
39
|
+
const values = {};
|
|
40
|
+
return fields.filter((field) => {
|
|
41
|
+
const { value } = field;
|
|
42
|
+
if (!(0, exports.isRadioFieldOptions)(field)) {
|
|
43
|
+
logger.warn(`SelectMfaType component does not support non-radio fields; field with type "${field.type}" has been ignored.`);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (!value) {
|
|
47
|
+
logger.warn('Each field must have a value; field has been ignored.');
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (values[value]) {
|
|
51
|
+
logger.warn(`Each field value must be unique; field with duplicate value of "${value}" has been ignored.`);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
values[value] = true;
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
exports.getSanitizedSelectMfaTypeFields = getSanitizedSelectMfaTypeFields;
|
|
38
59
|
const getSanitizedTextFields = (fields, componentName) => {
|
|
39
60
|
const names = {};
|
|
40
61
|
return fields.filter((field) => {
|
|
@@ -103,8 +124,11 @@ function getRouteTypedFields({ fields, route, }) {
|
|
|
103
124
|
}
|
|
104
125
|
// `VerifyUser` does not require additional updates to the shape of `fields`
|
|
105
126
|
const isVerifyUserRoute = route === 'verifyUser';
|
|
127
|
+
const isSelectMfaTypeRoute = route === 'selectMfaType';
|
|
106
128
|
const radioFields = fields;
|
|
107
|
-
return isVerifyUserRoute
|
|
129
|
+
return isVerifyUserRoute || isSelectMfaTypeRoute
|
|
130
|
+
? radioFields
|
|
131
|
+
: (0, exports.getTypedFields)(fields);
|
|
108
132
|
}
|
|
109
133
|
exports.getRouteTypedFields = getRouteTypedFields;
|
|
110
134
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RADIO_GROUP_CONTAINER_TEST_ID = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
6
|
const react_native_1 = require("react-native");
|
|
@@ -8,6 +9,7 @@ const theme_1 = require("../../theme");
|
|
|
8
9
|
const Label_1 = require("../Label");
|
|
9
10
|
const utils_1 = require("../Label/utils");
|
|
10
11
|
const styles_1 = require("./styles");
|
|
12
|
+
exports.RADIO_GROUP_CONTAINER_TEST_ID = 'amplify__radio-group__container';
|
|
11
13
|
function RadioGroup({ accessible = true, accessibilityRole = 'radiogroup', children, direction = 'vertical', disabled, initialValue, label, labelPosition = 'top', labelStyle, onChange, onValueChange, size, style, ...rest }) {
|
|
12
14
|
const theme = (0, theme_1.useTheme)();
|
|
13
15
|
const themedStyle = (0, styles_1.getThemedStyles)(theme);
|
|
@@ -29,7 +31,7 @@ function RadioGroup({ accessible = true, accessibilityRole = 'radiogroup', child
|
|
|
29
31
|
setValue(nextValue);
|
|
30
32
|
onChange?.(nextValue);
|
|
31
33
|
}, [onChange]);
|
|
32
|
-
return (<react_native_1.View {...rest} style={[themedStyle.container, containerStyle, style]}>
|
|
34
|
+
return (<react_native_1.View {...rest} style={[themedStyle.container, containerStyle, style]} testID={exports.RADIO_GROUP_CONTAINER_TEST_ID}>
|
|
33
35
|
<react_native_1.View accessible={accessible} accessibilityRole={accessibilityRole} style={childContainerStyle}>
|
|
34
36
|
{react_1.Children.map(children, (child) => {
|
|
35
37
|
if ((0, react_1.isValidElement)(child)) {
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react-native",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"react-native-safe-area-context": "^5.2.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@aws-amplify/ui": "6.
|
|
34
|
-
"@aws-amplify/ui-react-core": "3.
|
|
35
|
-
"@aws-amplify/ui-react-core-notifications": "2.2.
|
|
33
|
+
"@aws-amplify/ui": "6.10.0",
|
|
34
|
+
"@aws-amplify/ui-react-core": "3.4.0",
|
|
35
|
+
"@aws-amplify/ui-react-core-notifications": "2.2.6"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"aws-amplify": "^6.9.0",
|
|
@@ -28,6 +28,8 @@ import {
|
|
|
28
28
|
SignIn,
|
|
29
29
|
SignUp,
|
|
30
30
|
VerifyUser,
|
|
31
|
+
SetupEmail,
|
|
32
|
+
SelectMfaType,
|
|
31
33
|
} from './Defaults';
|
|
32
34
|
|
|
33
35
|
const DEFAULTS = {
|
|
@@ -41,6 +43,8 @@ const DEFAULTS = {
|
|
|
41
43
|
SignIn,
|
|
42
44
|
SignUp,
|
|
43
45
|
VerifyUser,
|
|
46
|
+
SetupEmail,
|
|
47
|
+
SelectMfaType,
|
|
44
48
|
};
|
|
45
49
|
|
|
46
50
|
const routePropSelector = ({
|
|
@@ -118,5 +122,7 @@ Authenticator.SetupTotp = SetupTotp;
|
|
|
118
122
|
Authenticator.SignIn = SignIn;
|
|
119
123
|
Authenticator.SignUp = SignUp;
|
|
120
124
|
Authenticator.VerifyUser = VerifyUser;
|
|
125
|
+
Authenticator.SetupEmail = SetupEmail;
|
|
126
|
+
Authenticator.SelectMfaType = SelectMfaType;
|
|
121
127
|
|
|
122
128
|
export default Authenticator;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { authenticatorTextUtil } from '@aws-amplify/ui';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
DefaultContent,
|
|
6
|
+
DefaultFooter,
|
|
7
|
+
DefaultHeader,
|
|
8
|
+
DefaultSelectMfaTypeFormFields,
|
|
9
|
+
} from '../../common';
|
|
10
|
+
import { useFieldValues } from '../../hooks';
|
|
11
|
+
|
|
12
|
+
import { DefaultSelectMfaTypeProps } from '../types';
|
|
13
|
+
|
|
14
|
+
const COMPONENT_NAME = 'SelectMfaType';
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
getSelectMfaTypeByChallengeName,
|
|
18
|
+
getBackToSignInText,
|
|
19
|
+
getConfirmText,
|
|
20
|
+
getConfirmingText,
|
|
21
|
+
} = authenticatorTextUtil;
|
|
22
|
+
|
|
23
|
+
const SelectMfaType = ({
|
|
24
|
+
challengeName,
|
|
25
|
+
fields,
|
|
26
|
+
handleBlur,
|
|
27
|
+
handleChange,
|
|
28
|
+
handleSubmit,
|
|
29
|
+
isPending,
|
|
30
|
+
toSignIn,
|
|
31
|
+
validationErrors,
|
|
32
|
+
...rest
|
|
33
|
+
}: DefaultSelectMfaTypeProps): React.JSX.Element => {
|
|
34
|
+
const {
|
|
35
|
+
disableFormSubmit: disabled,
|
|
36
|
+
fields: fieldsWithHandlers,
|
|
37
|
+
fieldValidationErrors,
|
|
38
|
+
handleFormSubmit,
|
|
39
|
+
} = useFieldValues({
|
|
40
|
+
componentName: COMPONENT_NAME,
|
|
41
|
+
fields,
|
|
42
|
+
handleBlur,
|
|
43
|
+
handleChange,
|
|
44
|
+
handleSubmit,
|
|
45
|
+
validationErrors,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const headerText = getSelectMfaTypeByChallengeName(challengeName);
|
|
49
|
+
const primaryButtonText = isPending ? getConfirmingText() : getConfirmText();
|
|
50
|
+
const secondaryButtonText = getBackToSignInText();
|
|
51
|
+
|
|
52
|
+
const buttons = useMemo(
|
|
53
|
+
() => ({
|
|
54
|
+
primary: {
|
|
55
|
+
children: primaryButtonText,
|
|
56
|
+
disabled,
|
|
57
|
+
onPress: handleFormSubmit,
|
|
58
|
+
},
|
|
59
|
+
links: [{ children: secondaryButtonText, onPress: toSignIn }],
|
|
60
|
+
}),
|
|
61
|
+
[
|
|
62
|
+
disabled,
|
|
63
|
+
handleFormSubmit,
|
|
64
|
+
primaryButtonText,
|
|
65
|
+
secondaryButtonText,
|
|
66
|
+
toSignIn,
|
|
67
|
+
]
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<DefaultContent
|
|
72
|
+
{...rest}
|
|
73
|
+
buttons={buttons}
|
|
74
|
+
headerText={headerText}
|
|
75
|
+
fields={fieldsWithHandlers}
|
|
76
|
+
isPending={isPending}
|
|
77
|
+
validationErrors={fieldValidationErrors}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
SelectMfaType.Footer = DefaultFooter;
|
|
83
|
+
SelectMfaType.FormFields = DefaultSelectMfaTypeFormFields;
|
|
84
|
+
SelectMfaType.Header = DefaultHeader;
|
|
85
|
+
|
|
86
|
+
SelectMfaType.displayName = COMPONENT_NAME;
|
|
87
|
+
export default SelectMfaType;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SelectMfaType } from './SelectMfaType';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { authenticatorTextUtil } from '@aws-amplify/ui';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
DefaultContent,
|
|
6
|
+
DefaultFooter,
|
|
7
|
+
DefaultTextFormFields,
|
|
8
|
+
DefaultHeader,
|
|
9
|
+
} from '../../common';
|
|
10
|
+
import { useFieldValues } from '../../hooks';
|
|
11
|
+
|
|
12
|
+
import { DefaultSetupEmailProps } from '../types';
|
|
13
|
+
|
|
14
|
+
const COMPONENT_NAME = 'SetupEmail';
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
getBackToSignInText,
|
|
18
|
+
getConfirmText,
|
|
19
|
+
getConfirmingText,
|
|
20
|
+
getSetupEmailText,
|
|
21
|
+
} = authenticatorTextUtil;
|
|
22
|
+
|
|
23
|
+
const SetupEmail = ({
|
|
24
|
+
fields,
|
|
25
|
+
handleBlur,
|
|
26
|
+
handleChange,
|
|
27
|
+
handleSubmit,
|
|
28
|
+
isPending,
|
|
29
|
+
toSignIn,
|
|
30
|
+
validationErrors,
|
|
31
|
+
...rest
|
|
32
|
+
}: DefaultSetupEmailProps): React.JSX.Element => {
|
|
33
|
+
const {
|
|
34
|
+
disableFormSubmit: disabled,
|
|
35
|
+
fields: fieldsWithHandlers,
|
|
36
|
+
fieldValidationErrors,
|
|
37
|
+
handleFormSubmit,
|
|
38
|
+
} = useFieldValues({
|
|
39
|
+
componentName: COMPONENT_NAME,
|
|
40
|
+
fields,
|
|
41
|
+
handleBlur,
|
|
42
|
+
handleChange,
|
|
43
|
+
handleSubmit,
|
|
44
|
+
validationErrors,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const headerText = getSetupEmailText();
|
|
48
|
+
const primaryButtonText = isPending ? getConfirmingText() : getConfirmText();
|
|
49
|
+
const secondaryButtonText = getBackToSignInText();
|
|
50
|
+
|
|
51
|
+
const buttons = useMemo(
|
|
52
|
+
() => ({
|
|
53
|
+
primary: {
|
|
54
|
+
children: primaryButtonText,
|
|
55
|
+
disabled,
|
|
56
|
+
onPress: handleFormSubmit,
|
|
57
|
+
},
|
|
58
|
+
links: [{ children: secondaryButtonText, onPress: toSignIn }],
|
|
59
|
+
}),
|
|
60
|
+
[
|
|
61
|
+
disabled,
|
|
62
|
+
handleFormSubmit,
|
|
63
|
+
primaryButtonText,
|
|
64
|
+
secondaryButtonText,
|
|
65
|
+
toSignIn,
|
|
66
|
+
]
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<DefaultContent
|
|
71
|
+
{...rest}
|
|
72
|
+
buttons={buttons}
|
|
73
|
+
headerText={headerText}
|
|
74
|
+
fields={fieldsWithHandlers}
|
|
75
|
+
isPending={isPending}
|
|
76
|
+
validationErrors={fieldValidationErrors}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
SetupEmail.Footer = DefaultFooter;
|
|
82
|
+
SetupEmail.FormFields = DefaultTextFormFields;
|
|
83
|
+
SetupEmail.Header = DefaultHeader;
|
|
84
|
+
|
|
85
|
+
SetupEmail.displayName = COMPONENT_NAME;
|
|
86
|
+
export default SetupEmail;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SetupEmail } from './SetupEmail';
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
DefaultContent,
|
|
6
6
|
DefaultFooter,
|
|
7
7
|
DefaultHeader,
|
|
8
|
-
|
|
8
|
+
DefaultVerifyUserFormFields,
|
|
9
9
|
} from '../../common';
|
|
10
10
|
import { useFieldValues } from '../../hooks';
|
|
11
11
|
import { DefaultVerifyUserProps } from '../types';
|
|
@@ -68,7 +68,7 @@ const VerifyUser = ({
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
VerifyUser.Footer = DefaultFooter;
|
|
71
|
-
VerifyUser.FormFields =
|
|
71
|
+
VerifyUser.FormFields = DefaultVerifyUserFormFields;
|
|
72
72
|
VerifyUser.Header = DefaultHeader;
|
|
73
73
|
|
|
74
74
|
VerifyUser.displayName = COMPONENT_NAME;
|
|
@@ -8,4 +8,21 @@ export { SetupTotp } from './SetupTotp';
|
|
|
8
8
|
export { SignIn } from './SignIn';
|
|
9
9
|
export { SignUp } from './SignUp';
|
|
10
10
|
export { VerifyUser } from './VerifyUser';
|
|
11
|
-
export {
|
|
11
|
+
export { SelectMfaType } from './SelectMfaType';
|
|
12
|
+
export { SetupEmail } from './SetupEmail';
|
|
13
|
+
export {
|
|
14
|
+
Components,
|
|
15
|
+
DefaultComponents,
|
|
16
|
+
ConfirmResetPasswordProps,
|
|
17
|
+
ConfirmSignInProps,
|
|
18
|
+
ConfirmSignUpProps,
|
|
19
|
+
ConfirmVerifyUserProps,
|
|
20
|
+
ForceNewPasswordProps,
|
|
21
|
+
ForgotPasswordProps,
|
|
22
|
+
SelectMfaTypeProps,
|
|
23
|
+
SetupEmailProps,
|
|
24
|
+
SetupTotpProps,
|
|
25
|
+
SignInProps,
|
|
26
|
+
SignUpProps,
|
|
27
|
+
VerifyUserProps,
|
|
28
|
+
} from './types';
|