@vtex/faststore-plugin-buyer-portal 1.3.76 → 1.3.78

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.
Files changed (36) hide show
  1. package/.prettierrc +3 -0
  2. package/CHANGELOG.md +27 -1
  3. package/package.json +1 -1
  4. package/src/features/addresses/clients/AddressesClient.ts +8 -26
  5. package/src/features/addresses/hooks/index.ts +1 -0
  6. package/src/features/addresses/hooks/useDebouncedSearchAddressByUnitId.ts +8 -9
  7. package/src/features/addresses/hooks/useListAddresses.ts +36 -0
  8. package/src/features/addresses/layouts/AddressesLayout/AddressesLayout.tsx +133 -151
  9. package/src/features/addresses/layouts/AddressesLayout/addresses-layout.scss +17 -2
  10. package/src/features/addresses/layouts/index.ts +1 -4
  11. package/src/features/product-assortment/clients/ProductAssortmentClient.ts +7 -45
  12. package/src/features/product-assortment/components/ProductAssortmentTable/ProductAssortmentTable.tsx +66 -75
  13. package/src/features/product-assortment/components/ProductAssortmentTable/product-assortment-table.scss +7 -44
  14. package/src/features/product-assortment/components/index.tsx +1 -6
  15. package/src/features/product-assortment/hooks/index.ts +2 -3
  16. package/src/features/product-assortment/hooks/useGetProductAssortment.ts +1 -8
  17. package/src/features/product-assortment/hooks/useGetProductAssortmentFromContract.ts +1 -1
  18. package/src/features/product-assortment/hooks/useSetAssortment.ts +20 -0
  19. package/src/features/product-assortment/layouts/ProductAssortmentLayout/ProductAssortmentLayout.tsx +28 -255
  20. package/src/features/product-assortment/layouts/ProductAssortmentLayout/product-assortment-layout.scss +22 -73
  21. package/src/features/product-assortment/services/get-product-assortment-attached.service.ts +2 -5
  22. package/src/features/product-assortment/services/get-product-assortment-from-contract.service.ts +2 -5
  23. package/src/features/product-assortment/services/set-assortment.service.ts +12 -0
  24. package/src/features/product-assortment/types/index.ts +3 -1
  25. package/src/features/shared/hooks/index.ts +1 -0
  26. package/src/features/shared/hooks/useUrlPaginatedSearch.ts +79 -0
  27. package/src/features/shared/utils/constants.ts +1 -1
  28. package/src/features/shared/utils/getContractSettingsLinks.ts +1 -1
  29. package/src/pages/addresses.tsx +16 -62
  30. package/src/features/addresses/hooks/useSearchAddressByUnitId.ts +0 -27
  31. package/src/features/product-assortment/hooks/useAddProductAssortmentToScope.ts +0 -25
  32. package/src/features/product-assortment/hooks/useGetProductAssortments.ts +0 -35
  33. package/src/features/product-assortment/hooks/useRemoveProductAssortmentFromScope.ts +0 -26
  34. package/src/features/product-assortment/services/add-product-assortment-to-scope.service.ts +0 -16
  35. package/src/features/product-assortment/services/get-product-assortment-from-scope.service.ts +0 -33
  36. package/src/features/product-assortment/services/remove-product-assortment-from-scope.ts +0 -9
package/.prettierrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "trailingComma": "es5"
3
+ }
package/CHANGELOG.md CHANGED
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.3.78] - 2026-04-23
11
+
12
+ ### Changed
13
+ - Move addresses list requests from server to client side
14
+
15
+ ### Fixed
16
+ - Remove `for` loop from `AddressesClient.getAddressesByUnitId` to prevent failed requests
17
+
18
+ ## [1.3.77] - 2026-04-14
19
+
20
+ ### Changed
21
+
22
+ - Redesign Assortments page with radio button selection replacing add/remove/settings drawers
23
+ - Migrate assortments data fetching from `/collections/attached` to new `/assortments` endpoint
24
+ - Rename sidebar link from "Product assortment" to "Assortments"
25
+
26
+ ### Added
27
+
28
+ - Add `setAssortment` mutation (POST `/assortment`) with optimistic UI update
29
+
30
+ ### Removed
31
+
32
+ - Remove Add Product Assortment, Remove Product Assortment, and Collections Settings drawers from Assortments page
33
+
10
34
  ## [1.3.76] - 2026-04-07
11
35
 
12
36
  ### Added
