UNPKG

@rocket.chat/onboarding-ui

Version:

Set of components and functions for the onboarding experience on Rocket.Chat

25 lines 3.7 kB
"use strict"; 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 LoginForm_styles_1 = require("./LoginForm.styles"); const LoginForm = ({ onSubmit, initialValues, isPasswordLess = false, onChangeForm, onResetPassword, formError, }) => { const { t } = (0, react_i18next_1.useTranslation)(); const { register, handleSubmit, formState: { errors, isValidating, isSubmitting, isDirty }, } = (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.jsxs)(layout_1.Form.Header, { children: [(0, jsx_runtime_1.jsx)(layout_1.Form.Title, { children: t('form.loginForm.content.logIn') }), (0, jsx_runtime_1.jsx)(layout_1.Form.Subtitle, { children: !isPasswordLess ? t('form.loginForm.content.default') : t('form.loginForm.content.passwordLess') })] }), (0, jsx_runtime_1.jsx)(layout_1.Form.Container, { children: (0, jsx_runtime_1.jsxs)(fuselage_1.FieldGroup, { children: [(0, jsx_runtime_1.jsxs)(fuselage_1.Field, { children: [(0, jsx_runtime_1.jsx)(fuselage_1.FieldLabel, { children: t('form.loginForm.fields.email.label') }), (0, jsx_runtime_1.jsx)(fuselage_1.FieldRow, { children: (0, jsx_runtime_1.jsx)(fuselage_1.EmailInput, { ...register('email', { required: t('component.form.requiredField'), }), placeholder: t('form.loginForm.fields.email.placeholder') }) }), errors.email && (0, jsx_runtime_1.jsx)(fuselage_1.FieldError, { children: errors.email.message })] }), !isPasswordLess && ((0, jsx_runtime_1.jsxs)(fuselage_1.Field, { children: [(0, jsx_runtime_1.jsx)(fuselage_1.FieldLabel, { children: t('form.loginForm.fields.password.label') }), (0, jsx_runtime_1.jsx)(fuselage_1.FieldRow, { children: (0, jsx_runtime_1.jsx)(fuselage_1.PasswordInput, { ...register('password', { required: true }), placeholder: t('form.loginForm.fields.password.placeholder') }) }), (formError || errors.password) && ((0, jsx_runtime_1.jsx)(fuselage_1.FieldError, { children: t('form.loginForm.fields.password.error') }))] }))] }) }), (0, jsx_runtime_1.jsxs)(layout_1.Form.Footer, { children: [(0, jsx_runtime_1.jsxs)(LoginForm_styles_1.LoginActionsWrapper, { children: [(0, jsx_runtime_1.jsx)(fuselage_1.Button, { type: 'submit', loading: isValidating || isSubmitting, disabled: !isDirty, primary: true, children: isPasswordLess ? t('form.loginForm.sendLoginLink') : t('form.loginForm.button.text') }), !isPasswordLess && ((0, jsx_runtime_1.jsx)(layout_1.ActionLink, { fontScale: 'p2', onClick: onChangeForm, children: t('form.loginForm.sendLoginLink') })), isPasswordLess && ((0, jsx_runtime_1.jsx)(layout_1.ActionLink, { fontScale: 'p2', onClick: onChangeForm, children: t('form.loginForm.redirect') }))] }), !isPasswordLess && ((0, jsx_runtime_1.jsx)(fuselage_1.Box, { mbs: 24, fontScale: 'p2', textAlign: 'left', children: (0, jsx_runtime_1.jsxs)(react_i18next_1.Trans, { i18nKey: 'form.loginForm.resetPassword', children: ["Forgot your password?", (0, jsx_runtime_1.jsx)(layout_1.ActionLink, { fontScale: 'p2', onClick: onResetPassword, children: "Reset password" })] }) }))] })] })); }; exports.default = LoginForm; //# sourceMappingURL=LoginForm.js.map