@vtex/faststore-plugin-buyer-portal 1.3.46 → 1.3.48

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 (61) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/package.json +1 -1
  3. package/public/buyer-portal-icons.svg +35 -13
  4. package/src/features/org-units/clients/OrgUnitClient.ts +17 -0
  5. package/src/features/org-units/components/AddAllToOrgUnitDropdown/AddAllToOrgUnitDropdown.tsx +2 -2
  6. package/src/features/org-units/components/AuthSetupDrawer/AuthSetupDrawer.tsx +346 -0
  7. package/src/features/org-units/components/AuthSetupDrawer/auth-setup-drawer.scss +138 -0
  8. package/src/features/org-units/components/AuthSetupDrawer/index.ts +1 -0
  9. package/src/features/org-units/components/OrgUnitDetailsDropdownMenu/OrgUnitDetailsDropdownMenu.tsx +80 -0
  10. package/src/features/org-units/components/OrgUnitDetailsDropdownMenu/index.ts +4 -0
  11. package/src/features/org-units/components/OrgUnitsDropdownMenu/OrgUnitsDropdownMenu.tsx +2 -2
  12. package/src/features/org-units/components/index.ts +8 -0
  13. package/src/features/org-units/hooks/index.ts +2 -0
  14. package/src/features/org-units/hooks/useGetOrgUnitSettings.ts +20 -0
  15. package/src/features/org-units/hooks/useOrgUnitByUser.ts +4 -1
  16. package/src/features/org-units/hooks/useUpdateOrgUnitSettings.ts +27 -0
  17. package/src/features/org-units/layouts/OrgUnitDetailsLayout/OrgUnitDetailsLayout.tsx +22 -1
  18. package/src/features/org-units/layouts/OrgUnitDetailsLayout/org-units-details.scss +1 -0
  19. package/src/features/org-units/services/get-org-unit-settings.service.ts +13 -0
  20. package/src/features/org-units/services/index.ts +8 -0
  21. package/src/features/org-units/services/update-org-unit-settings.service.ts +17 -0
  22. package/src/features/org-units/types/OrgUnitSettings.ts +25 -0
  23. package/src/features/org-units/types/index.ts +2 -0
  24. package/src/features/product-assortment/hooks/useGetProductAssortment.ts +52 -0
  25. package/src/features/product-assortment/hooks/useGetProductAssortmentFromContract.ts +35 -0
  26. package/src/features/product-assortment/layouts/ProductAssortmentLayout/ProductAssortmentLayout.tsx +55 -12
  27. package/src/features/product-assortment/layouts/ProductAssortmentLayout/product-assortment-layout.scss +1 -1
  28. package/src/features/product-assortment/types/index.ts +6 -14
  29. package/src/features/shared/components/BuyerPortalProvider/BuyerPortalProvider.tsx +5 -0
  30. package/src/features/shared/components/Toast/Toast.tsx +43 -2
  31. package/src/features/shared/components/Toast/toast.scss +23 -5
  32. package/src/features/shared/components/index.ts +1 -0
  33. package/src/features/shared/hooks/usePageItems.ts +2 -2
  34. package/src/features/shared/layouts/ContractTabsLayout/ContractTabsLayout.tsx +1 -0
  35. package/src/features/shared/layouts/LoadingTabsLayout/LoadingTabsLayout.tsx +13 -0
  36. package/src/features/shared/utils/constants.ts +2 -2
  37. package/src/features/shared/utils/withBuyerPortal.tsx +4 -1
  38. package/src/features/users/clients/UsersClient.ts +105 -4
  39. package/src/features/users/components/CreateUserDrawer/CreateUserDrawer.tsx +1 -1
  40. package/src/features/users/components/CreateUserDrawerSelector/CreateUserDrawerSelector.tsx +20 -0
  41. package/src/features/users/components/CreateUserDrawerWithUsername/CreateUserDrawerWithUsername.tsx +696 -0
  42. package/src/features/users/components/CreateUserDrawerWithUsername/create-user-drawer-with-username.scss +116 -0
  43. package/src/features/users/components/UserDropdownMenu/user-dropdown-menu.scss +1 -0
  44. package/src/features/users/components/UsersCard/UsersCard.tsx +2 -2
  45. package/src/features/users/components/index.ts +5 -0
  46. package/src/features/users/hooks/index.ts +2 -0
  47. package/src/features/users/hooks/useAddUserToOrgUnit.ts +12 -5
  48. package/src/features/users/hooks/useResetPassword.ts +39 -0
  49. package/src/features/users/hooks/useValidateUsername.ts +38 -0
  50. package/src/features/users/layouts/UserDetailsLayout/UserDetailsLayout.tsx +10 -0
  51. package/src/features/users/layouts/UsersLayout/UsersLayout.tsx +55 -10
  52. package/src/features/users/layouts/UsersLayout/users-layout.scss +19 -0
  53. package/src/features/users/services/add-user-to-org-unit.service.ts +8 -6
  54. package/src/features/users/services/get-users-by-org-unit-id.service.ts +1 -0
  55. package/src/features/users/services/index.ts +10 -0
  56. package/src/features/users/services/reset-password.service.ts +24 -0
  57. package/src/features/users/services/validate-username.service.ts +25 -0
  58. package/src/features/users/types/UserData.ts +1 -0
  59. package/src/features/users/types/UserDataService.ts +1 -0
  60. package/src/pages/org-unit-details.tsx +20 -2
  61. package/src/pages/productAssortment.tsx +61 -65
