-
Notifications
You must be signed in to change notification settings - Fork 92
/
CategoryFilter.tsx
53 lines (46 loc) · 1.44 KB
/
CategoryFilter.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { TGetStaticProps } from '@cromwell/core';
import { CPlugin } from '@cromwell/core-frontend';
import clsx from 'clsx';
import React from 'react';
import { useModuleState } from '../../helpers/state';
import styles from './CategoryFilter.module.scss';
const filterPluginName = '@cromwell/plugin-product-filter';
export type CategoryFilterProps = {
classes?: Partial<Record<'root' | 'plugin', string>>;
cacheSessionData?: boolean;
};
/**
* Renders product filter on a category page. A wrapper for plugin from
* `@cromwell/plugin-product-filter`
*
* - `withGetProps` - required
*/
export function CategoryFilter(props: CategoryFilterProps) {
const moduleState = useModuleState();
return (
<div className={clsx(styles.CategoryFilter, props.classes?.root)}>
<CPlugin
id="ccom_category_filter_plugin"
className={clsx(props.classes?.plugin)}
plugin={{
pluginName: filterPluginName,
instanceSettings: {
listId: moduleState.categoryListId,
cacheSessionData: props.cacheSessionData,
},
}}
blockName="Product filter"
/>
</div>
);
}
CategoryFilter.withGetProps = (originalGetProps?: TGetStaticProps) => {
const getProps: TGetStaticProps = async (context) => {
const originProps: any = (await originalGetProps?.(context)) ?? {};
return {
...originProps,
extraPlugins: [filterPluginName],
};
};
return getProps;
};