@rocket.chat/onboarding-ui
Version:
Set of components and functions for the onboarding experience on Rocket.Chat
25 lines • 2.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const fuselage_1 = require("@rocket.chat/fuselage");
const layout_1 = require("@rocket.chat/layout");
const react_hook_form_1 = require("react-hook-form");
const react_i18next_1 = require("react-i18next");
const TotpForm_styles_1 = require("./TotpForm.styles");
const TotpForm = ({ onSubmit, initialValues, isBackupCode = false, onChangeTotpForm, }) => {
const { t } = (0, react_i18next_1.useTranslation)();
const { register, handleSubmit, formState: { errors, isValidating, isSubmitting }, } = (0, react_hook_form_1.useForm)({
defaultValues: {
...initialValues,
},
});
return ((0, jsx_runtime_1.jsxs)(layout_1.Form, { onSubmit: handleSubmit(onSubmit), children: [(0, jsx_runtime_1.jsx)(layout_1.Form.Container, { children: (0, jsx_runtime_1.jsx)(fuselage_1.FieldGroup, { children: (0, jsx_runtime_1.jsxs)(fuselage_1.Field, { children: [isBackupCode ? ((0, jsx_runtime_1.jsx)(fuselage_1.FieldLabel, { children: t('form.totpForm.fields.backupCode.label') })) : ((0, jsx_runtime_1.jsx)(fuselage_1.FieldLabel, { children: t('form.totpForm.fields.totpCode.label') })), (0, jsx_runtime_1.jsx)(fuselage_1.FieldRow, { children: isBackupCode ? ((0, jsx_runtime_1.jsx)(fuselage_1.TextInput, { ...register('backupCode', {
required: t('component.form.requiredField'),
}), placeholder: t('form.totpForm.fields.backupCode.placeholder') })) : ((0, jsx_runtime_1.jsx)(fuselage_1.NumberInput, { ...register('totpCode', {
required: t('component.form.requiredField'),
}), placeholder: t('form.totpForm.fields.totpCode.placeholder') })) }), errors.backupCode && ((0, jsx_runtime_1.jsx)(fuselage_1.FieldError, { children: errors.backupCode.message })), errors.totpCode && ((0, jsx_runtime_1.jsx)(fuselage_1.FieldError, { children: errors.totpCode.message }))] }) }) }), (0, jsx_runtime_1.jsx)(layout_1.Form.Footer, { children: (0, jsx_runtime_1.jsxs)(TotpForm_styles_1.TotpActionsWrapper, { children: [(0, jsx_runtime_1.jsx)(fuselage_1.Button, { type: 'submit', loading: isValidating || isSubmitting, primary: true, children: t('form.totpForm.button.text') }), (0, jsx_runtime_1.jsx)(layout_1.ActionLink, { fontScale: 'p2', onClick: onChangeTotpForm, children: isBackupCode
? t('form.totpForm.buttonTotpCode.text')
: t('form.totpForm.buttonBackupCode.text') })] }) })] }));
};
exports.default = TotpForm;
//# sourceMappingURL=TotpForm.js.map