Skip to content

Commit 0f6b842

Browse files
committed
Fix contact-info page not showing check your email modal when one-click-checkout is disabled
1 parent 3c2123a commit 0f6b842

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

packages/template-retail-react-app/app/hooks/use-auth-modal.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
import LoginForm from '@salesforce/retail-react-app/app/components/login'
3030
import ResetPasswordForm from '@salesforce/retail-react-app/app/components/reset-password'
3131
import RegisterForm from '@salesforce/retail-react-app/app/components/register'
32+
import PasswordlessEmailConfirmation from '@salesforce/retail-react-app/app/components/email-confirmation/index'
3233
import OtpAuth from '@salesforce/retail-react-app/app/components/otp-auth'
3334
import {noop} from '@salesforce/retail-react-app/app/utils/utils'
3435
import {API_ERROR_MESSAGE} from '@salesforce/retail-react-app/app/constants'
@@ -110,14 +111,11 @@ export const AuthModal = ({
110111
locale: locale.id,
111112
...(callbackURL && {callbackURI: `${callbackURL}?redirectUrl=${redirectPath}`})
112113
})
113-
// Close AuthModal first, then open OtpAuth modal after a brief delay
114-
onClose()
115-
setTimeout(() => {
116-
setIsOtpAuthOpen(true)
117-
}, 150) // Small delay to allow AuthModal to close first
114+
return {success: true}
118115
} catch (error) {
119116
const message = formatMessage(getAuthorizePasswordlessErrorMessage(error.message))
120117
form.setError('global', {type: 'manual', message})
118+
return {success: false}
121119
}
122120
}
123121

@@ -160,7 +158,15 @@ export const AuthModal = ({
160158
login: async (data) => {
161159
if (isPasswordless) {
162160
const email = data.email
163-
await handlePasswordlessLogin(email)
161+
const {success} = await handlePasswordlessLogin(email)
162+
// Only close AuthModal and open OtpAuth modal if passwordless login succeeded
163+
if (success) {
164+
// Close AuthModal first, then open OtpAuth modal after a brief delay
165+
onClose()
166+
setTimeout(() => {
167+
setIsOtpAuthOpen(true)
168+
}, 150) // Small delay to allow AuthModal to close first
169+
}
164170
return
165171
}
166172

@@ -204,6 +210,10 @@ export const AuthModal = ({
204210
const message = formatMessage(getPasswordResetErrorMessage(e.message))
205211
form.setError('global', {type: 'manual', message})
206212
}
213+
},
214+
email: async () => {
215+
const email = form.getValues().email || initialEmail
216+
await handlePasswordlessLogin(email)
207217
}
208218
}[currentView](data)
209219
}
@@ -346,6 +356,13 @@ export const AuthModal = ({
346356
clickSignIn={onBackToSignInClick}
347357
/>
348358
)}
359+
{currentView === EMAIL_VIEW && (
360+
<PasswordlessEmailConfirmation
361+
form={form}
362+
submitForm={submitForm}
363+
email={form.getValues().email || initialEmail}
364+
/>
365+
)}
349366
</ModalBody>
350367
</ModalContent>
351368
</Modal>

packages/template-retail-react-app/app/hooks/use-auth-modal.test.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import {
1515
registerUserToken,
1616
clearAllCookies
1717
} from '@salesforce/retail-react-app/app/utils/test-utils'
18-
import {AuthModal, useAuthModal} from '@salesforce/retail-react-app/app/hooks/use-auth-modal'
18+
import {
19+
AuthModal,
20+
useAuthModal,
21+
EMAIL_VIEW
22+
} from '@salesforce/retail-react-app/app/hooks/use-auth-modal'
1923
import {BrowserRouter as Router, Route} from 'react-router-dom'
2024
import Account from '@salesforce/retail-react-app/app/pages/account'
2125
import {rest} from 'msw'
@@ -353,6 +357,27 @@ describe('Passwordless enabled', () => {
353357
})
354358
})
355359

360+
test('shows check your email view when initial view is set to email', async () => {
361+
const {user} = renderWithProviders(
362+
<MockedComponent isPasswordlessEnabled={true} initialView={EMAIL_VIEW} />
363+
)
364+
365+
// open the modal
366+
const trigger = screen.getByText(/open modal/i)
367+
await user.click(trigger)
368+
369+
await waitFor(() => {
370+
expect(screen.getByText(/Check Your Email/i)).toBeInTheDocument()
371+
})
372+
373+
await user.click(screen.getByText(/Resend Link/i))
374+
375+
// check that the Check Your Email view is still open
376+
await waitFor(() => {
377+
expect(screen.getByText(/Check Your Email/i)).toBeInTheDocument()
378+
})
379+
})
380+
356381
test.each([
357382
['no callback_uri is registered for client', 'This feature is not currently available.'],
358383
[

0 commit comments

Comments
 (0)