@vtex/faststore-plugin-buyer-portal 1.3.36 → 1.3.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/package.json +1 -1
- package/src/features/payment-methods/clients/PaymentMethodsClient.ts +9 -4
- package/src/features/payment-methods/components/AddPaymentMethodsDrawer/AddPaymentMethodsDrawer.tsx +75 -10
- package/src/features/payment-methods/components/AddPaymentMethodsDrawer/add-payment-methods-drawer.scss +17 -0
- package/src/features/payment-methods/hooks/useDebouncedSearchPaymentMethods.ts +4 -4
- package/src/features/payment-methods/hooks/useGetPaymentMethodsByUnitId.ts +2 -3
- package/src/features/payment-methods/layouts/PaymentMethodsLayout/PaymentMethodsLayout.tsx +80 -59
- package/src/features/payment-methods/layouts/PaymentMethodsLayout/payment-methods-layout.scss +147 -122
- package/src/features/payment-methods/services/get-payment-methods-by-unit-id.service.ts +7 -5
- package/src/features/payment-methods/types/PaymentMethod.ts +7 -0
- package/src/features/payment-methods/types/index.ts +1 -1
- package/src/features/product-assortment/clients/ProductAssortmentClient.ts +15 -9
- package/src/features/product-assortment/components/AddProductAssortmentDrawer/AddProductAssortmentDrawer.tsx +73 -28
- package/src/features/product-assortment/components/AddProductAssortmentDrawer/add-product-assortment-drawer.scss +4 -0
- package/src/features/product-assortment/components/ProductAssortmentTable/ProductAssortmentTable.tsx +2 -2
- package/src/features/product-assortment/hooks/index.ts +3 -0
- package/src/features/product-assortment/hooks/useGetProductAssortments.ts +35 -0
- package/src/features/product-assortment/layouts/ProductAssortmentLayout/ProductAssortmentLayout.tsx +33 -13
- package/src/features/product-assortment/services/get-product-assortment-from-contract.service.ts +4 -5
- package/src/features/product-assortment/services/get-product-assortment-from-scope.service.ts +9 -4
- package/src/features/product-assortment/services/index.ts +4 -0
- package/src/features/product-assortment/types/index.ts +19 -14
- package/src/features/shared/utils/constants.ts +1 -1
- package/src/features/shared/utils/creditCard.ts +1 -1
- package/src/pages/payment-methods.tsx +23 -4
- package/src/pages/productAssortment.tsx +18 -17
package/src/features/product-assortment/layouts/ProductAssortmentLayout/ProductAssortmentLayout.tsx
CHANGED
|
@@ -14,7 +14,7 @@ import { ProductAssortmentTable } from "../../components/ProductAssortmentTable/
|
|
|
14
14
|
|
|
15
15
|
import type {
|
|
16
16
|
ProductAssortmentLayoutProps,
|
|
17
|
-
|
|
17
|
+
ProductAssortmentWithAdditionalInformation,
|
|
18
18
|
} from "../../types";
|
|
19
19
|
|
|
20
20
|
export const ProductAssortmentLayout = ({
|
|
@@ -36,20 +36,23 @@ export const ProductAssortmentLayout = ({
|
|
|
36
36
|
searchTerm,
|
|
37
37
|
setSearchTerm,
|
|
38
38
|
increasePage,
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
decreasePage,
|
|
40
|
+
} = usePageItems<ProductAssortmentWithAdditionalInformation>({
|
|
41
|
+
initialItems: initialProductAssortment.items,
|
|
41
42
|
search,
|
|
42
43
|
page,
|
|
43
44
|
});
|
|
44
45
|
|
|
46
|
+
const isLastPage = initialProductAssortment.paging.pages === page;
|
|
47
|
+
|
|
45
48
|
const {
|
|
46
49
|
open: openAddProductAssortmentDrawer,
|
|
47
50
|
isOpen: isOpenAddProductAssortmentDrawer,
|
|
48
51
|
...addProductAssortmentDrawerProps
|
|
49
52
|
} = useDrawerProps();
|
|
50
53
|
|
|
51
|
-
const enabledAssortment = productAssortment.filter((p) => p.isEnabled);
|
|
52
|
-
const hasAllAssortment = drawerProductAssortment.length === 0;
|
|
54
|
+
//const enabledAssortment = productAssortment.filter((p) => p.isEnabled);
|
|
55
|
+
const hasAllAssortment = drawerProductAssortment.items.length === 0;
|
|
53
56
|
|
|
54
57
|
return (
|
|
55
58
|
<GlobalLayout>
|
|
@@ -102,8 +105,12 @@ export const ProductAssortmentLayout = ({
|
|
|
102
105
|
textSearch={setSearchTerm}
|
|
103
106
|
/>
|
|
104
107
|
<Paginator.Counter
|
|
105
|
-
total={
|
|
106
|
-
itemsLength={
|
|
108
|
+
total={initialProductAssortment.paging.total}
|
|
109
|
+
itemsLength={
|
|
110
|
+
isLastPage
|
|
111
|
+
? initialProductAssortment.paging.total
|
|
112
|
+
: page * initialProductAssortment.paging.perPage
|
|
113
|
+
}
|
|
107
114
|
/>
|
|
108
115
|
</div>
|
|
109
116
|
|
|
@@ -111,20 +118,34 @@ export const ProductAssortmentLayout = ({
|
|
|
111
118
|
<ProductAssortmentTable productAssortment={productAssortment} />
|
|
112
119
|
|
|
113
120
|
<div data-fs-bp-product-assortment-paginator>
|
|
114
|
-
{
|
|
121
|
+
{initialProductAssortment.paging.page > 1 ? (
|
|
122
|
+
<Paginator.NextPageButton
|
|
123
|
+
onClick={decreasePage}
|
|
124
|
+
disabled={isLoading}
|
|
125
|
+
>
|
|
126
|
+
{isLoading ? "Loading" : "Previous Page"}
|
|
127
|
+
</Paginator.NextPageButton>
|
|
128
|
+
) : (
|
|
129
|
+
<></>
|
|
130
|
+
)}
|
|
131
|
+
{!isLastPage ? (
|
|
115
132
|
<Paginator.NextPageButton
|
|
116
133
|
onClick={increasePage}
|
|
117
134
|
disabled={isLoading}
|
|
118
135
|
>
|
|
119
|
-
{isLoading ? "Loading" : "
|
|
136
|
+
{isLoading ? "Loading" : "Next Page"}
|
|
120
137
|
</Paginator.NextPageButton>
|
|
121
138
|
) : (
|
|
122
|
-
|
|
139
|
+
<></>
|
|
123
140
|
)}
|
|
124
141
|
|
|
125
142
|
<Paginator.Counter
|
|
126
|
-
total={
|
|
127
|
-
itemsLength={
|
|
143
|
+
total={initialProductAssortment.paging.total}
|
|
144
|
+
itemsLength={
|
|
145
|
+
isLastPage
|
|
146
|
+
? initialProductAssortment.paging.total
|
|
147
|
+
: page * initialProductAssortment.paging.perPage
|
|
148
|
+
}
|
|
128
149
|
/>
|
|
129
150
|
</div>
|
|
130
151
|
</section>
|
|
@@ -134,7 +155,6 @@ export const ProductAssortmentLayout = ({
|
|
|
134
155
|
|
|
135
156
|
{isOpenAddProductAssortmentDrawer && (
|
|
136
157
|
<AddProductAssortmentDrawer
|
|
137
|
-
productAssortment={drawerProductAssortment}
|
|
138
158
|
isOpen={isOpenAddProductAssortmentDrawer}
|
|
139
159
|
{...addProductAssortmentDrawerProps}
|
|
140
160
|
/>
|
package/src/features/product-assortment/services/get-product-assortment-from-contract.service.ts
CHANGED
|
@@ -2,12 +2,11 @@ import { productAssortmentClient } from "../clients/ProductAssortmentClient";
|
|
|
2
2
|
|
|
3
3
|
export const getProductAssortmentFromContractService = async (
|
|
4
4
|
params: Parameters<
|
|
5
|
-
typeof productAssortmentClient.
|
|
5
|
+
typeof productAssortmentClient.getProductAssortmentsInfoInContract
|
|
6
6
|
>[0]
|
|
7
7
|
) => {
|
|
8
|
-
const data =
|
|
9
|
-
params
|
|
10
|
-
);
|
|
8
|
+
const data =
|
|
9
|
+
await productAssortmentClient.getProductAssortmentsInfoInContract(params);
|
|
11
10
|
|
|
12
|
-
return data;
|
|
11
|
+
return data.paging;
|
|
13
12
|
};
|
package/src/features/product-assortment/services/get-product-assortment-from-scope.service.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { isRightFormat } from "../../shared/utils/isRightFormat";
|
|
2
2
|
import { productAssortmentClient } from "../clients/ProductAssortmentClient";
|
|
3
|
+
import { GetProductAssortmentFromContractResponse } from "../types";
|
|
3
4
|
|
|
4
|
-
export
|
|
5
|
+
export interface GetProductAssortmentFromScopeServiceProps {
|
|
5
6
|
args: Parameters<
|
|
6
7
|
typeof productAssortmentClient.getProductAssortmentListInScope
|
|
7
|
-
>[0]
|
|
8
|
-
|
|
8
|
+
>[0];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const getProductAssortmentFromScopeService = async ({
|
|
12
|
+
args,
|
|
13
|
+
}: GetProductAssortmentFromScopeServiceProps) => {
|
|
9
14
|
try {
|
|
10
15
|
const data = await productAssortmentClient.getProductAssortmentListInScope(
|
|
11
16
|
args
|
|
@@ -19,7 +24,7 @@ export const getProductAssortmentFromScopeService = async (
|
|
|
19
24
|
isRightFormat(err) &&
|
|
20
25
|
err.message.startsWith("No Product assortment found for the name")
|
|
21
26
|
) {
|
|
22
|
-
return
|
|
27
|
+
return {} as GetProductAssortmentFromContractResponse;
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
30
|
|
|
@@ -9,19 +9,26 @@ export type ProductAssortmentSummary = {
|
|
|
9
9
|
name: string;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
export type ProductAssortmentWithAdditionalInformation =
|
|
13
|
+
ProductAssortmentSummary & {
|
|
14
|
+
isEnabled: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type PageControl = {
|
|
18
|
+
page: number;
|
|
19
|
+
perPage: number;
|
|
20
|
+
total: number;
|
|
21
|
+
pages: number;
|
|
22
|
+
limit: number;
|
|
17
23
|
};
|
|
18
24
|
|
|
19
25
|
export type GetProductAssortmentFromContractResponse = {
|
|
20
|
-
|
|
26
|
+
items: Array<ProductAssortmentWithAdditionalInformation>;
|
|
27
|
+
paging: PageControl;
|
|
21
28
|
};
|
|
22
29
|
|
|
23
30
|
export type GetProductAssortmentFromScopeResponse = {
|
|
24
|
-
collections: Array<
|
|
31
|
+
collections: Array<ProductAssortmentWithAdditionalInformation>;
|
|
25
32
|
};
|
|
26
33
|
|
|
27
34
|
export type AddProductAssortmentResponse = {
|
|
@@ -34,9 +41,7 @@ export type AddProductAssortmentPayload = Array<{ name: string }>;
|
|
|
34
41
|
export type AddProductAssortmentDrawerProps = Omit<
|
|
35
42
|
BasicDrawerProps,
|
|
36
43
|
"children"
|
|
37
|
-
|
|
38
|
-
productAssortment: ScopeProductAssortment[];
|
|
39
|
-
};
|
|
44
|
+
>;
|
|
40
45
|
|
|
41
46
|
export type RemoveProductAssortmentDrawerProps = Omit<
|
|
42
47
|
BasicDrawerProps,
|
|
@@ -50,16 +55,16 @@ export interface ProductAssortmentSelectedProps {
|
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
export type ProductAssortmentLayoutProps = {
|
|
53
|
-
initialProductAssortment:
|
|
54
|
-
drawerProductAssortment:
|
|
58
|
+
initialProductAssortment: GetProductAssortmentFromContractResponse;
|
|
59
|
+
drawerProductAssortment: GetProductAssortmentFromContractResponse;
|
|
55
60
|
page: number;
|
|
56
61
|
search: string;
|
|
57
62
|
isContractEmpty: boolean;
|
|
58
63
|
};
|
|
59
64
|
|
|
60
65
|
export type ProductAssortmentData = {
|
|
61
|
-
productAssortment:
|
|
62
|
-
drawerProductAssortment:
|
|
66
|
+
productAssortment: GetProductAssortmentFromContractResponse;
|
|
67
|
+
drawerProductAssortment: GetProductAssortmentFromContractResponse;
|
|
63
68
|
isContractEmpty: boolean;
|
|
64
69
|
search: string;
|
|
65
70
|
page: number;
|
|
@@ -14,7 +14,7 @@ export const maskExpirationDate = (expDate: string) => {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export const maskCVV = (verificationCode: string) => {
|
|
17
|
-
return mask(verificationCode, "
|
|
17
|
+
return mask(verificationCode, "9999").substring(0, 4);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export const findCardNetwork = (
|
|
@@ -13,18 +13,20 @@ import {
|
|
|
13
13
|
withLoaderErrorBoundary,
|
|
14
14
|
withAuthLoader,
|
|
15
15
|
withProviders,
|
|
16
|
+
getValidPage,
|
|
16
17
|
} from "../features/shared/utils";
|
|
17
18
|
import { getUserByIdService } from "../features/users/services";
|
|
18
19
|
|
|
19
20
|
import type { ContractData } from "../features/contracts/types";
|
|
20
21
|
import type { OrgUnitBasicData } from "../features/org-units/types";
|
|
21
|
-
import type {
|
|
22
|
+
import type { PaginatedPaymentMethod } from "../features/payment-methods/types";
|
|
22
23
|
import type { AuthRouteProps, LoaderData } from "../features/shared/types";
|
|
23
24
|
import type { UserData } from "../features/users/types";
|
|
24
25
|
|
|
25
26
|
export type PaymentMethodsPageData = {
|
|
26
|
-
data:
|
|
27
|
+
data: PaginatedPaymentMethod;
|
|
27
28
|
search?: string;
|
|
29
|
+
totalPaymentMethods: number;
|
|
28
30
|
context: {
|
|
29
31
|
currentContract: ContractData | null;
|
|
30
32
|
clientContext: ClientContext;
|
|
@@ -38,12 +40,15 @@ export type PaymentMethodsPageData = {
|
|
|
38
40
|
export type PaymentMethodsPageQuery = GetPaymentMethodsByUnitIdServiceProps & {
|
|
39
41
|
orgUnitId: string;
|
|
40
42
|
contractId: string;
|
|
43
|
+
page: string;
|
|
41
44
|
};
|
|
42
45
|
|
|
43
46
|
const loaderFunction = async (
|
|
44
47
|
data: LoaderData<PaymentMethodsPageQuery>
|
|
45
48
|
): Promise<AuthRouteProps<PaymentMethodsPageData>> => {
|
|
46
|
-
const { contractId, orgUnitId, search } = data.query;
|
|
49
|
+
const { contractId, orgUnitId, search, page: pageString } = data.query;
|
|
50
|
+
|
|
51
|
+
const page = getValidPage(pageString);
|
|
47
52
|
|
|
48
53
|
return withAuthLoader(data, async ({ cookie, userId, ...clientContext }) => {
|
|
49
54
|
const currentOrgUnit = await getOrgUnitBasicDataService({
|
|
@@ -63,11 +68,21 @@ const loaderFunction = async (
|
|
|
63
68
|
customerId: contractId,
|
|
64
69
|
unitId: currentOrgUnit.id,
|
|
65
70
|
cookie,
|
|
71
|
+
search,
|
|
72
|
+
page,
|
|
73
|
+
filterByScope: true,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const contractPaymentMethods = await getPaymentMethodsByUnitIdService({
|
|
77
|
+
customerId: contractId,
|
|
78
|
+
unitId: currentOrgUnit.id,
|
|
79
|
+
cookie,
|
|
66
80
|
});
|
|
67
81
|
|
|
68
82
|
return {
|
|
69
83
|
data: paymentMethods,
|
|
70
84
|
search: search ?? "",
|
|
85
|
+
totalPaymentMethods: contractPaymentMethods.paging.total,
|
|
71
86
|
context: {
|
|
72
87
|
clientContext: { cookie, userId, ...clientContext },
|
|
73
88
|
currentOrgUnit,
|
|
@@ -85,6 +100,7 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
|
85
100
|
|
|
86
101
|
const PaymentMethodsPage = ({
|
|
87
102
|
data,
|
|
103
|
+
totalPaymentMethods,
|
|
88
104
|
hasError,
|
|
89
105
|
error,
|
|
90
106
|
}: PaymentMethodsPageData) => (
|
|
@@ -92,7 +108,10 @@ const PaymentMethodsPage = ({
|
|
|
92
108
|
{hasError ? (
|
|
93
109
|
<ErrorTabsLayout error={error} />
|
|
94
110
|
) : (
|
|
95
|
-
<PaymentMethodsLayout
|
|
111
|
+
<PaymentMethodsLayout
|
|
112
|
+
data={data}
|
|
113
|
+
totalPaymentMethods={totalPaymentMethods}
|
|
114
|
+
/>
|
|
96
115
|
)}
|
|
97
116
|
</>
|
|
98
117
|
);
|
|
@@ -31,22 +31,26 @@ const loaderFunction = async (
|
|
|
31
31
|
getContractDetailsService({ contractId, cookie, unitId: orgUnitId }),
|
|
32
32
|
]);
|
|
33
33
|
|
|
34
|
-
const [enabledAssortment,
|
|
34
|
+
const [enabledAssortment, notAddedAssortments, contractAssortment] =
|
|
35
35
|
await Promise.all([
|
|
36
36
|
getProductAssortmentFromScopeService({
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
args: {
|
|
38
|
+
cookie,
|
|
39
|
+
contractId,
|
|
40
|
+
unitId: orgUnitId,
|
|
41
|
+
filterByScope: true,
|
|
42
|
+
name: search,
|
|
43
|
+
page,
|
|
44
|
+
},
|
|
43
45
|
}),
|
|
44
46
|
getProductAssortmentFromScopeService({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
args: {
|
|
48
|
+
cookie,
|
|
49
|
+
contractId,
|
|
50
|
+
unitId: orgUnitId,
|
|
51
|
+
filterByScope: false,
|
|
52
|
+
page: 1,
|
|
53
|
+
},
|
|
50
54
|
}),
|
|
51
55
|
getProductAssortmentFromContractService({
|
|
52
56
|
contractId,
|
|
@@ -56,14 +60,11 @@ const loaderFunction = async (
|
|
|
56
60
|
]);
|
|
57
61
|
|
|
58
62
|
const isContractEmpty =
|
|
59
|
-
!
|
|
60
|
-
const drawerProductAssortment = allAssortment.filter(
|
|
61
|
-
(col) => !col.isEnabled
|
|
62
|
-
);
|
|
63
|
+
!contractAssortment || contractAssortment.total === 0;
|
|
63
64
|
|
|
64
65
|
return {
|
|
65
66
|
productAssortment: enabledAssortment,
|
|
66
|
-
drawerProductAssortment,
|
|
67
|
+
drawerProductAssortment: notAddedAssortments,
|
|
67
68
|
isContractEmpty,
|
|
68
69
|
search,
|
|
69
70
|
page,
|