@@ -557,7 +581,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
557
581
  - Add CHANGELOG file
558
582
  - Add README file
559
583
 
560
- [unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.76...HEAD
584
+ [unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.78...HEAD
561
585
  [1.3.55]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.54...v1.3.55
562
586
  [1.3.54]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.53...v1.3.54
563
587
  [1.3.53]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.52...v1.3.53
@@ -625,6 +649,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
625
649
  [1.3.65]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.64...v1.3.65
626
650
  [1.3.64]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.3.64
627
651
  [1.3.69]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.3.69
652
+ [1.3.78]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.77...v1.3.78
653
+ [1.3.77]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.76...v1.3.77
628
654
  [1.3.76]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.75...v1.3.76
629
655
  [1.3.75]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.74...v1.3.75
630
656
  [1.3.74]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.73...v1.3.74
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "1.3.76",
3
+ "version": "1.3.78",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,32 +32,14 @@ export default class AddressesClient extends Client {
32
32
  addressType,
33
33
  page = 1,
34
34
  }: GetAddressesByUnitIdParams) {
35
- let allAddresses: AddressData[] = [];
36
- let total = 0;
37
-
38
- for (let currentPage = 1; currentPage <= page; currentPage++) {
39
- const params = new URLSearchParams();
40
- if (name) params.append("name", name);
41
- if (currentPage > 1) params.append("page", String(currentPage));
42
- if (addressType) params.append("addressType", addressType);
43
- const queryString = params.toString();
44
- const url = queryString
45
- ? `units/${orgUnitId}/addresses?${queryString}`
46
- : `units/${orgUnitId}/addresses`;
47
-
48
- const response = await this.get<AddressResponse>(url, {
49
- headers: {
50
- Cookie: cookie,
51
- },
52
- });
53
-
54
- if (response?.addresses) {
55
- allAddresses = allAddresses.concat(response.addresses);
56
- total = response.total;
57
- }
58
- }
59
-
60
- return { addresses: allAddresses, total };
35
+ return this.get<AddressResponse>(`units/${orgUnitId}/addresses`, {
36
+ headers: { Cookie: cookie },
37
+ params: {
38
+ page,
39
+ name: name ?? "",
40
+ addressType: addressType ?? "",
41
+ },
42
+ });
61
43
  }
62
44
 
63
45
  getAddressById(
@@ -8,3 +8,4 @@ export * from "./useAddressLocationDelete";
8
8
  export * from "./useSetDefaultAddress";
9
9
  export * from "./useUnsetDefaultAddress";
10
10
  export * from "./useGetDefaultAddresses";
11
+ export * from "./useListAddresses";
@@ -1,7 +1,7 @@
1
1
  import { useDebounce } from "../../shared/hooks";
2
2
  import { DEBOUNCE_TIMEOUT } from "../../shared/utils/constants";
3
3
 
4
- import { useSearchAddressByUnitId } from "./useSearchAddressByUnitId";
4
+ import { useListAddresses } from "./useListAddresses";
5
5
 
6
6
  import type { AddressData } from "../types";
7
7
  import type { UseDebouncedSearchAddressByUnitIdProps } from "../types/AddressData";
@@ -12,12 +12,11 @@ export const useDebouncedSearchAddressByUnitId = ({
12
12
  addressType,
13
13
  }: UseDebouncedSearchAddressByUnitIdProps) => {
14
14
  const debouncedSearchTerm = useDebounce(search, DEBOUNCE_TIMEOUT);
15
- const { searchedAddresses, isSearchedAddressesLoading } =
16
- useSearchAddressByUnitId({
17
- orgUnitId,
18
- search: debouncedSearchTerm,
19
- addressType,
20
- });
15
+ const { listAddressesData, listAddressesLoading } = useListAddresses({
16
+ orgUnitId,
17
+ search: debouncedSearchTerm,
18
+ addressType,
19
+ });
21
20
 
22
21
  if (search === "") {
23
22
  return {
@@ -27,7 +26,7 @@ export const useDebouncedSearchAddressByUnitId = ({
27
26
  }
28
27
 
29
28
  return {
30
- searchedAddresses: searchedAddresses?.data ?? [],
31
- isDebouncedSearchAddressesLoading: isSearchedAddressesLoading,
29
+ searchedAddresses: listAddressesData?.data ?? [],
30
+ isDebouncedSearchAddressesLoading: listAddressesLoading,
32
31
  };
33
32
  };
@@ -0,0 +1,36 @@
1
+ import { type QueryOptions, useQuery } from "../../shared/hooks";
2
+ import { getAddressesByUnitIdService } from "../services";
3
+
4
+ type UseListAddressesProps = {
5
+ orgUnitId: string;
6
+ search: string;
7
+ page?: number;
8
+ addressType?: string;
9
+ };
10
+
11
+ export const useListAddresses = (
12
+ { orgUnitId, search, page = 1, addressType }: UseListAddressesProps,
13
+ options?: QueryOptions<AwaitedType<typeof getAddressesByUnitIdService>>
14
+ ) => {
15
+ const { data, error, isLoading, refetch } = useQuery(
16
+ `api/addresses/unitId=${orgUnitId}/page=${page}/search=${
17
+ search ?? ""
18
+ }/addressType=${addressType ?? ""}`,
19
+ ({ cookie }) =>
20
+ getAddressesByUnitIdService({
21
+ orgUnitId,
22
+ search,
23
+ cookie,
24
+ addressType,
25
+ page,
26
+ }),
27
+ options
28
+ );
29
+
30
+ return {
31
+ listAddressesData: data,
32
+ listAddressesError: error,
33
+ listAddressesLoading: isLoading,
34
+ listAddressesRefresh: refetch,
35
+ };
36
+ };
@@ -3,85 +3,42 @@ import { useEffect } from "react";
3
3
  import { useRouter } from "next/router";
4
4
 
5
5
  import {
6
+ EmptyState,
6
7
  HeaderInside,
7
8
  IconBookmarked,
8
9
  InternalSearch,
9
10
  Paginator,
11
+ Table,
10
12
  } from "../../../shared/components";
11
- import { EmptyState } from "../../../shared/components/EmptyState/EmptyState";
12
- import { Table } from "../../../shared/components/Table/Table";
13
13
  import { getTableColumns } from "../../../shared/components/Table/utils/tableColumns";
14
14
  import {
15
15
  useBuyerPortal,
16
16
  useDrawerProps,
17
17
  useGetScopeConfig,
18
+ useUrlPaginatedSearch,
18
19
  SCOPE_KEYS,
19
20
  } from "../../../shared/hooks";
20
- import { usePageItems } from "../../../shared/hooks/usePageItems";
21
21
  import { ContractTabsLayout, GlobalLayout } from "../../../shared/layouts";
22
22
  import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
23
23
  import { AddressDropdownMenu, CreateAddressDrawer } from "../../components";
24
24
  import { CreateAddressSettingsDrawer } from "../../components/CreateAddressSettingsDrawer/CreateAddressSettingsDrawer";
25
- import { useSearchAddressByUnitId } from "../../hooks/useSearchAddressByUnitId";
25
+ import { useListAddresses } from "../../hooks/useListAddresses";
26
26
 
27
- import type { AddressData } from "../../types";
27
+ const PAGE_SIZE = 25;
28
28
 
29
- export type AddressLayoutProps = {
30
- addresses: AddressData[];
31
- total: number;
32
- search: string;
33
- page: number;
34
- };
35
-
36
- export const AddressLayout = ({
37
- addresses: initialAddresses,
38
- search,
39
- total,
40
- page,
41
- }: AddressLayoutProps) => {
29
+ export const AddressLayout = () => {
42
30
  const router = useRouter();
43
31
 
44
32
  const {
45
- isLoading,
46
- items: addresses,
47
- searchTerm,
48
- setSearchTerm,
49
- increasePage,
50
- updateItemsFromRefetch,
51
- setIsLoading,
52
- } = usePageItems<AddressData>({
53
- initialItems: initialAddresses,
54
- search,
55
33
  page,
56
- });
57
-
58
- const { searchedAddresses: addressesData, refetchSearchedAddresses } =
59
- useSearchAddressByUnitId(
60
- {
61
- orgUnitId: router.query.orgUnitId as string,
62
- search: search ?? "",
63
- },
64
- { lazy: true }
65
- );
66
-
67
- useEffect(() => {
68
- if (addresses.length === 0) {
69
- setIsLoading(true);
70
- refetchSearchedAddresses();
71
- }
72
- }, []);
73
-
74
- useEffect(() => {
75
- if (addressesData?.data) {
76
- updateItemsFromRefetch(addressesData.data);
77
- }
78
- }, [addressesData]);
79
-
80
- const handleRefetchAddresses = () => {
81
- setIsLoading(true);
82
- refetchScopeConfig();
83
- refetchSearchedAddresses();
84
- };
34
+ search,
35
+ committedSearch,
36
+ isRouterSynced,
37
+ setSearch,
38
+ goToPage,
39
+ nextPage,
40
+ previousPage,
41
+ } = useUrlPaginatedSearch();
85
42
 
86
43
  const {
87
44
  open: openCreateDrawer,
@@ -109,6 +66,21 @@ export const AddressLayout = ({
109
66
  }
110
67
  );
111
68
 
69
+ const { listAddressesData, listAddressesLoading, listAddressesRefresh } =
70
+ useListAddresses(
71
+ {
72
+ orgUnitId: (router.query.orgUnitId as string) ?? "",
73
+ page: isRouterSynced ? page : 0,
74
+ search: committedSearch,
75
+ },
76
+ { lazy: !isRouterSynced }
77
+ );
78
+
79
+ const handleRefetchAddresses = () => {
80
+ refetchScopeConfig();
81
+ listAddressesRefresh();
82
+ };
83
+
112
84
  const columns = getTableColumns({
113
85
  nameColumnSize: "18.125rem",
114
86
  actionsLength: 2,
@@ -123,6 +95,23 @@ export const AddressLayout = ({
123
95
  ],
124
96
  });
125
97
 
98
+ const intervalData = {
99
+ page,
100
+ itemsLength: listAddressesData?.data.length ?? 0,
101
+ total: listAddressesData?.total ?? 0,
102
+ isLoading: listAddressesLoading,
103
+ };
104
+
105
+ const totalPages = Math.ceil(intervalData.total / PAGE_SIZE);
106
+
107
+ useEffect(() => {
108
+ if (listAddressesLoading || intervalData.total === 0) return;
109
+
110
+ if (page > totalPages) {
111
+ goToPage(Math.max(totalPages, 1));
112
+ }
113
+ }, [page, totalPages, intervalData.total, listAddressesLoading]);
114
+
126
115
  return (
127
116
  <GlobalLayout>
128
117
  <ContractTabsLayout
@@ -142,103 +131,96 @@ export const AddressLayout = ({
142
131
  <HeaderInside.Button onClick={openCreateDrawer} />
143
132
  </HeaderInside>
144
133
 
145
- {addresses.length === 0 && !isLoading && searchTerm.length === 0 ? (
146
- <EmptyState title="No addresses yet" iconName="LocalPostOffice" />
134
+ <div data-fs-buyer-portal-address-filter>
135
+ <InternalSearch defaultValue={search} textSearch={setSearch} />
136
+ <Paginator.Interval {...intervalData} />
137
+ </div>
138
+
139
+ {!listAddressesLoading && intervalData.total === 0 ? (
140
+ <EmptyState
141
+ title={
142
+ committedSearch.length > 0
143
+ ? "No results found"
144
+ : "No addresses yet"
145
+ }
146
+ description={
147
+ committedSearch.length > 0
148
+ ? "Try using different terms or filters"
149
+ : undefined
150
+ }
151
+ iconName={
152
+ committedSearch.length > 0 ? undefined : "LocalPostOffice"
153
+ }
154
+ />
147
155
  ) : (
148
- <>
149
- <div data-fs-buyer-portal-address-filter>
150
- <InternalSearch
151
- defaultValue={searchTerm}
152
- textSearch={setSearchTerm}
153
- />
154
- <div data-fs-bp-top-counter>
155
- <Paginator.Counter
156
- total={total}
157
- itemsLength={addresses.length}
158
- />
159
- </div>
160
- </div>
161
- {!isLoading && addresses.length === 0 && searchTerm.length > 0 ? (
162
- <EmptyState
163
- title="No results found"
164
- description="Try using different terms or filters"
165
- />
166
- ) : (
167
- <div data-fs-addresses-table>
168
- <Table layoutFixed>
169
- <Table.Head columns={columns} />
170
-
171
- <Table.Body>
172
- {isLoading ? (
173
- <Table.Loading columns={columns.length} />
174
- ) : (
175
- addresses.map(({ id, ...address }) => (
176
- <Table.Row
177
- key={id}
178
- title={address.name}
179
- searchTerm={search}
180
- iconName="LocalPostOffice"
181
- iconSize={20}
182
- children={
183
- <Table.Cell hideOnScreenSize="phonemid">
184
- {Array.isArray(address.types) &&
185
- address.types.length > 0 ? (
186
- <span>{address.types.join(", ")}</span>
187
- ) : null}
188
- </Table.Cell>
189
- }
190
- href={buyerPortalRoutes.addressDetails({
191
- orgUnitId: orgUnit?.id ?? "",
192
- contractId: contract?.id ?? "",
193
- addressId: id,
194
- })}
195
- actionIcons={
196
- address.isDefault ? <IconBookmarked /> : null
197
- }
198
- dropdownMenu={
199
- <AddressDropdownMenu
200
- currentAddress={{
201
- id,
202
- ...address,
203
- }}
204
- isSyncMode={isSyncMode}
205
- onUpdate={handleRefetchAddresses}
206
- onOpen={() => {
207
- const url = buyerPortalRoutes.addressDetails({
208
- orgUnitId: orgUnit?.id ?? "",
209
- contractId: contract?.id ?? "",
210
- addressId: id,
211
- });
212
-
213
- router.push(url);
214
- }}
215
- />
216
- }
156
+ <div data-fs-addresses-table>
157
+ <Table layoutFixed>
158
+ <Table.Head columns={columns} />
159
+ <Table.Body>
160
+ {listAddressesLoading ? (
161
+ <Table.Loading columns={columns.length} />
162
+ ) : (
163
+ listAddressesData?.data.map(({ id, ...address }) => (
164
+ <Table.Row
165
+ key={id}
166
+ title={address.name}
167
+ searchTerm={committedSearch}
168
+ iconName="LocalPostOffice"
169
+ iconSize={20}
170
+ href={buyerPortalRoutes.addressDetails({
171
+ orgUnitId: orgUnit?.id ?? "",
172
+ contractId: contract?.id ?? "",
173
+ addressId: id,
174
+ })}
175
+ actionIcons={
176
+ address.isDefault ? <IconBookmarked /> : null
177
+ }
178
+ dropdownMenu={
179
+ <AddressDropdownMenu
180
+ currentAddress={{ id, ...address }}
181
+ isSyncMode={isSyncMode}
182
+ onUpdate={handleRefetchAddresses}
183
+ onOpen={() => {
184
+ const url = buyerPortalRoutes.addressDetails({
185
+ orgUnitId: orgUnit?.id ?? "",
186
+ contractId: contract?.id ?? "",
187
+ addressId: id,
188
+ });
189
+
190
+ router.push(url);
191
+ }}
217
192
  />
218
- ))
219
- )}
220
- </Table.Body>
221
- </Table>
222
-
223
- {!isLoading && (
224
- <p
225
- data-fs-bp-addresses-paginator-last
226
- >{`${addresses.length} of ${total}`}</p>
227
- )}
228
-
229
- <div data-fs-bp-addresses-paginator>
230
- {total > addresses.length && (
231
- <Paginator.NextPageButton
232
- onClick={increasePage}
233
- disabled={isLoading}
193
+ }
234
194
  >
235
- {isLoading ? "Loading" : "Load More"}
236
- </Paginator.NextPageButton>
237
- )}
238
- </div>
239
- </div>
240
- )}
241
- </>
195
+ <Table.Cell hideOnScreenSize="phonemid">
196
+ {Array.isArray(address.types) &&
197
+ address.types.length > 0 ? (
198
+ <span>{address.types.join(", ")}</span>
199
+ ) : null}
200
+ </Table.Cell>
201
+ </Table.Row>
202
+ ))
203
+ )}
204
+ </Table.Body>
205
+ </Table>
206
+
207
+ <div data-fs-bp-addresses-paginator>
208
+ <Paginator.NextPageButton
209
+ onClick={previousPage}
210
+ disabled={page <= 1}
211
+ >
212
+ Previous Page
213
+ </Paginator.NextPageButton>
214
+ <Paginator.NextPageButton
215
+ data-fs-bp-addresses-next-page
216
+ onClick={nextPage}
217
+ disabled={page >= totalPages}
218
+ >
219
+ Next Page
220
+ </Paginator.NextPageButton>
221
+ <Paginator.Interval {...intervalData} />
222
+ </div>
223
+ </div>
242
224
  )}
243
225
 
244
226
  {isCreateAddressDrawerOpen && (
@@ -146,8 +146,23 @@
146
146
  display: flex;
147
147
  align-items: center;
148
148
  justify-content: flex-start;
149
- margin-top: var(--fs-spacing-2);
150
- padding: var(--fs-spacing-2) 0;
149
+ margin-top: var(--fs-bp-margin-3);
150
+ padding: var(--fs-bp-padding-3) 0;
151
+ gap: var(--fs-bp-gap-4);
152
+
153
+ [data-fs-bp-paginator-counter] {
154
+ margin-left: var(--fs-bp-margin-auto)
155
+ }
156
+
157
+ [data-fs-paginator-next-page-button]:disabled {
158
+ cursor: not-allowed;
159
+ color: var(--fs-bp-color-neutral-6);
160
+
161
+ &:hover {
162
+ color: var(--fs-bp-color-neutral-6);
163
+ background-color: transparent;
164
+ }
165
+ }
151
166
 
152
167
  @include media("<=phonemid") {
153
168
  padding: var(--fs-spacing-3) 0;
@@ -2,7 +2,4 @@ export {
2
2
  AddressDetailsLayout,
3
3
  type AddressDetailsLayoutProps,
4
4
  } from "./AddressDetailsLayout/AddressDetailsLayout";
5
- export {
6
- AddressLayout,
7
- type AddressLayoutProps,
8
- } from "./AddressesLayout/AddressesLayout";
5
+ export { AddressLayout } from "./AddressesLayout/AddressesLayout";
@@ -2,9 +2,8 @@ import { Client } from "../../shared/clients/Client";
2
2
  import { getApiUrl } from "../../shared/utils";
3
3
 
4
4
  import type {
5
- AddProductAssortmentPayload,
6
- AddProductAssortmentResponse,
7
5
  GetProductAssortmentFromContractResponse,
6
+ SetAssortmentPayload,
8
7
  } from "../types";
9
8
 
10
9
  type DefaultArgs = {
@@ -18,72 +17,35 @@ export class ProductAssortmentClient extends Client {
18
17
  super(getApiUrl());
19
18
  }
20
19
 
21
- getProductAssortmentsInfoInContract(
22
- args: DefaultArgs & { name?: string; page?: number }
23
- ) {
24
- const { contractId, cookie, name, unitId, page } = args;
25
-
26
- return this.get<GetProductAssortmentFromContractResponse>(
27
- `customers/${contractId}/units/${unitId}/collections/attached`,
28
- {
29
- headers: { Cookie: cookie },
30
- params: {
31
- ...(name ? { name } : undefined),
32
- ...(page ? { page } : undefined),
33
- },
34
- }
35
- );
36
- }
37
-
38
- getProductAssortmentListInScope(
20
+ getAssortments(
39
21
  args: DefaultArgs & {
40
- unitId: string;
41
22
  name?: string;
42
- page: number;
43
23
  }
44
24
  ) {
45
- const { contractId, cookie, name, unitId, page } = args;
25
+ const { contractId, cookie, name, unitId } = args;
46
26
 
47
27
  return this.get<GetProductAssortmentFromContractResponse>(
48
- `customers/${contractId}/units/${unitId}/collections/available`,
28
+ `customers/${contractId}/units/${unitId}/assortments/available`,
49
29
  {
50
30
  headers: { Cookie: cookie },
51
31
  params: {
52
32
  ...(name ? { name } : undefined),
53
- page,
54
- v: new Date().getTime(),
55
33
  },
56
34
  }
57
35
  );
58
36
  }
59
37
 
60
- addProductAssortmentToScope(
61
- args: DefaultArgs & { unitId: string; data: AddProductAssortmentPayload }
62
- ) {
38
+ setAssortment(args: DefaultArgs & { data: SetAssortmentPayload }) {
63
39
  const { contractId, cookie, unitId, data } = args;
64
40
 
65
- return this.post<AddProductAssortmentResponse, AddProductAssortmentPayload>(
66
- `/customers/${contractId}/units/${unitId}/collections`,
41
+ return this.put<void, SetAssortmentPayload>(
42
+ `customers/${contractId}/units/${unitId}/assortments`,
67
43
  data,
68
44
  {
69
45
  headers: { Cookie: cookie },
70
46
  }
71
47
  );
72
48
  }
73
-
74
- removeProductAssortmentFromScope(
75
- args: DefaultArgs & { unitId: string; productAssortmentId: string }
76
- ) {
77
- const { contractId, unitId, cookie, productAssortmentId } = args;
78
-
79
- return this.delete(
80
- `/customers/${contractId}/units/${unitId}/collections/${productAssortmentId}`,
81
- undefined,
82
- {
83
- headers: { Cookie: cookie },
84
- }
85
- );
86
- }
87
49
  }
88
50
 
89
51
  const productAssortmentClient = new ProductAssortmentClient();