-
Notifications
You must be signed in to change notification settings - Fork 212
@W-20448811 Shopper can manually enter OTP in login flows #3554
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 102 commits
7877887
22b6a36
c646e44
bd6d1d0
a903665
1e7e5fd
b707b09
a72864b
0fd5d2c
fdb57a2
f005c92
65dfe27
434ae12
78fd7e2
a0343e9
d9a6b12
823ac62
d56b87a
d34ec56
11be87e
4d1a5aa
355bc0d
d9ed864
229221c
f032e1c
e73c04c
cd05b1f
96f1b89
77d1147
07802f3
c0aedcb
f773ee4
3d27d0b
e49c9be
3cfece1
5c8c6ce
c02836d
8fd1ab2
81973db
128ccd5
a5deb6c
3d79932
892ef8c
80c1c80
0e79176
a0d8325
35a9a4d
d6fe32c
b9cb29d
076b1ac
b0ca814
3c05026
36e1b20
3e9e385
b7515c4
abff98d
c292a78
fe0a623
5f31e30
bc6f621
9fa4455
411fc67
dbb914e
9c618de
753f306
c766b59
f4852df
7b6ee61
57d8961
6f45d2b
32106db
4f04c56
e8ffba8
c672d31
8a25361
aff72eb
b73115a
44b2347
7ed0da9
e6b9f3d
2720a5c
25e4f4f
34507b7
23a40e4
77551f2
3c2123a
0f6b842
88419a6
bef76be
60d3614
6649505
5144503
2a74e96
e3c6e53
93c68c5
482cd49
babac43
ebdac22
b542c8d
9cec46e
88643c6
cd0d3d1
644928d
c3752d2
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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import {useUsid, useCustomerType, useDNT} from '@salesforce/commerce-sdk-react' | |
| import {useCurrentCustomer} from '@salesforce/retail-react-app/app/hooks/use-current-customer' | ||
| import {useOtpInputs} from '@salesforce/retail-react-app/app/hooks/use-otp-inputs' | ||
| import {useCountdown} from '@salesforce/retail-react-app/app/hooks/use-countdown' | ||
| import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config' | ||
|
|
||
| const OtpAuth = ({ | ||
| isOpen, | ||
|
|
@@ -35,9 +36,20 @@ const OtpAuth = ({ | |
| handleSendEmailOtp, | ||
| handleOtpVerification, | ||
| onCheckoutAsGuest, | ||
| isGuestRegistration = false | ||
| isGuestRegistration = false, | ||
| hideCheckoutAsGuestButton = false | ||
| }) => { | ||
| const OTP_LENGTH = 8 | ||
| const {tokenLength} = getConfig().app.login | ||
| const parsedLength = Number(tokenLength) | ||
| const isValidOtpLength = parsedLength === 6 || parsedLength === 8 | ||
| const OTP_LENGTH = isValidOtpLength ? parsedLength : 8 | ||
|
|
||
| if (!isValidOtpLength) { | ||
| console.warn( | ||
| `Invalid OTP token length: ${tokenLength}. Expected 6 or 8. Defaulting to ${OTP_LENGTH}.` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better if we enforce this 6 or 8 digit requirement somehow in both the user configuration and also in our own code. Currently, it feels like it's not easily known for other developers that there's this requirement. Perhaps we can use constants or enums to restrict them to either 6 or 8. And add some validations somewhere to make it loud and clear of this requirement.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vmarta Makes sense! I've added a validation check to
If they update They'll see a console warn when the OtpAuthModal is opened and the value would default to 8 In the docs, I'll mention setting tokenLength via env vars and not recommend setting it directly via default.js |
||
| ) | ||
| } | ||
|
|
||
| const [isVerifying, setIsVerifying] = useState(false) | ||
| const [error, setError] = useState('') | ||
| const [resendTimer, setResendTimer] = useCountdown(0) | ||
|
|
@@ -269,35 +281,37 @@ const OtpAuth = ({ | |
|
|
||
| {/* Buttons */} | ||
| <HStack spacing={4} width="100%" justifyContent="center"> | ||
| <Button | ||
| onClick={handleCheckoutAsGuest} | ||
| variant="solid" | ||
| size="lg" | ||
| minWidth="160px" | ||
| isDisabled={isVerifying} | ||
| bg="gray.50" | ||
| color="gray.800" | ||
| fontWeight="bold" | ||
| border="none" | ||
| _hover={{ | ||
| bg: 'gray.100' | ||
| }} | ||
| _active={{ | ||
| bg: 'gray.200' | ||
| }} | ||
| > | ||
| {isGuestRegistration ? ( | ||
| <FormattedMessage | ||
| defaultMessage="Cancel" | ||
| id="otp.button.cancel_guest_registration" | ||
| /> | ||
| ) : ( | ||
| <FormattedMessage | ||
| defaultMessage="Checkout as a Guest" | ||
| id="otp.button.checkout_as_guest" | ||
| /> | ||
| )} | ||
| </Button> | ||
| {!hideCheckoutAsGuestButton && ( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| <Button | ||
| onClick={handleCheckoutAsGuest} | ||
| variant="solid" | ||
| size="lg" | ||
| minWidth="160px" | ||
| isDisabled={isVerifying} | ||
| bg="gray.50" | ||
| color="gray.800" | ||
| fontWeight="bold" | ||
| border="none" | ||
| _hover={{ | ||
| bg: 'gray.100' | ||
| }} | ||
| _active={{ | ||
| bg: 'gray.200' | ||
| }} | ||
| > | ||
| {isGuestRegistration ? ( | ||
| <FormattedMessage | ||
| defaultMessage="Cancel" | ||
| id="otp.button.cancel_guest_registration" | ||
| /> | ||
| ) : ( | ||
| <FormattedMessage | ||
| defaultMessage="Checkout as a Guest" | ||
| id="otp.button.checkout_as_guest" | ||
| /> | ||
| )} | ||
| </Button> | ||
| )} | ||
|
|
||
| <Button | ||
| onClick={handleResend} | ||
|
|
@@ -338,7 +352,8 @@ OtpAuth.propTypes = { | |
| handleSendEmailOtp: PropTypes.func.isRequired, | ||
| handleOtpVerification: PropTypes.func.isRequired, | ||
| onCheckoutAsGuest: PropTypes.func, | ||
| isGuestRegistration: PropTypes.bool | ||
| isGuestRegistration: PropTypes.bool, | ||
| hideCheckoutAsGuestButton: PropTypes.bool | ||
| } | ||
|
|
||
| export default OtpAuth | ||



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.
Cool, thank you for updating the E2E tests too.