-
Notifications
You must be signed in to change notification settings - Fork 214
@W-17271709 Passwordless Login in Checkout #2178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 78 commits
7f8e46f
1dd7f93
4b5a766
e4523d3
b8383f9
b3b1aef
59b4eb2
3a2bc7f
60b22fe
2fc643d
e667f24
5bfa864
6da68a3
4cb119e
7d77678
c4f76a2
f069a4d
6d66a18
3457660
c9cb595
fe5aecb
a18210d
2d1df55
acf5410
f5f7816
c459a5c
6e9d4ab
9e02121
2094575
e30c985
fea3716
bfc543b
06377fd
65932e2
f768507
6d578f0
03e0b08
b9408ed
5dd3218
9cba398
93ffca3
8a6a779
6c5beb2
03047f8
d90eaa4
2c9565e
1b90e44
984a36c
9fa1fbd
8042db8
12feb9e
83656b9
6c33000
073154e
0fbb136
e4413ca
00db78f
2a56b20
c10a9fa
7b46eb8
8f78ea8
b1f717a
4916285
322dea2
efe0d1b
a3d7117
34c7177
738aa9f
2e2994d
a9ac1ca
5119614
669568c
7b5e450
b9b51d8
af4ceb2
8dfbd13
5e6141d
692f0e9
c536635
b7cfad0
3857c96
60726cc
865765c
480a5f3
37f19c0
dd8f3e9
4917ef3
2531c5c
05eabf9
56b3de5
79116bb
812b92b
04e21fa
5f0c2da
ee5e599
b13835d
ba3d8f4
ca22bef
56b3b1a
8316458
76cb121
d0344b6
95bea67
c555280
e9e5dcf
5107f31
7960548
30ea366
7f2c142
0c5cbfd
306bf87
fabda07
b659bfc
f9abaa7
9d7e556
dde5352
e0cb754
c83457a
f6e3623
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,20 +32,25 @@ import { | |
| } from '@salesforce/retail-react-app/app/components/toggle-card' | ||
| import Field from '@salesforce/retail-react-app/app/components/field' | ||
| import LoginState from '@salesforce/retail-react-app/app/pages/checkout/partials/login-state' | ||
| import {AuthModal, useAuthModal} from '@salesforce/retail-react-app/app/hooks/use-auth-modal' | ||
| import { | ||
| AuthModal, | ||
| EMAIL_VIEW, | ||
| PASSWORD_VIEW, | ||
| useAuthModal | ||
| } from '@salesforce/retail-react-app/app/hooks/use-auth-modal' | ||
| import useNavigation from '@salesforce/retail-react-app/app/hooks/use-navigation' | ||
| import {useCurrentCustomer} from '@salesforce/retail-react-app/app/hooks/use-current-customer' | ||
| import {useCurrentBasket} from '@salesforce/retail-react-app/app/hooks/use-current-basket' | ||
| import {AuthHelpers, useAuthHelper, useShopperBasketsMutation} from '@salesforce/commerce-sdk-react' | ||
|
|
||
| const ContactInfo = ({isSocialEnabled = false, isPasswordlessEnabled = false, idps = []}) => { | ||
| const {formatMessage} = useIntl() | ||
| const authModal = useAuthModal('password') | ||
| const navigate = useNavigation() | ||
| const {data: customer} = useCurrentCustomer() | ||
| const {data: basket} = useCurrentBasket() | ||
| const login = useAuthHelper(AuthHelpers.LoginRegisteredUserB2C) | ||
| const logout = useAuthHelper(AuthHelpers.Logout) | ||
| const authorizePasswordlessLogin = useAuthHelper(AuthHelpers.AuthorizePasswordless) | ||
| const updateCustomerForBasket = useShopperBasketsMutation('updateCustomerForBasket') | ||
| const mergeBasket = useShopperBasketsMutation('mergeBasket') | ||
|
|
||
|
|
@@ -62,9 +67,20 @@ const ContactInfo = ({isSocialEnabled = false, isPasswordlessEnabled = false, id | |
| const [showPasswordField, setShowPasswordField] = useState(false) | ||
| const [signOutConfirmDialogIsOpen, setSignOutConfirmDialogIsOpen] = useState(false) | ||
|
|
||
| const [authModalView, setAuthModalView] = useState(PASSWORD_VIEW) | ||
| const authModal = useAuthModal(authModalView) | ||
| const [isPasswordlessLoginClicked, setIsPasswordlessLoginClicked] = useState(false) | ||
|
|
||
| const submitForm = async (data) => { | ||
| setError(null) | ||
| try { | ||
| if (isPasswordlessLoginClicked) { | ||
|
||
| await authorizePasswordlessLogin.mutateAsync({userid: data.email}) | ||
| setAuthModalView(EMAIL_VIEW) | ||
|
||
| authModal.onOpen() | ||
| setIsPasswordlessLoginClicked(false) | ||
| return | ||
| } | ||
| if (!data.password) { | ||
| await updateCustomerForBasket.mutateAsync({ | ||
| parameters: {basketId: basket.basketId}, | ||
|
|
@@ -108,6 +124,7 @@ const ContactInfo = ({isSocialEnabled = false, isPasswordlessEnabled = false, id | |
| } | ||
|
|
||
| const onForgotPasswordClick = () => { | ||
| setAuthModalView(PASSWORD_VIEW) | ||
| authModal.onOpen() | ||
| } | ||
|
|
||
|
|
@@ -117,6 +134,10 @@ const ContactInfo = ({isSocialEnabled = false, isPasswordlessEnabled = false, id | |
| } | ||
| }, [showPasswordField]) | ||
|
|
||
| const onPasswordlessLoginClick = async () => { | ||
| setIsPasswordlessLoginClicked(true) | ||
| } | ||
|
|
||
| return ( | ||
| <ToggleCard | ||
| id="step-0" | ||
|
|
@@ -198,12 +219,13 @@ const ContactInfo = ({isSocialEnabled = false, isPasswordlessEnabled = false, id | |
| idps={idps} | ||
| showPasswordField={showPasswordField} | ||
| togglePasswordField={togglePasswordField} | ||
| handlePasswordlessLoginClick={onPasswordlessLoginClick} | ||
| /> | ||
| </Stack> | ||
| </Stack> | ||
| </form> | ||
| </Container> | ||
| <AuthModal {...authModal} /> | ||
| <AuthModal {...authModal} initialEmail={form.getValues().email} /> | ||
| </ToggleCardEdit> | ||
| <ToggleCardSummary> | ||
| <Text>{basket?.customerInfo?.email || customer?.email}</Text> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice I had this in my PR too!