-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathindex.jsx
More file actions
103 lines (98 loc) · 4.02 KB
/
index.jsx
File metadata and controls
103 lines (98 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React, {Fragment} from 'react'
import PropTypes from 'prop-types'
import {FormattedMessage} from 'react-intl'
import {Alert, Button, Stack, Text} from '@salesforce/retail-react-app/app/components/shared/ui'
import {AlertIcon, BrandLogo} from '@salesforce/retail-react-app/app/components/icons'
import StandardLogin from '@salesforce/retail-react-app/app/components/standard-login'
import PasswordlessLogin from '@salesforce/retail-react-app/app/components/passwordless-login'
import {noop} from '@salesforce/retail-react-app/app/utils/utils'
const LoginForm = ({
submitForm,
handleForgotPasswordClick,
handlePasswordlessLoginClick,
clickCreateAccount = noop,
form,
isPasswordlessEnabled = false,
isSocialEnabled = false,
idps = [],
setLoginType
}) => {
return (
<Fragment>
<Stack justify="center" align="center" spacing={8} marginBottom={8}>
<BrandLogo width="60px" height="auto" />
<Text align="center" fontSize="xl" fontWeight="semibold">
<FormattedMessage
defaultMessage="Welcome Back"
id="login_form.message.welcome_back"
/>
</Text>
</Stack>
<form
id="login-form"
onSubmit={form.handleSubmit(submitForm)}
data-testid="sf-auth-modal-form"
>
{form.formState.errors?.global && (
<Alert status="error" marginBottom={8}>
<AlertIcon color="red.500" boxSize={4} />
<Text fontSize="sm" ml={3}>
{form.formState.errors.global.message}
</Text>
</Alert>
)}
<Stack spacing={6}>
{isPasswordlessEnabled ? (
<PasswordlessLogin
form={form}
handleForgotPasswordClick={handleForgotPasswordClick}
handlePasswordlessLoginClick={handlePasswordlessLoginClick}
isSocialEnabled={isSocialEnabled}
idps={idps}
setLoginType={setLoginType}
/>
) : (
<StandardLogin
form={form}
handleForgotPasswordClick={handleForgotPasswordClick}
isSocialEnabled={isSocialEnabled}
idps={idps}
/>
)}
<Stack direction="row" spacing={1} justify="center">
<Text fontSize="sm">
<FormattedMessage
defaultMessage="Don't have an account?"
id="login_form.message.dont_have_account"
/>
</Text>
<Button variant="link" size="sm" onClick={clickCreateAccount}>
<FormattedMessage
defaultMessage="Create account"
id="login_form.action.create_account"
/>
</Button>
</Stack>
</Stack>
</form>
</Fragment>
)
}
LoginForm.propTypes = {
submitForm: PropTypes.func,
handleForgotPasswordClick: PropTypes.func,
clickCreateAccount: PropTypes.func,
handlePasswordlessLoginClick: PropTypes.func,
form: PropTypes.object,
isPasswordlessEnabled: PropTypes.bool,
isSocialEnabled: PropTypes.bool,
idps: PropTypes.arrayOf(PropTypes.string),
setLoginType: PropTypes.func
}
export default LoginForm