@vtex/faststore-plugin-buyer-portal 1.1.69 → 1.1.71

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "1.1.69",
3
+ "version": "1.1.71",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4,7 +4,8 @@ import { getApiUrl } from "../../shared/utils";
4
4
  import type {
5
5
  OrgUnitBasicData,
6
6
  OrgUnitSummaryData,
7
- OrgUnitData,
7
+ OrgUnitSearchParams,
8
+ OrgUnitSearchResponse,
8
9
  } from "../types";
9
10
 
10
11
  export class OrgUnitClient extends Client {
@@ -114,12 +115,15 @@ export class OrgUnitClient extends Client {
114
115
  });
115
116
  }
116
117
 
117
- searchOrgUnitsByName(name: string, cookie: string) {
118
- return this.get<OrgUnitData[]>(`units?name=${name}`, {
119
- headers: {
120
- Cookie: cookie,
121
- },
122
- });
118
+ searchOrgUnitsByName({ cookie, name, contractId }: OrgUnitSearchParams) {
119
+ return this.get<OrgUnitSearchResponse>(
120
+ `customers/${contractId}/units?name=${name}`,
121
+ {
122
+ headers: {
123
+ Cookie: cookie,
124
+ },
125
+ }
126
+ );
123
127
  }
124
128
  }
125
129
 
@@ -7,7 +7,12 @@ export const useSearchOrgUnits = (
7
7
  ) => {
8
8
  const { data, error, isLoading, refetch } = useQuery(
9
9
  `api/search-org-unit/${name}`,
10
- ({ cookie }) => searchOrgUnitsByNameService({ name }, cookie),
10
+ ({ cookie, customerId }) =>
11
+ searchOrgUnitsByNameService({
12
+ name,
13
+ contractId: customerId,
14
+ cookie,
15
+ }),
11
16
  options
12
17
  );
13
18
  return {
@@ -18,7 +18,4 @@ export {
18
18
  updateOrgUnitService,
19
19
  } from "./update-org-unit.service";
20
20
  export { getOrgUnitByUserIdService } from "./get-org-unit-by-user-id.service";
21
- export {
22
- type searchOrgUnitsByNameServiceProps,
23
- searchOrgUnitsByNameService,
24
- } from "./search-org-units-by-name.service";
21
+ export { searchOrgUnitsByNameService } from "./search-org-units-by-name.service";
@@ -1,26 +1,21 @@
1
1
  import { orgUnitClient } from "../clients/OrgUnitClient";
2
2
 
3
- import type { OrgUnitData } from "../types";
4
-
5
- export type searchOrgUnitsByNameServiceProps = {
6
- name: string;
7
- };
3
+ import type { OrgUnitSearchParams, OrgUnitSearchResponse } from "../types";
8
4
 
9
5
  export const searchOrgUnitsByNameService = async (
10
- { name }: searchOrgUnitsByNameServiceProps,
11
- cookie: string
12
- ): Promise<{ organizationalUnits: OrgUnitData[]; total: number }> => {
13
- if (!name) {
6
+ params: OrgUnitSearchParams
7
+ ): Promise<OrgUnitSearchResponse> => {
8
+ if (!params.name) {
14
9
  return {
15
10
  organizationalUnits: [],
16
11
  total: 0,
17
12
  };
18
13
  }
19
14
 
20
- const orgUnits = await orgUnitClient.searchOrgUnitsByName(name, cookie);
15
+ const orgUnits = await orgUnitClient.searchOrgUnitsByName(params);
21
16
 
22
17
  return {
23
- organizationalUnits: orgUnits,
24
- total: orgUnits?.length || 0,
18
+ organizationalUnits: orgUnits?.organizationalUnits || [],
19
+ total: orgUnits?.total || 0,
25
20
  };
26
21
  };
@@ -0,0 +1,12 @@
1
+ import type { OrgUnitData } from "./OrgUnitsData";
2
+
3
+ export type OrgUnitSearchParams = {
4
+ cookie: string;
5
+ name?: string;
6
+ contractId: string;
7
+ };
8
+
9
+ export type OrgUnitSearchResponse = {
10
+ organizationalUnits: OrgUnitData[];
11
+ total: number;
12
+ };
@@ -10,3 +10,7 @@ export type {
10
10
  OrgUnitBreadcrumbItemProps,
11
11
  OrgUnitBreadcrumbPathProps,
12
12
  } from "./OrgUnitBreadcrumbTypes";
13
+ export type {
14
+ OrgUnitSearchParams,
15
+ OrgUnitSearchResponse,
16
+ } from "./OrgUnitSearch";
@@ -4,7 +4,8 @@ import { DEBOUNCE_TIMEOUT } from "../../shared/utils";
4
4
 
5
5
  export const useDebouncedSearchOrgUnit = (searchTerm = "") => {
6
6
  const debouncedSearchTerm = useDebounce(searchTerm, DEBOUNCE_TIMEOUT);
7
- const { searchedOrgUnits } = useSearchOrgUnits(debouncedSearchTerm);
7
+ const { searchedOrgUnits, isSearchedOrgUnitsLoading } =
8
+ useSearchOrgUnits(debouncedSearchTerm);
8
9
 
9
10
  if (searchTerm === "") {
10
11
  return {
@@ -18,6 +19,6 @@ export const useDebouncedSearchOrgUnit = (searchTerm = "") => {
18
19
 
19
20
  return {
20
21
  searchedOrgUnits: searchedOrgUnits?.organizationalUnits ?? [],
21
- isDebouncedSearchOrgUnitLoading: false,
22
+ isDebouncedSearchOrgUnitLoading: isSearchedOrgUnitsLoading,
22
23
  };
23
24
  };
@@ -11,13 +11,13 @@ import { getUserByIdService } from "../features/users/services";
11
11
 
12
12
  import type {
13
13
  OrgUnitBasicData,
14
- OrgUnitData,
14
+ OrgUnitSearchResponse,
15
15
  } from "../features/org-units/types";
16
16
  import type { LoaderData } from "../features/shared/types";
17
17
  import type { UserData } from "../features/users/types";
18
18
 
19
19
  export type OrgUnitsPageData = {
20
- data: { organizationalUnits: OrgUnitData[]; total: number };
20
+ data: OrgUnitSearchResponse;
21
21
  search: string;
22
22
  context: {
23
23
  clientContext: ClientContext;
@@ -55,7 +55,11 @@ export async function loader(
55
55
 
56
56
  if (search) {
57
57
  return {
58
- data: await searchOrgUnitsByNameService({ name: search }, cookie),
58
+ data: await searchOrgUnitsByNameService({
59
+ name: search,
60
+ contractId: customerId,
61
+ cookie,
62
+ }),
59
63
  search,
60
64
  context: {
61
65
  clientContext,