Skip to content

Commit 4ff3c4f

Browse files
@W-21451244 Mobile launch location support and header icon fixes (#3724)
* feat: add support for mobile and fix the header icons
1 parent 4e372ae commit 4ff3c4f

File tree

4 files changed

+57
-22
lines changed

4 files changed

+57
-22
lines changed

packages/template-retail-react-app/app/components/header/index.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ const Header = ({
174174
<Box as="header" role="banner" {...styles.container} {...props}>
175175
<Box {...styles.content}>
176176
{showLoading && <LoadingSpinner wrapperStyles={{height: '100vh'}} />}
177-
<Flex wrap="wrap" alignItems={['baseline', 'baseline', 'baseline', 'center']}>
177+
<Flex
178+
wrap="wrap"
179+
alignItems={['baseline', 'baseline', 'baseline', 'center']}
180+
gap={3}
181+
>
178182
<IconButton
179183
aria-label={intl.formatMessage({
180184
id: 'header.button.assistive_msg.menu',
@@ -213,6 +217,7 @@ const Header = ({
213217
})}
214218
variant="unstyled"
215219
{...styles.icons}
220+
{...styles.agentIcon}
216221
onClick={onAgentClick}
217222
/>
218223
)}

packages/template-retail-react-app/app/components/search/index.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
} from '@salesforce/retail-react-app/app/utils/url'
4343
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
4444
import {getCommerceAgentConfig} from '@salesforce/retail-react-app/app/utils/config-utils'
45+
import {launchChat as launchChatFromUtils} from '@salesforce/retail-react-app/app/utils/shopper-agent-utils'
4546
import {useUsid} from '@salesforce/commerce-sdk-react'
4647
import {useLocation} from 'react-router-dom'
4748
import useRefreshToken from '@salesforce/retail-react-app/app/hooks/use-refresh-token'
@@ -351,9 +352,11 @@ const Search = (props) => {
351352
}
352353

353354
const onAskAssistantClick = useCallback(() => {
354-
launchChat()
355+
// When floating button is hidden (enableAgentFromFloatingButton false), show it first then launch
356+
setPrechatFieldsForNewSession()
357+
launchChatFromUtils()
355358
clearInput()
356-
}, [launchChat, clearInput])
359+
}, [setPrechatFieldsForNewSession, clearInput])
357360

358361
const shouldOpenPopover = () => {
359362
// As per design we only want to show the popover if the input is focused and we have recent searches saved

packages/template-retail-react-app/app/components/search/partials/ask-assistant-banner.jsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import React from 'react'
7+
import React, {useRef} from 'react'
88
import PropTypes from 'prop-types'
99
import {Box, Text} from '@salesforce/retail-react-app/app/components/shared/ui'
1010
import {useIntl} from 'react-intl'
1111
import {SparkleIcon, ChevronRightIcon} from '@salesforce/retail-react-app/app/components/icons'
1212

1313
const AskAssistantBanner = ({onClick, styles}) => {
1414
const intl = useIntl()
15+
const handledByTouchRef = useRef(false)
1516
const title = intl.formatMessage({
1617
id: 'search.suggestions.askAssistant.title',
1718
defaultMessage: 'Ask Shopping Agent'
@@ -27,13 +28,36 @@ const AskAssistantBanner = ({onClick, styles}) => {
2728
onClick?.()
2829
}
2930

31+
const handleTouchStart = (e) => {
32+
// Prevent the search input from blurring when the user touches the banner.
33+
// Otherwise onBlur closes the overlay before touchEnd/click fires, so the tap never runs.
34+
e.preventDefault()
35+
}
36+
37+
const handleTouchEnd = () => {
38+
handledByTouchRef.current = true
39+
onClick?.()
40+
setTimeout(() => {
41+
handledByTouchRef.current = false
42+
}, 400)
43+
}
44+
45+
const handleClick = (e) => {
46+
if (handledByTouchRef.current) {
47+
return
48+
}
49+
handleInteraction(e)
50+
}
51+
3052
return (
3153
<Box
3254
{...styles.askAssistantBanner}
3355
as="button"
3456
type="button"
3557
textAlign="left"
36-
onClick={handleInteraction}
58+
onClick={handleClick}
59+
onTouchStart={handleTouchStart}
60+
onTouchEnd={handleTouchEnd}
3761
aria-label={ariaLabel}
3862
>
3963
<Box {...styles.askAssistantBannerIcon}>

packages/template-retail-react-app/app/theme/components/project/header.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export default {
2424
searchContainer: {
2525
order: [2, 2, 2, 'inherit'],
2626
width: ['full', 'full', 'full', 60],
27-
marginRight: [0, 0, 0, 4],
2827
marginBottom: [1, 1, 2, 0]
2928
},
3029
bodyContainer: {
@@ -35,37 +34,31 @@ export default {
3534
height: [6, 6, 6, 8]
3635
},
3736
icons: {
38-
marginBottom: [1, 1, 2, 0]
39-
},
40-
accountIcon: {
4137
height: 11,
4238
minWidth: 'auto',
43-
cursor: 'pointer',
44-
alignSelf: ['self-start', 'self-start', 'self-start', 'auto'],
39+
marginBottom: [1, 1, 2, 0],
4540
_focus: {
4641
boxShadow: 'outline'
4742
},
4843
_focusVisible: {
4944
outline: 0
5045
}
5146
},
47+
agentIcon: {
48+
alignSelf: ['self-start', 'self-start', 'self-start', 'auto']
49+
},
50+
accountIcon: {
51+
cursor: 'pointer',
52+
alignSelf: ['self-start', 'self-start', 'self-start', 'auto']
53+
},
5254
arrowDown: {
53-
height: 11,
54-
minWidth: 'auto',
5555
marginRight: 0,
5656
alignSelf: ['self-start', 'self-start', 'self-start', 'auto'],
5757
cursor: 'pointer',
58-
_focus: {
59-
boxShadow: 'outline'
60-
},
61-
_focusVisible: {
62-
outline: 0
63-
},
6458
display: ['none', 'none', 'none', 'block']
6559
},
6660
wishlistIcon: {
67-
// More breathing room between the account and wishlist icons
68-
marginLeft: 2
61+
alignSelf: ['self-start', 'self-start', 'self-start', 'auto']
6962
},
7063
signout: {
7164
width: '100%',
@@ -86,5 +79,15 @@ export default {
8679
marginRight: 2
8780
}
8881
},
89-
parts: ['container', 'content', 'searchContainer', 'bodyContainer', 'logo', 'icons', 'signout']
82+
parts: [
83+
'container',
84+
'content',
85+
'searchContainer',
86+
'bodyContainer',
87+
'logo',
88+
'icons',
89+
'agentIcon',
90+
'wishlistIcon',
91+
'signout'
92+
]
9093
}

0 commit comments

Comments
 (0)