@vtex/faststore-plugin-buyer-portal 1.1.116-poc-1 → 1.1.116-poc-3

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-1",
3
+ "version": "1.1.116-poc-3",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,3 +1,5 @@
1
+ import { Skeleton } from "@faststore/ui";
2
+
1
3
  import { useContractDetails } from "../../../contracts/hooks";
2
4
  import { useOrgUnitBasicData } from "../../../org-units/hooks";
3
5
  import { HeaderInside } from "../../../shared/components";
@@ -88,6 +90,15 @@ export const ProfileLayout = ({
88
90
  <hr data-fs-bp-profile-divider />
89
91
  </div>
90
92
  )}
93
+
94
+ {loading && (
95
+ <Skeleton
96
+ size={{
97
+ width: "100%",
98
+ height: "8rem",
99
+ }}
100
+ />
101
+ )}
91
102
  </section>
92
103
  </ContractTabsLayout>
93
104
  </GlobalLayout>
@@ -3,8 +3,7 @@ import { useEffect, useState } from "react";
3
3
  import { useRouter } from "next/router";
4
4
 
5
5
  import { authClient } from "../clients/Auth";
6
-
7
- import { useBuyerPortal } from "./useBuyerPortal";
6
+ import { ClientContext } from "../utils";
8
7
 
9
8
  export type UseAuthResult = {
10
9
  isAuthenticated: boolean | null;
@@ -17,8 +16,7 @@ export type UseAuthResult = {
17
16
  *
18
17
  * @returns Object containing authentication status and loading state
19
18
  */
20
- export const useAuth = (): UseAuthResult => {
21
- const { clientContext } = useBuyerPortal();
19
+ export const useAuth = (clientContext: ClientContext): UseAuthResult => {
22
20
  const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
23
21
  const [isLoading, setIsLoading] = useState(true);
24
22
  const router = useRouter();
@@ -2,8 +2,9 @@ import type { ReactNode } from "react";
2
2
 
3
3
  import { DropdownItem } from "@faststore/ui";
4
4
 
5
+ import { useContractDetails } from "../../../contracts/hooks";
6
+ import { useOrgUnitBasicData } from "../../../org-units/hooks";
5
7
  import { Icon } from "../../components";
6
- import { useBuyerPortal } from "../../hooks";
7
8
  import { getContractSettingsLinks } from "../../utils";
8
9
  import { BaseTabsLayout } from "../BaseTabsLayout/BaseTabsLayout";
9
10
 
@@ -32,17 +33,19 @@ export const ContractTabsLayout = ({
32
33
  contractId,
33
34
  person,
34
35
  }: ContractTabsLayoutProps) => {
35
- const { currentOrgUnit, currentContract } = useBuyerPortal();
36
+ const { orgUnit } = useOrgUnitBasicData(orgUnitId);
37
+
38
+ const { contract } = useContractDetails(contractId, orgUnitId);
36
39
 
37
40
  const verticalLinks = getContractSettingsLinks({
38
- contractId: currentContract?.id ?? contractId ?? "",
39
- orgUnitId: currentOrgUnit?.id ?? orgUnitId ?? "",
41
+ contractId: contractId,
42
+ orgUnitId: orgUnitId,
40
43
  });
41
44
 
42
45
  return (
43
46
  <BaseTabsLayout data-fs-bp-contract-tabs-layout>
44
47
  <BaseTabsLayout.Navbar
45
- orgUnit={currentOrgUnit}
48
+ orgUnit={orgUnit}
46
49
  pageName={pageName}
47
50
  person={{
48
51
  name: person.name,
@@ -61,7 +64,7 @@ export const ContractTabsLayout = ({
61
64
  </DropdownItem>
62
65
  }
63
66
  verticalLinks={verticalLinks}
64
- name={currentContract?.name ?? ""}
67
+ name={contract?.name ?? ""}
65
68
  />
66
69
  <BaseTabsLayout.Content>{children}</BaseTabsLayout.Content>
67
70
  </BaseTabsLayout.Container>
@@ -36,6 +36,7 @@ const loaderFunction = async (
36
36
  const { orgUnitId } = data.query;
37
37
 
38
38
  const { cookie, userId, ...clientContext } = await getClientContext(data);
39
+ console.log(">>> Org Unit Loader", cookie);
39
40
 
40
41
  return {
41
42
  data: {
@@ -55,6 +56,7 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
55
56
 
56
57
  const OrgUnitDetailsPage = ({
57
58
  data,
59
+ context,
58
60
  hasError,
59
61
  error,
60
62
  }: OrgUnitDetailsPageData) => {
@@ -62,7 +64,8 @@ const OrgUnitDetailsPage = ({
62
64
  return <ErrorTabsLayout error={error} />;
63
65
  }
64
66
 
65
- const { isAuthenticated, isLoading } = useAuth();
67
+ const { isAuthenticated, isLoading } = useAuth(context.clientContext);
68
+ console.log(">> Org Unit Details, auth", isAuthenticated, isLoading);
66
69
 
67
70
  if (isLoading || isAuthenticated === null) {
68
71
  return <PageLoader />;
@@ -57,12 +57,12 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
57
57
  redirectToError: true,
58
58
  });
59
59
 
60
- const ProfilePage = ({ data, hasError, error }: ProfilePageData) => {
60
+ const ProfilePage = ({ data, context, hasError, error }: ProfilePageData) => {
61
61
  if (hasError) {
62
62
  return <ErrorTabsLayout error={error} />;
63
63
  }
64
64
 
65
- const { isAuthenticated, isLoading } = useAuth();
65
+ const { isAuthenticated, isLoading } = useAuth(context.clientContext);
66
66
 
67
67
  if (isLoading || isAuthenticated === null) {
68
68
  return <PageLoader />;