-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathlogin-state.jsx
More file actions
116 lines (110 loc) · 4.03 KB
/
login-state.jsx
File metadata and controls
116 lines (110 loc) · 4.03 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
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright (c) 2025, 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, {useState} from 'react'
import PropTypes from 'prop-types'
import {Button, Divider, Text} from '@salesforce/retail-react-app/app/components/shared/ui'
import {FormattedMessage} from 'react-intl'
import SocialLogin from '@salesforce/retail-react-app/app/components/social-login'
const LoginState = ({
form,
handlePasswordlessLoginClick,
isSocialEnabled,
isPasswordlessEnabled,
idps,
showPasswordField,
togglePasswordField
}) => {
const [showLoginButtons, setShowLoginButtons] = useState(true)
if (isSocialEnabled || isPasswordlessEnabled) {
return showLoginButtons ? (
<>
<Divider />
<Text align="center" fontSize="sm" marginTop={2} marginBottom={2}>
<FormattedMessage
defaultMessage="Or Login With"
id="contact_info.message.or_login_with"
/>
</Text>
{/* Passwordless Login */}
{isPasswordlessEnabled && (
<Button
variant="outline"
borderColor="gray.500"
type="button"
onClick={() => {
handlePasswordlessLoginClick()
}}
isLoading={form.formState.isSubmitting}
>
<FormattedMessage
defaultMessage="Secure Link"
id="contact_info.button.secure_link"
/>
</Button>
)}
{/* Standard Password Login */}
{!showPasswordField && (
<Button
variant="outline"
borderColor="gray.500"
onClick={() => {
togglePasswordField()
setShowLoginButtons(!showLoginButtons)
}}
>
<FormattedMessage
defaultMessage="Password"
id="contact_info.button.password"
/>
</Button>
)}
{/* Social Login */}
{isSocialEnabled && idps && <SocialLogin form={form} idps={idps} />}
</>
) : (
<Button
variant="outline"
borderColor="gray.500"
onClick={() => {
togglePasswordField()
setShowLoginButtons(!showLoginButtons)
}}
>
<FormattedMessage
defaultMessage="Back to Sign In Options"
id="contact_info.button.back_to_sign_in_options"
/>
</Button>
)
} else {
return (
<Button variant="outline" borderColor="gray.500" onClick={togglePasswordField}>
{!showPasswordField ? (
<FormattedMessage
defaultMessage="Already have an account? Log in"
id="contact_info.button.already_have_account"
/>
) : (
<FormattedMessage
defaultMessage="Checkout as Guest"
id="contact_info.button.checkout_as_guest"
/>
)}
</Button>
)
}
}
LoginState.propTypes = {
form: PropTypes.object,
handlePasswordlessLoginClick: PropTypes.func,
isSocialEnabled: PropTypes.bool,
isPasswordlessEnabled: PropTypes.bool,
idps: PropTypes.arrayOf(PropTypes.string),
showPasswordField: PropTypes.bool,
togglePasswordField: PropTypes.func
}
export default LoginState