@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 +1 -1
- package/src/features/org-units/clients/OrgUnitClient.ts +11 -7
- package/src/features/org-units/hooks/useSearchOrgUnits.ts +6 -1
- package/src/features/org-units/services/index.ts +1 -4
- package/src/features/org-units/services/search-org-units-by-name.service.ts +7 -12
- package/src/features/org-units/types/OrgUnitSearch.tsx +12 -0
- package/src/features/org-units/types/index.ts +4 -0
- package/src/features/users/hooks/useDebouncedSearchOrgUnit.ts +3 -2
- package/src/pages/org-units.tsx +7 -3
package/package.json
CHANGED
|
@@ -4,7 +4,8 @@ import { getApiUrl } from "../../shared/utils";
|
|
|
4
4
|
import type {
|
|
5
5
|
OrgUnitBasicData,
|
|
6
6
|
OrgUnitSummaryData,
|
|
7
|
-
|
|
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(
|
|
118
|
-
return this.get<
|
|
119
|
-
|
|
120
|
-
|
|
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 }) =>
|
|
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 {
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
)
|
|
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(
|
|
15
|
+
const orgUnits = await orgUnitClient.searchOrgUnitsByName(params);
|
|
21
16
|
|
|
22
17
|
return {
|
|
23
|
-
organizationalUnits: orgUnits,
|
|
24
|
-
total: orgUnits?.
|
|
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
|
+
};
|
|
@@ -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 } =
|
|
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:
|
|
22
|
+
isDebouncedSearchOrgUnitLoading: isSearchedOrgUnitsLoading,
|
|
22
23
|
};
|
|
23
24
|
};
|
package/src/pages/org-units.tsx
CHANGED
|
@@ -11,13 +11,13 @@ import { getUserByIdService } from "../features/users/services";
|
|
|
11
11
|
|
|
12
12
|
import type {
|
|
13
13
|
OrgUnitBasicData,
|
|
14
|
-
|
|
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:
|
|
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({
|
|
58
|
+
data: await searchOrgUnitsByNameService({
|
|
59
|
+
name: search,
|
|
60
|
+
contractId: customerId,
|
|
61
|
+
cookie,
|
|
62
|
+
}),
|
|
59
63
|
search,
|
|
60
64
|
context: {
|
|
61
65
|
clientContext,
|