@@ -0,0 +1,80 @@
1
+ import { DropdownItem } from "@faststore/ui";
2
+
3
+ import { BasicDropdownMenu, Icon } from "../../../shared/components";
4
+ import { useDrawerProps } from "../../../shared/hooks";
5
+ // TODO[2FA]: Uncomment when Authentication settings are ready
6
+ // import { AuthSetupDrawer } from "../AuthSetupDrawer";
7
+ import { UpdateOrgUnitDrawer } from "../UpdateOrgUnitDrawer/UpdateOrgUnitDrawer";
8
+
9
+ // TODO[2FA]: Uncomment when Authentication settings are ready
10
+ // import type { OrgUnitSettings } from "../../types";
11
+
12
+ export type OrgUnitDetailsDropdownMenuProps = {
13
+ id: string;
14
+ name: string;
15
+ // TODO[2FA]: Uncomment when Authentication settings are ready
16
+ // settings: OrgUnitSettings;
17
+ onUpdate?: () => void;
18
+ };
19
+
20
+ export const OrgUnitDetailsDropdownMenu = ({
21
+ id,
22
+ name,
23
+ // TODO[2FA]: Uncomment when Authentication settings are ready
24
+ // settings,
25
+ onUpdate,
26
+ }: OrgUnitDetailsDropdownMenuProps) => {
27
+ const {
28
+ open: openUpdateDrawerProps,
29
+ isOpen: isUpdateDrawerOpen,
30
+ ...updateDrawerProps
31
+ } = useDrawerProps();
32
+
33
+ // TODO[2FA]: Uncomment when Authentication settings are ready
34
+ // const {
35
+ // open: openAuthSetupDrawerProps,
36
+ // isOpen: isAuthSetupDrawerOpen,
37
+ // ...authSetupDrawerProps
38
+ // } = useDrawerProps();
39
+
40
+ const sizeProps = { width: 20, height: 20 };
41
+
42
+ return (
43
+ <>
44
+ <BasicDropdownMenu>
45
+ <DropdownItem onClick={openUpdateDrawerProps}>
46
+ <Icon name="FormatSize" {...sizeProps} />
47
+ Rename
48
+ </DropdownItem>
49
+ {/* TODO[2FA]: Uncomment when 2FA settings are ready
50
+ <BasicDropdownMenu.Separator />
51
+ <DropdownItem onClick={openAuthSetupDrawerProps}>
52
+ <Icon name="Settings" {...sizeProps} />
53
+ Authentication
54
+ </DropdownItem>
55
+ */}
56
+ </BasicDropdownMenu>
57
+ {isUpdateDrawerOpen && (
58
+ <UpdateOrgUnitDrawer
59
+ readonly
60
+ id={id}
61
+ name={name}
62
+ onSuccess={onUpdate}
63
+ {...updateDrawerProps}
64
+ isOpen={isUpdateDrawerOpen}
65
+ />
66
+ )}
67
+ {/* TODO[2FA]: Uncomment when 2FA settings are ready
68
+ {isAuthSetupDrawerOpen && (
69
+ <AuthSetupDrawer
70
+ id={id}
71
+ name={name}
72
+ settings={settings}
73
+ {...authSetupDrawerProps}
74
+ isOpen={isAuthSetupDrawerOpen}
75
+ />
76
+ )}
77
+ */}
78
+ </>
79
+ );
80
+ };
@@ -0,0 +1,4 @@
1
+ export {
2
+ OrgUnitDetailsDropdownMenu,
3
+ type OrgUnitDetailsDropdownMenuProps,
4
+ } from "./OrgUnitDetailsDropdownMenu";
@@ -8,7 +8,7 @@ import {
8
8
  import { useGetRolesOptions } from "../../../roles/hooks";
9
9
  import { BasicDropdownMenu, Icon } from "../../../shared/components";
10
10
  import { useDrawerProps } from "../../../shared/hooks";
11
- import { CreateUserDrawer } from "../../../users/components";
11
+ import { CreateUserDrawerSelector } from "../../../users/components";
12
12
 
13
13
  export type OrgUnitsDropdownMenuProps = {
14
14
  id: string;
@@ -114,7 +114,7 @@ export const OrgUnitsDropdownMenu = ({
114
114
  />
115
115
  )}
116
116
  {isCreateUserDrawerOpen && (
117
- <CreateUserDrawer
117
+ <CreateUserDrawerSelector
118
118
  orgUnit={{ id, name }}
119
119
  rolesOptions={rolesOptions}
120
120
  {...createUserDrawerProps}
@@ -28,3 +28,11 @@ export {
28
28
  type OrgUnitDetailsNavbarProps,
29
29
  } from "./OrgUnitDetailsNavbar/OrgUnitDetailsNavbar";
30
30
  export { OrgUnitBreadcrumb } from "./OrgUnitBreadcrumb/OrgUnitBreadcrumb";
31
+ export {
32
+ AuthSetupDrawer,
33
+ type AuthSetupDrawerProps,
34
+ } from "./AuthSetupDrawer/AuthSetupDrawer";
35
+ export {
36
+ OrgUnitDetailsDropdownMenu,
37
+ type OrgUnitDetailsDropdownMenuProps,
38
+ } from "./OrgUnitDetailsDropdownMenu/OrgUnitDetailsDropdownMenu";
@@ -2,6 +2,8 @@ export { useCreateNewOrgUnit } from "./useCreateNewOrgUnit";
2
2
  export { useDeleteOrgUnit } from "./useDeleteOrgUnit";
3
3
  export { useOrgUnitStructure } from "./useOrgUnitStructure";
4
4
  export { useUpdateOrgUnit } from "./useUpdateOrgUnit";
5
+ export { useUpdateOrgUnitSettings } from "./useUpdateOrgUnitSettings";
5
6
  export { useChildrenOrgUnits } from "./useChildrenOrgUnits";
6
7
  export { useOrgUnitByUser } from "./useOrgUnitByUser";
7
8
  export { useSearchOrgUnits } from "./useSearchOrgUnits";
9
+ export { useGetOrgUnitSettings } from "./useGetOrgUnitSettings";
@@ -0,0 +1,20 @@
1
+ import { type QueryOptions, useQuery } from "../../shared/hooks";
2
+ import { getOrgUnitSettingsService } from "../services";
3
+
4
+ export const useGetOrgUnitSettings = (
5
+ unitId: string,
6
+ options?: QueryOptions<AwaitedType<typeof getOrgUnitSettingsService>>
7
+ ) => {
8
+ const { data, error, isLoading, refetch } = useQuery(
9
+ `api/org-unit-settings/${unitId}`,
10
+ ({ cookie }) => getOrgUnitSettingsService({ cookie, unitId }),
11
+ options
12
+ );
13
+
14
+ return {
15
+ settings: data,
16
+ hasSettingsError: error,
17
+ isSettingsLoading: isLoading,
18
+ refetchSettings: refetch,
19
+ };
20
+ };
@@ -8,7 +8,10 @@ export const useOrgUnitByUser = (
8
8
  const { data, error, isLoading, refetch } = useQuery(
9
9
  `api/org-unit-by-user-id/${userId}`,
10
10
  ({ cookie }) => getOrgUnitByUserIdService({ cookie, userId }),
11
- options
11
+ {
12
+ ...options,
13
+ lazy: !userId || options?.lazy,
14
+ }
12
15
  );
13
16
  return {
14
17
  orgUnit: data,
@@ -0,0 +1,27 @@
1
+ import { type MutationOptions, useMutation } from "../../shared/hooks";
2
+ import {
3
+ updateOrgUnitSettingsService,
4
+ type UpdateOrgUnitSettingsServiceProps,
5
+ } from "../services/update-org-unit-settings.service";
6
+
7
+ export const useUpdateOrgUnitSettings = (
8
+ options?: MutationOptions<AwaitedType<typeof updateOrgUnitSettingsService>>
9
+ ) => {
10
+ const { mutate, isLoading, error } = useMutation<
11
+ null,
12
+ Omit<UpdateOrgUnitSettingsServiceProps, "cookie">
13
+ >(
14
+ (variables, clientContext) =>
15
+ updateOrgUnitSettingsService({
16
+ ...variables,
17
+ cookie: clientContext.cookie,
18
+ }),
19
+ options
20
+ );
21
+
22
+ return {
23
+ updateOrgUnitSettings: mutate,
24
+ isUpdateOrgUnitSettingsLoading: isLoading,
25
+ hasUpdateOrgUnitSettingsError: error,
26
+ };
27
+ };
@@ -13,6 +13,7 @@ import {
13
13
  LetterHighlight,
14
14
  VerticalNav,
15
15
  } from "../../../shared/components";
16
+ import { BasicDropdownMenuTrigger } from "../../../shared/components/BasicDropdownMenu/BasicDropdownMenuTrigger";
16
17
  import { useMediaQuery } from "../../../shared/hooks/useMediaQuery";
17
18
  import { GlobalLayout } from "../../../shared/layouts";
18
19
  import {
@@ -25,6 +26,7 @@ import {
25
26
  AddAllToOrgUnitDropdown,
26
27
  OrgUnitBreadcrumb,
27
28
  OrgUnitDetailsNavbar,
29
+ OrgUnitDetailsDropdownMenu,
28
30
  } from "../../components";
29
31
  import { useOrgUnitByUser } from "../../hooks";
30
32
 
@@ -43,12 +45,19 @@ export type OrgUnitsDetailsLayoutProps = {
43
45
  orgUnit: OrgUnitBasicData;
44
46
  contracts: ContractData[];
45
47
  user: UserData | null;
48
+ // TODO[2FA]: Uncomment when Authentication settings are ready
49
+ // settings: OrgUnitSettings;
46
50
  };
47
51
  loading?: boolean;
48
52
  };
49
53
 
50
54
  export const OrgUnitsDetailsLayout = ({
51
- data: { orgUnit, contracts, user },
55
+ data: {
56
+ orgUnit,
57
+ contracts,
58
+ user, // TODO[2FA]: Uncomment when Authentication settings are ready
59
+ // settings,
60
+ },
52
61
  loading = false,
53
62
  }: OrgUnitsDetailsLayoutProps) => {
54
63
  const isMobile = useMediaQuery(QUERY_TABLET);
@@ -104,10 +113,22 @@ export const OrgUnitsDetailsLayout = ({
104
113
  />
105
114
  )}
106
115
 
116
+ <Dropdown>
117
+ <BasicDropdownMenuTrigger />
118
+
119
+ <OrgUnitDetailsDropdownMenu
120
+ id={orgUnit?.id}
121
+ name={orgUnit?.name}
122
+ // TODO[2FA]: Uncomment when Authentication settings are ready
123
+ // settings={settings}
124
+ />
125
+ </Dropdown>
126
+
107
127
  <Dropdown>
108
128
  <DropdownButton asChild>
109
129
  <HeaderInside.Button />
110
130
  </DropdownButton>
131
+
111
132
  <AddAllToOrgUnitDropdown
112
133
  isSingleContract={isSingleContract}
113
134
  contractId={contracts[0]?.id}
@@ -5,6 +5,7 @@
5
5
  @import "../../../shared/layouts/BaseTabsLayout/about-drawer/about-drawer.scss";
6
6
  @import "../../../credit-cards/components/CreateCreditCardDrawer/create-credit-card-drawer.scss";
7
7
  @import "../../components/OrgUnitBreadcrumb/org-unit-breadcrumb.scss";
8
+ @import "../../components/AuthSetupDrawer/auth-setup-drawer.scss";
8
9
 
9
10
  [data-fs-org-units-details-section] {
10
11
  @import "../../../shared/components/BasicCard/basic-card.scss";
@@ -0,0 +1,13 @@
1
+ import { orgUnitClient } from "../clients/OrgUnitClient";
2
+
3
+ export type GetOrgUnitSettingsServiceProps = {
4
+ unitId: string;
5
+ cookie: string;
6
+ };
7
+
8
+ export const getOrgUnitSettingsService = async ({
9
+ unitId,
10
+ cookie,
11
+ }: GetOrgUnitSettingsServiceProps) => {
12
+ return orgUnitClient.getOrgUnitSettings(unitId, cookie);
13
+ };
@@ -19,3 +19,11 @@ export {
19
19
  } from "./update-org-unit.service";
20
20
  export { getOrgUnitByUserIdService } from "./get-org-unit-by-user-id.service";
21
21
  export { searchOrgUnitsByNameService } from "./search-org-units-by-name.service";
22
+ export {
23
+ type GetOrgUnitSettingsServiceProps,
24
+ getOrgUnitSettingsService,
25
+ } from "./get-org-unit-settings.service";
26
+ export {
27
+ type UpdateOrgUnitSettingsServiceProps,
28
+ updateOrgUnitSettingsService,
29
+ } from "./update-org-unit-settings.service";
@@ -0,0 +1,17 @@
1
+ import { orgUnitClient } from "../clients/OrgUnitClient";
2
+
3
+ import type { OrgUnitSettings } from "../types";
4
+
5
+ export type UpdateOrgUnitSettingsServiceProps = {
6
+ unitId: string;
7
+ data: OrgUnitSettings;
8
+ cookie: string;
9
+ };
10
+
11
+ export const updateOrgUnitSettingsService = async ({
12
+ unitId,
13
+ data,
14
+ cookie,
15
+ }: UpdateOrgUnitSettingsServiceProps) => {
16
+ return orgUnitClient.updateOrgUnitSettings(unitId, data, cookie);
17
+ };
@@ -0,0 +1,25 @@
1
+ export enum AuthenticationMethod {
2
+ PASSWORD = "PASSWORD",
3
+ SSO = "SSO",
4
+ }
5
+
6
+ export type OrgUnitSettings = {
7
+ userIdentification: {
8
+ userName: boolean;
9
+ email: boolean;
10
+ phone: boolean;
11
+ };
12
+ authenticationMethods: {
13
+ method: AuthenticationMethod;
14
+ };
15
+ "2FA": {
16
+ verificationCode: boolean;
17
+ };
18
+ };
19
+
20
+ export type Identifier = {
21
+ id: string;
22
+ name: string;
23
+ disabled: boolean;
24
+ defaultChecked?: boolean;
25
+ };
@@ -14,3 +14,5 @@ export type {
14
14
  OrgUnitSearchParams,
15
15
  OrgUnitSearchResponse,
16
16
  } from "./OrgUnitSearch";
17
+ export { AuthenticationMethod } from "./OrgUnitSettings";
18
+ export type { OrgUnitSettings, Identifier } from "./OrgUnitSettings";
@@ -0,0 +1,52 @@
1
+ import { type QueryOptions, useQuery } from "../../shared/hooks";
2
+ import { getProductAssortmentFromScopeService } from "../services/get-product-assortment-from-scope.service";
3
+
4
+ export const useGetProductAssortment = ({
5
+ contractId,
6
+ orgUnitId,
7
+ search = "",
8
+ filterByScope = false,
9
+ page = 1,
10
+ options,
11
+ }: {
12
+ contractId: string;
13
+ orgUnitId: string;
14
+ filterByScope?: boolean;
15
+ search?: string;
16
+ page?: number;
17
+ options?: QueryOptions<
18
+ AwaitedType<typeof getProductAssortmentFromScopeService>
19
+ >;
20
+ }) => {
21
+ const { data, error, isLoading, refetch } = useQuery(
22
+ `customers/${contractId}/units/${orgUnitId}/collections`,
23
+ ({ cookie }) =>
24
+ getProductAssortmentFromScopeService({
25
+ args: {
26
+ cookie,
27
+ contractId,
28
+ unitId: orgUnitId,
29
+ filterByScope,
30
+ name: search,
31
+ page,
32
+ },
33
+ }),
34
+ { ...options }
35
+ );
36
+
37
+ return {
38
+ data: {
39
+ items: data?.items ?? [],
40
+ paging: {
41
+ page: data?.paging?.page ?? 1,
42
+ total: data?.paging?.total ?? 0,
43
+ pages: data?.paging?.pages ?? 0,
44
+ limit: data?.paging?.limit ?? 10,
45
+ perPage: data?.paging?.perPage ?? 10,
46
+ },
47
+ },
48
+ hasError: !!error,
49
+ isProductAssortmentLoading: isLoading,
50
+ refetchProductAssortment: refetch,
51
+ };
52
+ };
@@ -0,0 +1,35 @@
1
+ import { type QueryOptions, useQuery } from "../../shared/hooks";
2
+ import { getProductAssortmentFromContractService } from "../services/get-product-assortment-from-contract.service";
3
+
4
+ export const useGetProductAssortmentFromContract = ({
5
+ contractId,
6
+ orgUnitId,
7
+ search = "",
8
+ options,
9
+ }: {
10
+ contractId: string;
11
+ orgUnitId: string;
12
+ search?: string;
13
+ options?: QueryOptions<
14
+ AwaitedType<typeof getProductAssortmentFromContractService>
15
+ >;
16
+ }) => {
17
+ const { data, error, isLoading, refetch } = useQuery(
18
+ `customers/${contractId}/units/${orgUnitId}/collections`,
19
+ ({ cookie }) =>
20
+ getProductAssortmentFromContractService({
21
+ cookie,
22
+ contractId,
23
+ unitId: orgUnitId,
24
+ name: search,
25
+ }),
26
+ { ...options }
27
+ );
28
+
29
+ return {
30
+ data,
31
+ hasError: !!error,
32
+ isProductAssortmentFromContractLoading: isLoading,
33
+ refetchProductAssortmentFromContract: refetch,
34
+ };
35
+ };
@@ -1,3 +1,5 @@
1
+ import { useMemo } from "react";
2
+
1
3
  import { Tooltip } from "@faststore/ui";
2
4
 
3
5
  import {
@@ -6,11 +8,16 @@ import {
6
8
  Paginator,
7
9
  } from "../../../shared/components";
8
10
  import { EmptyState } from "../../../shared/components/EmptyState/EmptyState";
9
- import { useBuyerPortal, usePageItems } from "../../../shared/hooks";
10
- import { useDrawerProps } from "../../../shared/hooks";
11
+ import {
12
+ useBuyerPortal,
13
+ useDrawerProps,
14
+ usePageItems,
15
+ } from "../../../shared/hooks";
11
16
  import { ContractTabsLayout, GlobalLayout } from "../../../shared/layouts";
12
17
  import { AddProductAssortmentDrawer } from "../../components";
13
18
  import { ProductAssortmentTable } from "../../components/ProductAssortmentTable/ProductAssortmentTable";
19
+ import { useGetProductAssortment } from "../../hooks/useGetProductAssortment";
20
+ import { useGetProductAssortmentFromContract } from "../../hooks/useGetProductAssortmentFromContract";
14
21
 
15
22
  import type {
16
23
  ProductAssortmentLayoutProps,
@@ -18,11 +25,10 @@ import type {
18
25
  } from "../../types";
19
26
 
20
27
  export const ProductAssortmentLayout = ({
21
- initialProductAssortment,
22
- drawerProductAssortment,
23
- isContractEmpty,
24
28
  page,
25
29
  search,
30
+ orgUnitId,
31
+ contractId,
26
32
  }: ProductAssortmentLayoutProps) => {
27
33
  const {
28
34
  currentOrgUnit: orgUnit,
@@ -30,6 +36,39 @@ export const ProductAssortmentLayout = ({
30
36
  currentContract: contract,
31
37
  } = useBuyerPortal();
32
38
 
39
+ const { data: drawerProductAssortment } = useGetProductAssortment({
40
+ contractId,
41
+ orgUnitId,
42
+ });
43
+ const { data: contractAssortment } = useGetProductAssortmentFromContract({
44
+ contractId,
45
+ orgUnitId,
46
+ });
47
+ const { data: initialProductAssortment, isProductAssortmentLoading } =
48
+ useGetProductAssortment({
49
+ filterByScope: true,
50
+ contractId,
51
+ orgUnitId,
52
+ search,
53
+ page,
54
+ });
55
+
56
+ const isContractEmpty = !contractAssortment || contractAssortment.total === 0;
57
+
58
+ const itemsKey = useMemo(
59
+ () =>
60
+ initialProductAssortment.items
61
+ .map((item) => item.id)
62
+ .sort()
63
+ .join(","),
64
+ [initialProductAssortment.items]
65
+ );
66
+
67
+ const memoizedInitialItems = useMemo(
68
+ () => initialProductAssortment.items,
69
+ [itemsKey]
70
+ );
71
+
33
72
  const {
34
73
  isLoading,
35
74
  items: productAssortment,
@@ -38,7 +77,7 @@ export const ProductAssortmentLayout = ({
38
77
  increasePage,
39
78
  decreasePage,
40
79
  } = usePageItems<ProductAssortmentWithAdditionalInformation>({
41
- initialItems: initialProductAssortment.items,
80
+ initialItems: memoizedInitialItems,
42
81
  search,
43
82
  page,
44
83
  });
@@ -53,7 +92,6 @@ export const ProductAssortmentLayout = ({
53
92
  ...addProductAssortmentDrawerProps
54
93
  } = useDrawerProps();
55
94
 
56
- //const enabledAssortment = productAssortment.filter((p) => p.isEnabled);
57
95
  const hasAllAssortment = drawerProductAssortment.items.length === 0;
58
96
  const isEmpty = productAssortment.length === 0;
59
97
 
@@ -72,7 +110,7 @@ export const ProductAssortmentLayout = ({
72
110
  <GlobalLayout>
73
111
  <ContractTabsLayout
74
112
  orgUnitName={orgUnit?.name ?? ""}
75
- orgUnitId={orgUnit?.id ?? ""}
113
+ orgUnitId={orgUnitId ?? orgUnit?.id ?? ""}
76
114
  contractName={contract?.name ?? ""}
77
115
  contractId={contract?.id ?? ""}
78
116
  pageName="Contract"
@@ -80,6 +118,7 @@ export const ProductAssortmentLayout = ({
80
118
  image: undefined,
81
119
  name: user?.name ?? "",
82
120
  role: user?.role ?? "",
121
+ id: user?.id ?? "",
83
122
  }}
84
123
  >
85
124
  <section data-fs-bp-product-assortment-container>
@@ -140,9 +179,11 @@ export const ProductAssortmentLayout = ({
140
179
  {initialProductAssortment.paging.page > 1 ? (
141
180
  <Paginator.NextPageButton
142
181
  onClick={decreasePage}
143
- disabled={isLoading}
182
+ disabled={isLoading || isProductAssortmentLoading}
144
183
  >
145
- {isLoading ? "Loading" : "Previous Page"}
184
+ {isLoading || isProductAssortmentLoading
185
+ ? "Loading"
186
+ : "Previous Page"}
146
187
  </Paginator.NextPageButton>
147
188
  ) : (
148
189
  <></>
@@ -150,9 +191,11 @@ export const ProductAssortmentLayout = ({
150
191
  {!isLastPage && !isEmpty ? (
151
192
  <Paginator.NextPageButton
152
193
  onClick={increasePage}
153
- disabled={isLoading}
194
+ disabled={isLoading || isProductAssortmentLoading}
154
195
  >
155
- {isLoading ? "Loading" : "Next Page"}
196
+ {isLoading || isProductAssortmentLoading
197
+ ? "Loading"
198
+ : "Next Page"}
156
199
  </Paginator.NextPageButton>
157
200
  ) : (
158
201
  <></>
@@ -95,4 +95,4 @@
95
95
  margin-top: var(--fs-spacing-0);
96
96
  padding: var(--fs-spacing-2) 0;
97
97
  }
98
- }
98
+ }
@@ -1,8 +1,5 @@
1
- import type { ContractData } from "../../contracts/types";
2
- import type { OrgUnitBasicData } from "../../org-units/types";
3
1
  import type { BasicDrawerProps } from "../../shared/components";
4
2
  import type { ErrorBoundaryProps } from "../../shared/components/ErrorBoundary/types";
5
- import type { ClientContext } from "../../shared/utils";
6
3
 
7
4
  export type ProductAssortmentSummary = {
8
5
  id: string;
@@ -55,24 +52,19 @@ export interface ProductAssortmentSelectedProps {
55
52
  }
56
53
 
57
54
  export type ProductAssortmentLayoutProps = {
58
- initialProductAssortment: GetProductAssortmentFromContractResponse;
59
- drawerProductAssortment: GetProductAssortmentFromContractResponse;
55
+ userId?: string;
56
+ orgUnitId: string;
57
+ contractId: string;
60
58
  page: number;
61
59
  search: string;
62
- isContractEmpty: boolean;
63
60
  };
64
61
 
65
62
  export type ProductAssortmentData = {
66
- productAssortment: GetProductAssortmentFromContractResponse;
67
- drawerProductAssortment: GetProductAssortmentFromContractResponse;
68
- isContractEmpty: boolean;
63
+ userId: string;
64
+ orgUnitId: string;
65
+ contractId: string;
69
66
  search: string;
70
67
  page: number;
71
- context: {
72
- clientContext: ClientContext;
73
- currentOrgUnit: OrgUnitBasicData;
74
- currentContract: ContractData | null;
75
- };
76
68
  hasError?: boolean;
77
69
  error?: ErrorBoundaryProps;
78
70
  };
@@ -7,6 +7,10 @@ import type { ContractData } from "../../../contracts/types";
7
7
  import type { OrgUnitBasicData } from "../../../org-units/types";
8
8
  import type { ClientContext } from "../../utils";
9
9
 
10
+ export type FeatureFlags = {
11
+ enableUsernameCreation?: boolean;
12
+ };
13
+
10
14
  export type BuyerPortalContextType = {
11
15
  clientContext: ClientContext;
12
16
  currentOrgUnit?: OrgUnitBasicData | null;
@@ -16,6 +20,7 @@ export type BuyerPortalContextType = {
16
20
  name: string;
17
21
  role?: string;
18
22
  } | null;
23
+ featureFlags?: FeatureFlags;
19
24
  };
20
25
 
21
26
  export const BuyerPortalContext = createContext<