Skip to content

Commit 87ef7ef

Browse files
[CI 3213] Create zero results page (#70)
* create zero results page * lint * code review changes * lint * import fix * lint fix
1 parent 801a56f commit 87ef7ef

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.cio-zero-results-header {
2+
font-weight: 700;
3+
font-size: 20px;
4+
}
5+
6+
.cio-zero-results-option-list {
7+
font-weight: 400;
8+
font-size: 16px;
9+
padding-left: 18px;
10+
padding-top: 6px;
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import useRequestConfigs from '../../hooks/useRequestConfigs';
3+
import './ZeroResults.css';
4+
5+
/**
6+
* Renders the 'no results' component if search results returns no items.
7+
*
8+
* @component
9+
* @returns {JSX.Element} The 'no results' component
10+
*/
11+
export default function ZeroResults() {
12+
const config = useRequestConfigs();
13+
const { query } = config.requestConfigs;
14+
15+
return (
16+
<>
17+
<div className='cio-zero-results-header'>Sorry, we didn’t find: “{query}</div>
18+
<ul className='cio-zero-results-option-list'>
19+
<li>Check for typos</li>
20+
<li>Use fewer keywords</li>
21+
<li>Broaden your search terms</li>
22+
</ul>
23+
</>
24+
);
25+
}

src/components/SearchResults/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IncludeRenderProps, PlpSearchRedirectResponse, PlpSearchResponse } from
44
import ProductCard from '../ProductCard';
55
import { useCioPlpContext } from '../../hooks/useCioPlpContext';
66
import '../../styles.css';
7+
import ZeroResults from './ZeroResults';
78

89
/**
910
* Props for the SearchResults component.
@@ -55,18 +56,18 @@ export default function SearchResults(props: SearchResultsWithRenderProps = {})
5556
children({ status, data, pagination, refetch })
5657
) : (
5758
<>
58-
<div>Search Results</div>
59-
<>
60-
{data.response?.results?.length ? (
59+
{data.response?.results?.length ? (
60+
<>
61+
<div>Search Results</div>
6162
<div className='cio-results data-results-search' data-cnstrc-search>
6263
{data.response?.results.map((item) => (
6364
<ProductCard item={item} key={item.itemId} />
6465
))}
6566
</div>
66-
) : (
67-
"Can't find matching items. Please try something else"
68-
)}
69-
</>
67+
</>
68+
) : (
69+
<ZeroResults />
70+
)}
7071
</>
7172
)}
7273
</>

src/stories/components/SearchResults/SearchResults.stories.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,23 @@ export const Primary: Story = {
3838
},
3939
],
4040
};
41+
42+
export const ZeroResults: Story = {
43+
render: (args) => (
44+
<CioPlp apiKey={DEMO_API_KEY}>
45+
<div>Example Url: https://www.example.com?q=cvwdacoknqeauosd1</div>
46+
<br />
47+
<SearchResults {...args} />
48+
</CioPlp>
49+
),
50+
decorators: [
51+
(Story) => {
52+
const url = new URL(window.location as any);
53+
/* cspell:disable-next-line */
54+
url.searchParams.set('q', 'cvwdacoknqeauosd1');
55+
window.history.pushState({}, '', url);
56+
57+
return <Story />;
58+
},
59+
],
60+
};

0 commit comments

Comments
 (0)