@akinon/pz-multi-basket 1.42.0-rc.15
Sign up to get free protection for your applications and to get access to all the features.
- package/.gitattributes +14 -0
- package/.prettierrc +13 -0
- package/CHANGELOG.md +7 -0
- package/README.md +29 -0
- package/package.json +19 -0
- package/src/index.ts +1 -0
- package/src/views/MultiBasket.tsx +126 -0
package/.gitattributes
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
*.js text eol=lf
|
2
|
+
*.jsx text eol=lf
|
3
|
+
*.ts text eol=lf
|
4
|
+
*.tsx text eol=lf
|
5
|
+
*.json text eol=lf
|
6
|
+
*.md text eol=lf
|
7
|
+
|
8
|
+
.eslintignore text eol=lf
|
9
|
+
.eslintrc text eol=lf
|
10
|
+
.gitignore text eol=lf
|
11
|
+
.prettierrc text eol=lf
|
12
|
+
.yarnrc text eol=lf
|
13
|
+
|
14
|
+
* text=auto
|
package/.prettierrc
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"bracketSameLine": false,
|
3
|
+
"tabWidth": 2,
|
4
|
+
"singleQuote": true,
|
5
|
+
"jsxSingleQuote": false,
|
6
|
+
"bracketSpacing": true,
|
7
|
+
"semi": true,
|
8
|
+
"useTabs": false,
|
9
|
+
"arrowParens": "always",
|
10
|
+
"endOfLine": "lf",
|
11
|
+
"proseWrap": "never",
|
12
|
+
"trailingComma": "none"
|
13
|
+
}
|
package/CHANGELOG.md
ADDED
package/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# pz-multi-basket
|
2
|
+
|
3
|
+
### Setting the Visibility of Multi Basket
|
4
|
+
|
5
|
+
```javascript
|
6
|
+
// settings.js file
|
7
|
+
|
8
|
+
module.exports = {
|
9
|
+
// other settings
|
10
|
+
plugins: {
|
11
|
+
// other plugin settings
|
12
|
+
multiBasket: true
|
13
|
+
}
|
14
|
+
};
|
15
|
+
```
|
16
|
+
|
17
|
+
### Usage in Plugin Module System
|
18
|
+
|
19
|
+
```javascript
|
20
|
+
import PluginModule, { Component } from '@akinon/next/components/plugin-module';
|
21
|
+
|
22
|
+
<PluginModule component={Component.MultiBasket} props={{ BasketItem }} />;
|
23
|
+
```
|
24
|
+
|
25
|
+
## Props
|
26
|
+
|
27
|
+
| Property | Type | Description |
|
28
|
+
| ---------- | ------------- | ----------------------------------------- |
|
29
|
+
| BasketItem | `JSX.Element` | product component displayed in the basket |
|
package/package.json
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"name": "@akinon/pz-multi-basket",
|
3
|
+
"version": "1.42.0-rc.15",
|
4
|
+
"license": "MIT",
|
5
|
+
"main": "./src/index.ts",
|
6
|
+
"module": "./src/index.ts",
|
7
|
+
"peerDependencies": {
|
8
|
+
"react": "^18.0.0",
|
9
|
+
"react-dom": "^18.0.0"
|
10
|
+
},
|
11
|
+
"devDependencies": {
|
12
|
+
"@types/node": "^18.7.8",
|
13
|
+
"@types/react": "^18.0.17",
|
14
|
+
"@types/react-dom": "^18.0.6",
|
15
|
+
"react": "^18.2.0",
|
16
|
+
"react-dom": "^18.2.0",
|
17
|
+
"typescript": "^4.7.4"
|
18
|
+
}
|
19
|
+
}
|
package/src/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { MultiBasket } from './views/MultiBasket';
|
@@ -0,0 +1,126 @@
|
|
1
|
+
'use client';
|
2
|
+
|
3
|
+
import React, { useEffect, useState } from 'react';
|
4
|
+
import {
|
5
|
+
useGetBasketQuery,
|
6
|
+
useGetAllBasketsQuery,
|
7
|
+
useGetBasketDetailMutation,
|
8
|
+
useRemoveBasketMutation,
|
9
|
+
useSelectMainBasketMutation
|
10
|
+
} from '@akinon/next/data/client/basket';
|
11
|
+
import { Button, Icon, Price } from '@akinon/next/components';
|
12
|
+
import { useLocalization } from '@akinon/next/hooks';
|
13
|
+
import clsx from 'clsx';
|
14
|
+
|
15
|
+
interface Props {
|
16
|
+
BasketItem?: React.JSXElementConstructor<any>;
|
17
|
+
}
|
18
|
+
|
19
|
+
export const MultiBasket = (props: Props) => {
|
20
|
+
const { t } = useLocalization();
|
21
|
+
const { data: basketData } = useGetBasketQuery();
|
22
|
+
const { data: allBaskets, isSuccess: isAllBasketsSuccess } =
|
23
|
+
useGetAllBasketsQuery();
|
24
|
+
const { BasketItem } = props;
|
25
|
+
const [getBasketDetail] = useGetBasketDetailMutation();
|
26
|
+
const [removeBasket] = useRemoveBasketMutation();
|
27
|
+
const [selectMainBasket] = useSelectMainBasketMutation();
|
28
|
+
const [detailedBaskets, setDetailedBaskets] = useState<any[]>([]);
|
29
|
+
|
30
|
+
useEffect(() => {
|
31
|
+
const fetchAllBasketDetails = async () => {
|
32
|
+
if (!allBaskets) return;
|
33
|
+
|
34
|
+
if (allBaskets) {
|
35
|
+
const basketDetails = [];
|
36
|
+
|
37
|
+
for (const basket of allBaskets) {
|
38
|
+
try {
|
39
|
+
const detail = await getBasketDetail({
|
40
|
+
namespace: basket.namespace
|
41
|
+
}).unwrap();
|
42
|
+
basketDetails.push(detail);
|
43
|
+
} catch (error) {
|
44
|
+
console.error('Error fetching basket details:', error);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
setDetailedBaskets(basketDetails);
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
fetchAllBasketDetails();
|
52
|
+
}, [allBaskets, getBasketDetail]);
|
53
|
+
|
54
|
+
return (
|
55
|
+
<>
|
56
|
+
{isAllBasketsSuccess && (
|
57
|
+
<>
|
58
|
+
{detailedBaskets.map(({ basket }) => (
|
59
|
+
<div key={basket.pk}>
|
60
|
+
{basket?.basketitem_set?.length > 0 && (
|
61
|
+
<div className="border mb-4">
|
62
|
+
<div
|
63
|
+
className={clsx(
|
64
|
+
'w-full flex items-center justify-end border-b font-medium py-2 px-4 text-sm',
|
65
|
+
{
|
66
|
+
'justify-between': basket.namespace
|
67
|
+
}
|
68
|
+
)}
|
69
|
+
>
|
70
|
+
{basket.namespace && <h1>{basket.namespace}</h1>}
|
71
|
+
<Button
|
72
|
+
onClick={() => removeBasket({ pk: basket.pk })}
|
73
|
+
appearance="ghost"
|
74
|
+
data-testid="basket-select-button"
|
75
|
+
className="text-primary-500 font-medium border-0 p-0 m-0 hover:bg-transparent hover:text-error"
|
76
|
+
>
|
77
|
+
{t('basket.remove_basket')}
|
78
|
+
</Button>
|
79
|
+
</div>
|
80
|
+
<ul className="px-4">
|
81
|
+
{basket.basketitem_set.map((basketItem, index) => (
|
82
|
+
<BasketItem
|
83
|
+
basketItem={basketItem}
|
84
|
+
key={index}
|
85
|
+
namespace={basket.namespace}
|
86
|
+
/>
|
87
|
+
))}
|
88
|
+
</ul>
|
89
|
+
<div className="flex justify-end items-center gap-2 p-4">
|
90
|
+
<div className="flex items-center gap-3">
|
91
|
+
<div className="">
|
92
|
+
<div className="text-xs text-right font-light text-gray-900">
|
93
|
+
{t('basket.total')}
|
94
|
+
</div>
|
95
|
+
<Price
|
96
|
+
value={basket.total_amount}
|
97
|
+
data-testid="basket-total"
|
98
|
+
className="text-sm font-medium"
|
99
|
+
/>
|
100
|
+
</div>
|
101
|
+
<Button
|
102
|
+
onClick={() => selectMainBasket({ pk: basket.pk })}
|
103
|
+
data-testid="basket-select-button"
|
104
|
+
>
|
105
|
+
{basketData?.pk == basket?.pk ? (
|
106
|
+
<div className="flex items-center">
|
107
|
+
<Icon name="check" className="mr-2" />
|
108
|
+
<span>{t('basket.selected_basket')}</span>
|
109
|
+
</div>
|
110
|
+
) : (
|
111
|
+
<span>{t('basket.select_basket')}</span>
|
112
|
+
)}
|
113
|
+
</Button>
|
114
|
+
</div>
|
115
|
+
</div>
|
116
|
+
</div>
|
117
|
+
)}
|
118
|
+
</div>
|
119
|
+
))}
|
120
|
+
</>
|
121
|
+
)}
|
122
|
+
</>
|
123
|
+
);
|
124
|
+
};
|
125
|
+
|
126
|
+
export default MultiBasket;
|