@vtex/faststore-plugin-buyer-portal 1.1.116-poc-4 → 1.1.116-poc-5

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.116-poc-4",
3
+ "version": "1.1.116-poc-5",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,6 +15,10 @@ const getContractDetailsFunction = async ({
15
15
  cookie,
16
16
  unitId,
17
17
  }: GetContractDetailsServiceProps) => {
18
+ if (!unitId || !contractId) {
19
+ return null;
20
+ }
21
+
18
22
  const { contract } = await contractsClient.getContractDetails(
19
23
  unitId,
20
24
  contractId,
@@ -6,6 +6,7 @@ import type {
6
6
  OrgUnitSummaryData,
7
7
  OrgUnitSearchParams,
8
8
  OrgUnitSearchResponse,
9
+ OrgUnitUserData,
9
10
  } from "../types";
10
11
 
11
12
  export class OrgUnitClient extends Client {
@@ -30,21 +31,7 @@ export class OrgUnitClient extends Client {
30
31
  }
31
32
 
32
33
  getOrgUnitByUserId(userId: string, cookie: string) {
33
- return this.get<{
34
- orgUnit: {
35
- createdAt: string;
36
- updatedAt: string;
37
- name: string;
38
- path: {
39
- ids: string;
40
- names: string;
41
- };
42
- id: string;
43
- customerGroup: {
44
- customerIds: string[];
45
- };
46
- };
47
- }>(`users/${userId}/units`, {
34
+ return this.get<OrgUnitUserData>(`users/${userId}/units`, {
48
35
  headers: {
49
36
  Cookie: cookie,
50
37
  },
@@ -7,5 +7,9 @@ export const getOrgUnitBasicDataService = async ({
7
7
  id: string;
8
8
  cookie: string;
9
9
  }) => {
10
+ if (!id) {
11
+ return null;
12
+ }
13
+
10
14
  return orgUnitClient.getOrgUnitBasicData(id, cookie);
11
15
  };
@@ -8,6 +8,10 @@ export const getOrgUnitByUserIdService = async ({
8
8
  cookie: string;
9
9
  }) => {
10
10
  try {
11
+ if (!userId) {
12
+ return null;
13
+ }
14
+
11
15
  const { orgUnit } = await orgUnitClient.getOrgUnitByUserId(userId, cookie);
12
16
  return orgUnit;
13
17
  } catch {
@@ -25,3 +25,21 @@ export type OrgUnitBasicData = Pick<OrgUnitSummaryData, "id" | "name"> & {
25
25
  ids: string;
26
26
  };
27
27
  };
28
+
29
+ export type UserOrgUnit = {
30
+ createdAt: string;
31
+ updatedAt: string;
32
+ name: string;
33
+ path: {
34
+ ids: string;
35
+ names: string;
36
+ };
37
+ id: string;
38
+ customerGroup: {
39
+ customerIds: string[];
40
+ };
41
+ };
42
+
43
+ export type OrgUnitUserData = {
44
+ orgUnit: UserOrgUnit;
45
+ };
@@ -1,6 +1,8 @@
1
1
  export type {
2
2
  OrgUnitBasicData,
3
3
  OrgUnitSummaryData,
4
+ OrgUnitUserData,
5
+ UserOrgUnit,
4
6
  } from "./OrgUnitSummaryData";
5
7
  export type { OrgUnitData, OrgUnitHierarchyData } from "./OrgUnitsData";
6
8
  export type { OrganizationData } from "./OrganizationData";
@@ -10,12 +10,14 @@ export type ProfileLayoutProps = {
10
10
  orgUnitId: string;
11
11
  contractId: string;
12
12
  userId: string;
13
+ loading?: boolean;
13
14
  };
14
15
 
15
16
  export const ProfileLayout = ({
16
17
  orgUnitId,
17
18
  contractId,
18
19
  userId,
20
+ loading = true,
19
21
  }: ProfileLayoutProps) => {
20
22
  const { orgUnit, isOrgUnitLoading } = useOrgUnitBasicData(orgUnitId);
21
23
 
@@ -26,7 +28,7 @@ export const ProfileLayout = ({
26
28
 
27
29
  const { user, isUserLoading } = useGetUserById({ orgUnitId, userId });
28
30
 
29
- const loading = isContractLoading || isOrgUnitLoading || isUserLoading;
31
+ loading = isContractLoading || isOrgUnitLoading || isUserLoading;
30
32
 
31
33
  const creationDate = contract
32
34
  ? new Date(contract.creationDate).toLocaleDateString("en-US", {
@@ -55,6 +57,15 @@ export const ProfileLayout = ({
55
57
  <section data-fs-bp-profile>
56
58
  <HeaderInside title="Profile" />
57
59
 
60
+ {loading && !contract && (
61
+ <Skeleton
62
+ size={{
63
+ width: "100%",
64
+ height: "8rem",
65
+ }}
66
+ />
67
+ )}
68
+
58
69
  {contract && (
59
70
  <div data-fs-bp-profile-details>
60
71
  <span data-fs-bp-profile-details-title>Details</span>
@@ -90,15 +101,6 @@ export const ProfileLayout = ({
90
101
  <hr data-fs-bp-profile-divider />
91
102
  </div>
92
103
  )}
93
-
94
- {loading && (
95
- <Skeleton
96
- size={{
97
- width: "100%",
98
- height: "8rem",
99
- }}
100
- />
101
- )}
102
104
  </section>
103
105
  </ContractTabsLayout>
104
106
  </GlobalLayout>
@@ -33,6 +33,8 @@ export const LoadingTabsLayoutContent = ({
33
33
  );
34
34
 
35
35
  export const LoadingTabsLayout = ({ children }: LoadingTabsLayoutProps) => {
36
+ console.log("Enter loading layout");
37
+
36
38
  const { routerLoading, nextRoute } = useRouterLoading();
37
39
  const [shouldShowLoading, setShouldShowLoading] = useState(false);
38
40
  const wasLoadingRef = useRef(false);
@@ -65,6 +67,8 @@ export const LoadingTabsLayout = ({ children }: LoadingTabsLayoutProps) => {
65
67
 
66
68
  const pageTitle = layoutConfig.pageTitle;
67
69
 
70
+ console.log(">>>TabsLayout", layoutConfig.layout);
71
+
68
72
  switch (layoutConfig.layout) {
69
73
  case "ContractTabsLayout":
70
74
  return (
@@ -12,6 +12,10 @@ export const getUserByIdService = async ({
12
12
  cookie: string;
13
13
  }): Promise<UserData | null> => {
14
14
  try {
15
+ if (!userId || orgUnitId) {
16
+ return {} as UserData;
17
+ }
18
+
15
19
  const { email, name, orgUnit, role } = await usersClient.getUserById(
16
20
  orgUnitId,
17
21
  userId,
@@ -1,5 +1,5 @@
1
1
  import { OrgUnitsDetailsLayout } from "../features/org-units/layouts";
2
- import { PageLoader, withErrorBoundary } from "../features/shared/components";
2
+ import { withErrorBoundary } from "../features/shared/components";
3
3
  import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
4
4
  import { useAuth } from "../features/shared/hooks";
5
5
  import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
@@ -68,7 +68,7 @@ const OrgUnitDetailsPage = ({
68
68
  console.log(">> Context", data.cookie);
69
69
 
70
70
  if (isLoading || isAuthenticated === null) {
71
- return <PageLoader />;
71
+ return <OrgUnitsDetailsLayout loading={true} orgUnitId="" userId="" />;
72
72
  }
73
73
 
74
74
  return (