@vtex/faststore-plugin-buyer-portal 1.0.30 → 1.0.32

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 (54) hide show
  1. package/package.json +1 -1
  2. package/plugin.config.js +11 -10
  3. package/src/features/addresses/clients/AddressesClient.ts +21 -0
  4. package/src/features/addresses/services/get-addresses.service.ts +2 -2
  5. package/src/features/contracts/clients/ContractsClient.ts +78 -0
  6. package/src/features/contracts/components/ContractsCard/ContractsCard.tsx +1 -1
  7. package/src/features/contracts/services/get-contract-details.service.ts +2 -2
  8. package/src/features/contracts/services/get-contracts-by-customer-id.service.ts +2 -2
  9. package/src/features/contracts/services/get-contracts-org-by-unit-id.service.ts +2 -5
  10. package/src/features/contracts/services/update-contract-status.service.ts +2 -2
  11. package/src/features/org-units/clients/OrgUnitClient.ts +141 -0
  12. package/src/features/org-units/components/CreateOrgUnitDrawer/CreateOrgUnitDrawer.tsx +17 -2
  13. package/src/features/org-units/components/DeleteOrgUnitDrawer/DeleteOrgUnitDrawer.tsx +1 -1
  14. package/src/features/org-units/components/OrgUnitsDropdownMenu/OrgUnitsDropdownMenu.tsx +4 -2
  15. package/src/features/org-units/components/OrgUnitsHierarchyTree/OrgUnitsHierarchyTree.tsx +24 -16
  16. package/src/features/org-units/components/OrganizationalUnitsCard/OrganizationalUnitsCard.tsx +1 -1
  17. package/src/features/org-units/hooks/useChildrenOrgUnits.ts +2 -1
  18. package/src/features/org-units/layouts/OrgUnitDetailsLayout/OrgUnitDetailsLayout.tsx +9 -13
  19. package/src/features/org-units/layouts/OrgUnitsLayout/OrgUnitsLayout.tsx +11 -3
  20. package/src/features/org-units/services/create-new-org-unit.service.ts +2 -2
  21. package/src/features/org-units/services/delete-org-unit.service.ts +2 -2
  22. package/src/features/org-units/services/get-children-org-units.service.ts +15 -12
  23. package/src/features/org-units/services/get-org-unit-basic-data.service.ts +3 -3
  24. package/src/features/org-units/services/get-org-unit-by-id.service.ts +11 -22
  25. package/src/features/org-units/services/get-org-unit-by-user-id.service.ts +16 -0
  26. package/src/features/org-units/services/get-org-unit-summary.service.ts +2 -2
  27. package/src/features/org-units/services/get-root-org-unit-by-customer-id.service.ts +2 -2
  28. package/src/features/org-units/services/index.ts +6 -1
  29. package/src/features/org-units/services/search-org-units-by-name.service.ts +18 -0
  30. package/src/features/org-units/services/update-org-unit.service.ts +2 -2
  31. package/src/features/org-units/types/OrgUnitSummaryData.ts +4 -0
  32. package/src/features/org-units/types/OrgUnitsData.ts +1 -1
  33. package/src/{clients → features/shared/clients}/Client.ts +4 -3
  34. package/src/features/shared/components/BuyerPortalProvider/BuyerPortalProvider.tsx +5 -1
  35. package/src/features/shared/components/InternalSearch/InternalSearch.tsx +3 -1
  36. package/src/features/shared/components/InternalTopbar/InternalTopbar.tsx +2 -2
  37. package/src/features/shared/components/MainLinksDropdownMenu/MainLinksDropdownMenu.tsx +3 -3
  38. package/src/features/shared/hooks/useBuyerPortal.ts +2 -2
  39. package/src/features/shared/hooks/useMutation.ts +1 -1
  40. package/src/features/shared/hooks/useQuery.ts +1 -1
  41. package/src/features/shared/types/LoaderData.ts +4 -0
  42. package/src/features/shared/utils/getClientContext.ts +2 -13
  43. package/src/features/users/components/UsersCard/UsersCard.tsx +7 -7
  44. package/src/features/users/types/UserSummary.ts +4 -0
  45. package/src/features/users/types/index.ts +1 -0
  46. package/src/pages/addresses.tsx +21 -5
  47. package/src/pages/contracts.tsx +30 -13
  48. package/src/pages/home.tsx +24 -18
  49. package/src/pages/org-unit-details.tsx +17 -2
  50. package/src/pages/org-units.tsx +79 -12
  51. package/src/pages/profile.tsx +7 -21
  52. package/src/pages/user-details.tsx +1 -0
  53. package/src/pages/users.tsx +23 -15
  54. package/src/clients/BuyerPortalClient.ts +0 -181
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "dependencies": {
package/plugin.config.js CHANGED
@@ -17,26 +17,27 @@ module.exports = {
17
17
  path: "/user/[userId]",
18
18
  appLayout: false,
19
19
  },
20
- profile: {
21
- path: "/profile/[[...contractId]]",
22
- appLayout: false,
23
- },
24
20
 
25
- // Shared pages
26
- "org-units": {
27
- path: "/org-units/[[...orgUnitId]]",
21
+ // ----
22
+ profile: {
23
+ path: "/profile/[contractId]",
28
24
  appLayout: false,
29
25
  },
30
26
  contracts: {
31
- path: "/contracts/[[...orgUnitId]]",
27
+ path: "/contracts/[orgUnitId]",
32
28
  appLayout: false,
33
29
  },
34
30
  addresses: {
35
- path: "/addresses/[[...orgUnitId]]",
31
+ path: "/addresses/[orgUnitId]",
36
32
  appLayout: false,
37
33
  },
38
34
  users: {
39
- path: "/users/[[...orgUnitId]]",
35
+ path: "/users/[orgUnitId]",
36
+ appLayout: false,
37
+ },
38
+
39
+ "org-units": {
40
+ path: "/org-units/[orgUnitId]",
40
41
  appLayout: false,
41
42
  },
42
43
  },
@@ -0,0 +1,21 @@
1
+ import { Client } from "../../shared/clients/Client";
2
+ import { getApiUrl } from "../../shared/utils";
3
+ import type { AddressData } from "../types";
4
+
5
+ export default class AddressesClient extends Client {
6
+ constructor() {
7
+ super(getApiUrl());
8
+ }
9
+
10
+ getAddressesByCustomerId(customerId: string, cookie: string) {
11
+ return this.get<{ addresses: AddressData[] }>(`addresses/${customerId}`, {
12
+ headers: {
13
+ Cookie: cookie,
14
+ },
15
+ });
16
+ }
17
+ }
18
+
19
+ const addressesClient = new AddressesClient();
20
+
21
+ export { addressesClient };
@@ -1,6 +1,6 @@
1
1
  import type { AddressSummaryData } from "../types/AddressData";
2
- import { buyerPortalClient } from "../../../clients/BuyerPortalClient";
3
2
  import { compareItems, statusFilters } from "../../shared/utils";
3
+ import { addressesClient } from "../clients/AddressesClient";
4
4
 
5
5
  export type GetAddressesServiceProps = Partial<{
6
6
  search: string;
@@ -27,7 +27,7 @@ export const getAddressesService = async ({
27
27
  const addressesData: AddressSummaryData[] = [];
28
28
 
29
29
  try {
30
- const { addresses = [] } = await buyerPortalClient.getAddressesByCustomerId(
30
+ const { addresses = [] } = await addressesClient.getAddressesByCustomerId(
31
31
  customerId,
32
32
  cookie
33
33
  );
@@ -0,0 +1,78 @@
1
+ import { Client } from "../../shared/clients/Client";
2
+ import { getApiUrl } from "../../shared/utils";
3
+ import type { ContractData } from "../types";
4
+
5
+ class ContractsClient extends Client {
6
+ constructor() {
7
+ super(getApiUrl());
8
+ }
9
+
10
+ getContractsByCustomerId(customerId: string, cookie: string) {
11
+ return this.get<{ data: { contracts: ContractData[]; total: number } }>(
12
+ `contracts/${customerId}/list`,
13
+ {
14
+ headers: {
15
+ Cookie: cookie,
16
+ },
17
+ }
18
+ );
19
+ }
20
+
21
+ getContractsByOrgUnitId(orgUnitId: string, cookie: string) {
22
+ return this.get<{ contracts: ContractData[]; total: number }>(
23
+ `contracts/${orgUnitId}`,
24
+ {
25
+ headers: {
26
+ Cookie: cookie,
27
+ },
28
+ }
29
+ );
30
+ }
31
+
32
+ getContractDetails(contractId: string, cookie: string) {
33
+ return this.get<{ contract: ContractData }>(`contract/${contractId}`, {
34
+ headers: {
35
+ Cookie: cookie,
36
+ },
37
+ });
38
+ }
39
+
40
+ getContracts(
41
+ cookie: string,
42
+ params?: {
43
+ salesRepresentative?: string;
44
+ isActive?: boolean;
45
+ page?: number;
46
+ sort?: "Asc" | "Desc";
47
+ }
48
+ ) {
49
+ return this.get<ContractData[]>("contracts/filter", {
50
+ headers: {
51
+ Cookie: cookie,
52
+ },
53
+ params,
54
+ });
55
+ }
56
+
57
+ updateContractStatus(
58
+ data: { contractId: string; isActive: boolean },
59
+ cookie: string
60
+ ) {
61
+ const { contractId, isActive } = data;
62
+
63
+ return this.post<null, { isActive: boolean }>(
64
+ `contracts/status/${contractId}`,
65
+ { isActive },
66
+ {
67
+ headers: {
68
+ Cookie: cookie,
69
+ },
70
+ data: { isActive },
71
+ }
72
+ );
73
+ }
74
+ }
75
+
76
+ const contractsClient = new ContractsClient();
77
+
78
+ export { contractsClient };
@@ -36,7 +36,7 @@ export default function ContractsCard({
36
36
  icon={<Icon name="Info" width={20} height={20} />}
37
37
  onPlusIconClick={() => {}}
38
38
  >
39
- {contracts.length &&
39
+ {!!contracts.length &&
40
40
  contracts.map((contract: ContractData) => {
41
41
  return (
42
42
  <div key={contract.id}>
@@ -1,4 +1,4 @@
1
- import { buyerPortalClient } from "../../../clients/BuyerPortalClient";
1
+ import { contractsClient } from "../clients/ContractsClient";
2
2
 
3
3
  export const getContractDetailsService = async ({
4
4
  contractId,
@@ -7,7 +7,7 @@ export const getContractDetailsService = async ({
7
7
  contractId: string;
8
8
  cookie: string;
9
9
  }) => {
10
- const { contract } = await buyerPortalClient.getContractDetails(
10
+ const { contract } = await contractsClient.getContractDetails(
11
11
  contractId,
12
12
  cookie
13
13
  );
@@ -1,4 +1,4 @@
1
- import { buyerPortalClient } from "../../../clients/BuyerPortalClient";
1
+ import { contractsClient } from "../clients/ContractsClient";
2
2
  import type { ContractData } from "../types";
3
3
 
4
4
  export type GetContractsByCustomerIdServiceProps = {
@@ -25,7 +25,7 @@ export const getContractsByCustomerIdService = async ({
25
25
  try {
26
26
  const {
27
27
  data: { contracts },
28
- } = await buyerPortalClient.getContractsByCustomerId(customerId, cookie);
28
+ } = await contractsClient.getContractsByCustomerId(customerId, cookie);
29
29
 
30
30
  contractsData.push(...contracts);
31
31
  } catch (err) {
@@ -1,5 +1,4 @@
1
- import { buyerPortalClient } from "../../../clients/BuyerPortalClient";
2
- import { compareItems, statusFilters } from "../../shared/utils";
1
+ import { contractsClient } from "../clients/ContractsClient";
3
2
  import type { ContractData } from "../types";
4
3
 
5
4
  export type GetContractsByOrgUnitIdServiceProps = {
@@ -24,7 +23,7 @@ export const getContractsByOrgUnitIdService = async ({
24
23
  }
25
24
 
26
25
  try {
27
- const { contracts } = await buyerPortalClient.getContractsByOrgUnitId(
26
+ const { contracts } = await contractsClient.getContractsByOrgUnitId(
28
27
  orgUnitId,
29
28
  cookie
30
29
  );
@@ -34,7 +33,5 @@ export const getContractsByOrgUnitIdService = async ({
34
33
  return contractsData;
35
34
  }
36
35
 
37
- console.log("Contracts Data: ", contractsData);
38
-
39
36
  return contractsData;
40
37
  };
@@ -1,4 +1,4 @@
1
- import { buyerPortalClient } from "../../../clients/BuyerPortalClient";
1
+ import { contractsClient } from "../clients/ContractsClient";
2
2
 
3
3
  export type UpdateContractStatusServiceProps = {
4
4
  contractId: string;
@@ -12,7 +12,7 @@ export const updateContractStatusService = async ({
12
12
  cookie,
13
13
  }: UpdateContractStatusServiceProps): Promise<null> => {
14
14
  try {
15
- const data = await buyerPortalClient.updateContractStatus(
15
+ const data = await contractsClient.updateContractStatus(
16
16
  { contractId, isActive },
17
17
  cookie
18
18
  );
@@ -0,0 +1,141 @@
1
+ import { Client } from "../../shared/clients/Client";
2
+ import { getApiUrl } from "../../shared/utils";
3
+ import type {
4
+ OrgUnitBasicData,
5
+ OrgUnitSummaryData,
6
+ OrgUnitData,
7
+ } from "../types";
8
+
9
+ export class OrgUnitClient extends Client {
10
+ constructor() {
11
+ super(getApiUrl());
12
+ }
13
+
14
+ getOrgUnitBasicData(id: string, cookie: string) {
15
+ return this.get<OrgUnitBasicData>(`units/${id}`, {
16
+ headers: {
17
+ Cookie: cookie,
18
+ },
19
+ });
20
+ }
21
+
22
+ getOrgUnitSummary(id: string, cookie: string) {
23
+ return this.get<OrgUnitSummaryData>(`units/summary/${id}`, {
24
+ headers: {
25
+ Cookie: cookie,
26
+ },
27
+ });
28
+ }
29
+
30
+ getRootOrgUnitByCustomerId(customerId: string, cookie: string) {
31
+ return this.get<{ organizationalUnits: OrgUnitData[]; total: number }>(
32
+ `units/root/${customerId}`,
33
+ {
34
+ headers: {
35
+ Cookie: cookie,
36
+ },
37
+ }
38
+ );
39
+ }
40
+
41
+ getOrgUnitByUserId(userId: string, cookie: string) {
42
+ return this.get<{
43
+ orgUnit: {
44
+ createdAt: string;
45
+ updatedAt: string;
46
+ name: string;
47
+ path: {
48
+ ids: string;
49
+ names: string;
50
+ };
51
+ id: string;
52
+ customerGroup: {
53
+ customerIds: string[];
54
+ };
55
+ };
56
+ }>(`units/user/${userId}`, {
57
+ headers: {
58
+ Cookie: cookie,
59
+ },
60
+ });
61
+ }
62
+
63
+ createOrgUnit(
64
+ data: { name: string; parentId?: string | null; customerId: string[] },
65
+ cookie: string
66
+ ) {
67
+ const { parentId, ...input } = data;
68
+ return this.post<
69
+ {
70
+ customerIds: string[];
71
+ id: string;
72
+ isActive: boolean;
73
+ name: string;
74
+ parentId: string;
75
+ },
76
+ typeof data
77
+ >(
78
+ "units",
79
+ { ...input, ...(parentId && { parentId }) },
80
+ {
81
+ headers: {
82
+ Cookie: cookie,
83
+ },
84
+ }
85
+ );
86
+ }
87
+
88
+ updateOrgUnit(data: { name?: string; id: string }, cookie: string) {
89
+ const { id, ...input } = data;
90
+ return this.patch<null, typeof input>(`units/${id}`, input, {
91
+ headers: {
92
+ Cookie: cookie,
93
+ },
94
+ });
95
+ }
96
+
97
+ deleteOrgUnit(orgUnitId: string, cookie: string) {
98
+ return this.delete(`units/${orgUnitId}`, {
99
+ headers: {
100
+ Cookie: cookie,
101
+ },
102
+ });
103
+ }
104
+
105
+ getOrgUnitChildren(orgUnitId: string, cookie: string) {
106
+ return this.get<{
107
+ orgUnit: {
108
+ id: string;
109
+ name: string;
110
+ path: {
111
+ ids: string;
112
+ names: string;
113
+ };
114
+ }[];
115
+ }>(`units/children/${orgUnitId}`, {
116
+ headers: {
117
+ Cookie: cookie,
118
+ },
119
+ });
120
+ }
121
+
122
+ searchOrgUnitsByName(name: string, cookie: string) {
123
+ return this.get<{
124
+ orgUnits: {
125
+ id: string;
126
+ name: string;
127
+ path: {
128
+ ids: string;
129
+ names: string;
130
+ };
131
+ }[];
132
+ }>(`search/units?name=${name}`, {
133
+ headers: {
134
+ Cookie: cookie,
135
+ },
136
+ });
137
+ }
138
+ }
139
+
140
+ const orgUnitClient = new OrgUnitClient();
141
+ export { orgUnitClient };
@@ -17,6 +17,7 @@ export type CreateOrgUnitDrawerProps = Omit<BasicDrawerProps, "children"> & {
17
17
  options?: { id: string; name: string }[];
18
18
  initialParentOrgUnit?: { id: string | null; name: string };
19
19
  readonly?: boolean;
20
+ onCreate?: () => void;
20
21
  };
21
22
 
22
23
  export const CreateOrgUnitDrawer = ({
@@ -24,6 +25,7 @@ export const CreateOrgUnitDrawer = ({
24
25
  options = [],
25
26
  initialParentOrgUnit: initialOrgUnit,
26
27
  readonly,
28
+ onCreate,
27
29
  ...props
28
30
  }: CreateOrgUnitDrawerProps) => {
29
31
  const { pushToast } = useUI();
@@ -52,13 +54,26 @@ export const CreateOrgUnitDrawer = ({
52
54
  </button>
53
55
  ),
54
56
  });
57
+ onCreate?.();
55
58
  close();
56
- router.replace(router.asPath);
57
59
  };
58
60
 
59
61
  const { createNewOrgUnit, isCreateNewOrgUnitLoading } = useCreateNewOrgUnit({
60
62
  onSuccess: handleCreateNewOrgUnitSuccess,
61
- onError: () => {
63
+ onError: (err) => {
64
+ const error = JSON.parse(err.message) as {
65
+ code: string;
66
+ description: string;
67
+ };
68
+
69
+ if (error.code === "InvalidOrganizationUnitName") {
70
+ pushToast({
71
+ message: "An organizational unit with the same name already exists",
72
+ status: "ERROR",
73
+ });
74
+ return;
75
+ }
76
+
62
77
  pushToast({
63
78
  message: "An error occurred while creating the organizational unit",
64
79
  status: "ERROR",
@@ -28,7 +28,7 @@ export const DeleteOrgUnitDrawer = ({
28
28
  ...props
29
29
  }: DeleteOrgUnitDrawerProps) => {
30
30
  const router = useRouter();
31
- const { childrenOrgUnits } = useChildrenOrgUnits(id);
31
+ const { childrenOrgUnits } = useChildrenOrgUnits(id, name);
32
32
  const { pushToast } = useUI();
33
33
 
34
34
  const [confirmName, setConfirmName] = useState("");
@@ -1,5 +1,4 @@
1
- import { DropdownItem, Toggle } from "@faststore/ui";
2
- import { useRouter } from "next/router";
1
+ import { DropdownItem } from "@faststore/ui";
3
2
 
4
3
  import {
5
4
  CreateOrgUnitDrawer,
@@ -13,6 +12,7 @@ export type OrgUnitsDropdownMenuProps = {
13
12
  id: string;
14
13
  name: string;
15
14
  onUpdate?: () => void;
15
+ onCreate?: () => void;
16
16
  isComplete?: boolean;
17
17
  };
18
18
 
@@ -20,6 +20,7 @@ export const OrgUnitsDropdownMenu = ({
20
20
  id,
21
21
  name,
22
22
  onUpdate,
23
+ onCreate,
23
24
  isComplete = true,
24
25
  }: OrgUnitsDropdownMenuProps) => {
25
26
  const { open: openCreateDrawerProps, ...createDrawerProps } =
@@ -67,6 +68,7 @@ export const OrgUnitsDropdownMenu = ({
67
68
  <CreateOrgUnitDrawer
68
69
  readonly
69
70
  initialParentOrgUnit={{ id, name }}
71
+ onCreate={onCreate}
70
72
  {...createDrawerProps}
71
73
  />
72
74
  <DeleteOrgUnitDrawer id={id} name={name} {...deleteDrawerProps} />
@@ -8,11 +8,13 @@ import { HierarchyTree, Icon } from "../../../shared/components";
8
8
  export type OrgUnitsHierarchyTreeProps = {
9
9
  orgUnitHierarchyData: OrgUnitHierarchyData;
10
10
  readonly?: boolean;
11
+ enableChildren?: boolean;
11
12
  };
12
13
 
13
14
  export const OrgUnitsHierarchyTree = ({
14
15
  orgUnitHierarchyData,
15
16
  readonly,
17
+ enableChildren = true,
16
18
  }: OrgUnitsHierarchyTreeProps) => {
17
19
  const { structure, setNode } = useOrgUnitStructure(orgUnitHierarchyData);
18
20
 
@@ -23,7 +25,7 @@ export const OrgUnitsHierarchyTree = ({
23
25
  data-fs-org-units-hierarchy-root
24
26
  >
25
27
  {({ isRoot, isOpen, toggle, isLastNode, name, id }) => {
26
- useChildrenOrgUnits(id, {
28
+ const { refetchChildrenOrgUnits } = useChildrenOrgUnits(id, name, {
27
29
  onSuccess: (orgUnitHierarchyData) => {
28
30
  orgUnitHierarchyData?.nodes &&
29
31
  setNode(id, orgUnitHierarchyData.nodes);
@@ -39,20 +41,22 @@ export const OrgUnitsHierarchyTree = ({
39
41
  href={`/org-unit/${id}`}
40
42
  />
41
43
  )}
42
- <button
43
- type="button"
44
- data-fs-org-unit-item-toggle
45
- disabled={isLastNode}
46
- onClick={toggle}
47
- >
48
- <Icon
49
- name="ArrowRight"
50
- data-fs-org-unit-item-toggle-icon
51
- data-fs-org-unit-item-toggle-icon-open={isOpen}
52
- width={20}
53
- height={20}
54
- />
55
- </button>
44
+ {enableChildren && (
45
+ <button
46
+ type="button"
47
+ data-fs-org-unit-item-toggle
48
+ disabled={isLastNode}
49
+ onClick={toggle}
50
+ >
51
+ <Icon
52
+ name="ArrowRight"
53
+ data-fs-org-unit-item-toggle-icon
54
+ data-fs-org-unit-item-toggle-icon-open={isOpen}
55
+ width={20}
56
+ height={20}
57
+ />
58
+ </button>
59
+ )}
56
60
  <span data-fs-org-unit-item-wrapper>
57
61
  <Icon
58
62
  name={isRoot ? "FolderSpecial" : "Folder"}
@@ -74,7 +78,11 @@ export const OrgUnitsHierarchyTree = ({
74
78
  <Icon name="MoreVert" width={24} height={24} />
75
79
  </button>
76
80
  </DropdownButton>
77
- <OrgUnitsDropdownMenu id={id} name={name} />
81
+ <OrgUnitsDropdownMenu
82
+ id={id}
83
+ name={name}
84
+ onCreate={refetchChildrenOrgUnits}
85
+ />
78
86
  </Dropdown>
79
87
  </div>
80
88
  )}
@@ -10,7 +10,7 @@ type OrganizationalUnitsCardProps = {
10
10
  id: string | null;
11
11
  name: string;
12
12
  };
13
- organizationalUnits: OrgUnitData[];
13
+ organizationalUnits?: OrgUnitData[];
14
14
  };
15
15
 
16
16
  export default function OrganizationalUnitsCard({
@@ -3,11 +3,12 @@ import { getChildrenOrgUnitsService } from "../services";
3
3
 
4
4
  export const useChildrenOrgUnits = (
5
5
  id: string,
6
+ name: string,
6
7
  options?: QueryOptions<AwaitedType<typeof getChildrenOrgUnitsService>>
7
8
  ) => {
8
9
  const { data, error, isLoading, refetch } = useQuery(
9
10
  `api/children-org-units/${id}`,
10
- ({ cookie }) => getChildrenOrgUnitsService(id, cookie),
11
+ ({ cookie }) => getChildrenOrgUnitsService(id, name, cookie),
11
12
  options
12
13
  );
13
14
  return {
@@ -4,12 +4,11 @@ import { ContractsCard } from "../../../contracts/components";
4
4
  import { ProfileCard } from "../../../profile/components";
5
5
  import { GlobalLayout } from "../../../shared/layouts";
6
6
  import { UsersCard } from "../../../users/components";
7
- import type { UserData } from "../../../users/types";
8
7
  import {
9
8
  OrganizationalUnitsCard,
10
9
  OrgUnitsDropdownMenu,
11
10
  } from "../../components";
12
- import type { OrgUnitData, OrgUnitSummaryData } from "../../types";
11
+ import type { OrgUnitSummaryData } from "../../types";
13
12
  import { Icon } from "../../../shared/components";
14
13
 
15
14
  export type OrgUnitsDetailsLayoutProps = {
@@ -17,10 +16,7 @@ export type OrgUnitsDetailsLayoutProps = {
17
16
  };
18
17
 
19
18
  export const OrgUnitsDetailsLayout = ({ data }: OrgUnitsDetailsLayoutProps) => {
20
- const users: UserData[] = [];
21
- const orgUnits: OrgUnitData[] = [];
22
-
23
- const hasContracts = data.contracts.length > 0;
19
+ const isSingleContract = data.contracts.length === 1;
24
20
  return (
25
21
  <GlobalLayout>
26
22
  <section data-fs-home-section>
@@ -38,19 +34,19 @@ export const OrgUnitsDetailsLayout = ({ data }: OrgUnitsDetailsLayoutProps) => {
38
34
  </Dropdown>
39
35
  </div>
40
36
  <div data-fs-home-grid>
41
- {hasContracts ? (
42
- <ProfileCard orgUnitData={data} {...data.contracts[0]} />
37
+ {isSingleContract ? (
38
+ <ProfileCard {...data.contracts[0]} />
43
39
  ) : (
44
40
  <ContractsCard orgUnitData={data} contracts={data.contracts} />
45
41
  )}
46
- <UsersCard orgUnitData={data} users={users} />
47
- {/* Remove this comments when mocks be removed */}
48
- {hasContracts && (
49
- <AddressesCard orgUnitData={data} addresses={data?.addresses} />
42
+ <UsersCard orgUnitData={data} users={data.users} />
43
+ {!!data?.addresses?.length && (
44
+ <AddressesCard orgUnitData={data} addresses={data.addresses} />
50
45
  )}
46
+
51
47
  <OrganizationalUnitsCard
52
48
  orgUnitData={data}
53
- organizationalUnits={orgUnits}
49
+ organizationalUnits={data.children}
54
50
  />
55
51
  </div>
56
52
  </section>
@@ -4,17 +4,23 @@ import {
4
4
  InternalTopBar,
5
5
  MainLinksDropdownMenu,
6
6
  } from "../../../shared/components";
7
- import { useDrawerProps, useQueryParams } from "../../../shared/hooks";
7
+ import {
8
+ useBuyerPortal,
9
+ useDrawerProps,
10
+ useQueryParams,
11
+ } from "../../../shared/hooks";
8
12
  import { GlobalLayout } from "../../../shared/layouts";
9
13
  import { CreateOrgUnitDrawer, OrgUnitsHierarchyTree } from "../../components";
10
14
  import type { OrgUnitHierarchyData } from "../../types";
11
15
 
12
16
  export type OrgUnitsLayoutProps = {
13
17
  data: { organizationalUnits: OrgUnitHierarchyData[]; total: number } | null;
18
+ search: string;
14
19
  };
15
20
 
16
- export const OrgUnitsLayout = ({ data }: OrgUnitsLayoutProps) => {
21
+ export const OrgUnitsLayout = ({ data, search }: OrgUnitsLayoutProps) => {
17
22
  const { setQueryString, removeQueryString } = useQueryParams();
23
+ const { currentOrgUnit } = useBuyerPortal();
18
24
 
19
25
  const { open, ...drawerProps } = useDrawerProps();
20
26
 
@@ -35,6 +41,7 @@ export const OrgUnitsLayout = ({ data }: OrgUnitsLayoutProps) => {
35
41
 
36
42
  <div data-fs-buyer-portal-org-units-filter>
37
43
  <InternalSearch
44
+ defaultValue={search}
38
45
  textSearch={(searchTerm) => {
39
46
  searchTerm
40
47
  ? setQueryString("search", searchTerm)
@@ -48,6 +55,7 @@ export const OrgUnitsLayout = ({ data }: OrgUnitsLayoutProps) => {
48
55
  <section data-fs-hierarchy-tree-wrapper>
49
56
  {data?.organizationalUnits?.map((orgUnit) => (
50
57
  <OrgUnitsHierarchyTree
58
+ enableChildren={!search}
51
59
  key={orgUnit.id}
52
60
  orgUnitHierarchyData={orgUnit}
53
61
  />
@@ -57,7 +65,7 @@ export const OrgUnitsLayout = ({ data }: OrgUnitsLayoutProps) => {
57
65
  {data && (
58
66
  <CreateOrgUnitDrawer
59
67
  readonly
60
- initialParentOrgUnit={{ name: "Root", id: null }}
68
+ initialParentOrgUnit={currentOrgUnit ?? undefined}
61
69
  {...drawerProps}
62
70
  />
63
71
  )}