@vtex/faststore-plugin-buyer-portal 1.1.116-poc-9 → 1.2.1

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 (41) hide show
  1. package/package.json +42 -42
  2. package/src/features/addresses/layouts/AddressDetailsLayout/AddressDetailsLayout.tsx +0 -1
  3. package/src/features/addresses/layouts/AddressesLayout/AddressesLayout.tsx +0 -1
  4. package/src/features/budgets/layouts/BudgetsDetailsLayout/BudgetsDetailsLayout.tsx +0 -1
  5. package/src/features/collections/layouts/CollectionsLayout/CollectionsLayout.tsx +0 -1
  6. package/src/features/contracts/hooks/index.ts +0 -2
  7. package/src/features/contracts/services/get-contract-details.service.ts +0 -4
  8. package/src/features/credit-cards/layouts/CreditCardsLayout/CreditCardLayout.tsx +0 -1
  9. package/src/features/custom-fields/layouts/CustomFieldsLayout/CustomFieldsLayout.tsx +0 -1
  10. package/src/features/org-units/clients/OrgUnitClient.ts +15 -2
  11. package/src/features/org-units/components/OrgUnitBreadcrumb/OrgUnitBreadcrumbLink.tsx +0 -1
  12. package/src/features/org-units/hooks/index.ts +0 -1
  13. package/src/features/org-units/layouts/OrgUnitDetailsLayout/OrgUnitDetailsLayout.tsx +29 -32
  14. package/src/features/org-units/services/get-org-unit-basic-data.service.ts +0 -4
  15. package/src/features/org-units/services/get-org-unit-by-user-id.service.ts +0 -4
  16. package/src/features/org-units/types/OrgUnitSummaryData.ts +0 -18
  17. package/src/features/org-units/types/index.ts +0 -2
  18. package/src/features/payment-methods/layouts/PaymentMethodsLayout/PaymentMethodsLayout.tsx +0 -1
  19. package/src/features/profile/layouts/ProfileLayout/ProfileLayout.tsx +16 -46
  20. package/src/features/shared/components/Error/Error.tsx +13 -12
  21. package/src/features/shared/components/index.ts +0 -1
  22. package/src/features/shared/components/withErrorBoundary/withErrorBoundary.tsx +1 -0
  23. package/src/features/shared/hooks/index.ts +0 -2
  24. package/src/features/shared/layouts/ContractTabsLayout/ContractTabsLayout.tsx +9 -14
  25. package/src/features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout.tsx +0 -1
  26. package/src/features/shared/layouts/LoadingTabsLayout/LoadingTabsLayout.tsx +27 -6
  27. package/src/features/shared/utils/withAuthLoader.ts +1 -1
  28. package/src/features/shared/utils/withAuthProvider.tsx +0 -1
  29. package/src/features/shared/utils/withProviders.tsx +2 -1
  30. package/src/features/users/services/get-user-by-id.service.ts +0 -4
  31. package/src/pages/org-unit-details.tsx +62 -42
  32. package/src/pages/profile.tsx +64 -48
  33. package/src/themes/index.scss +0 -1
  34. package/src/features/contracts/hooks/useContractDetails.ts +0 -22
  35. package/src/features/contracts/hooks/useContractsByOrgUnitId.ts +0 -20
  36. package/src/features/org-units/hooks/useOrgUnitBasicData.ts +0 -20
  37. package/src/features/shared/components/PageLoader/PageLoader.tsx +0 -47
  38. package/src/features/shared/components/PageLoader/index.ts +0 -1
  39. package/src/features/shared/components/PageLoader/page-loader.scss +0 -22
  40. package/src/features/shared/hooks/useAuth.ts +0 -50
  41. package/src/features/shared/hooks/useCookieMonitor.ts +0 -73
@@ -2,9 +2,8 @@ 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";
7
5
  import { Icon } from "../../components";
6
+ import { useBuyerPortal } from "../../hooks";
8
7
  import { getContractSettingsLinks } from "../../utils";
9
8
  import { BaseTabsLayout } from "../BaseTabsLayout/BaseTabsLayout";
10
9
 
@@ -19,7 +18,6 @@ export type ContractTabsLayoutProps = {
19
18
  image?: ReactNode;
20
19
  name: string;
21
20
  role?: string;
22
- id: string;
23
21
  };
24
22
  loading?: boolean;
25
23
  children?: ReactNode;
@@ -31,26 +29,23 @@ export const ContractTabsLayout = ({
31
29
  children,
32
30
  orgUnitId,
33
31
  contractId,
34
- person,
35
32
  }: ContractTabsLayoutProps) => {
36
- const { orgUnit } = useOrgUnitBasicData(orgUnitId);
37
-
38
- const { contract } = useContractDetails(contractId, orgUnitId);
33
+ const { currentOrgUnit, currentUser, currentContract } = useBuyerPortal();
39
34
 
40
35
  const verticalLinks = getContractSettingsLinks({
41
- contractId: contractId,
42
- orgUnitId: orgUnitId,
36
+ contractId: currentContract?.id ?? contractId ?? "",
37
+ orgUnitId: currentOrgUnit?.id ?? orgUnitId ?? "",
43
38
  });
44
39
 
45
40
  return (
46
41
  <BaseTabsLayout data-fs-bp-contract-tabs-layout>
47
42
  <BaseTabsLayout.Navbar
48
- orgUnit={orgUnit}
43
+ orgUnit={currentOrgUnit}
49
44
  pageName={pageName}
50
45
  person={{
51
- name: person.name,
52
- role: person.role,
53
- id: person.id,
46
+ name: currentUser?.name ?? "",
47
+ role: currentUser?.role ?? "",
48
+ id: currentUser?.id ?? "",
54
49
  }}
55
50
  loading={loading}
56
51
  />
@@ -64,7 +59,7 @@ export const ContractTabsLayout = ({
64
59
  </DropdownItem>
65
60
  }
66
61
  verticalLinks={verticalLinks}
67
- name={contract?.name ?? ""}
62
+ name={currentContract?.name ?? ""}
68
63
  />
69
64
  <BaseTabsLayout.Content>{children}</BaseTabsLayout.Content>
70
65
  </BaseTabsLayout.Container>
@@ -82,7 +82,6 @@ export const ErrorTabsLayout = ({ children, error }: ErrorTabsLayoutProps) => {
82
82
  image: undefined,
83
83
  name: user?.name ?? "",
84
84
  role: user?.role ?? "",
85
- id: user?.id ?? "",
86
85
  }}
87
86
  >
88
87
  <ErrorTabsLayoutContent title={pageTitle} error={error} />
@@ -33,8 +33,6 @@ export const LoadingTabsLayoutContent = ({
33
33
  );
34
34
 
35
35
  export const LoadingTabsLayout = ({ children }: LoadingTabsLayoutProps) => {
36
- console.log("Enter loading layout");
37
-
38
36
  const { routerLoading, nextRoute } = useRouterLoading();
39
37
  const [shouldShowLoading, setShouldShowLoading] = useState(false);
40
38
  const wasLoadingRef = useRef(false);
@@ -67,8 +65,6 @@ export const LoadingTabsLayout = ({ children }: LoadingTabsLayoutProps) => {
67
65
 
68
66
  const pageTitle = layoutConfig.pageTitle;
69
67
 
70
- console.log(">>>TabsLayout", layoutConfig.layout);
71
-
72
68
  switch (layoutConfig.layout) {
73
69
  case "ContractTabsLayout":
74
70
  return (
@@ -82,7 +78,6 @@ export const LoadingTabsLayout = ({ children }: LoadingTabsLayoutProps) => {
82
78
  image: undefined,
83
79
  name: "",
84
80
  role: "",
85
- id: "",
86
81
  }}
87
82
  loading={true}
88
83
  >
@@ -105,7 +100,33 @@ export const LoadingTabsLayout = ({ children }: LoadingTabsLayoutProps) => {
105
100
  );
106
101
 
107
102
  case "OrgUnitDetailsLayout":
108
- return <OrgUnitsDetailsLayout loading={true} orgUnitId="" userId="" />;
103
+ return (
104
+ <OrgUnitsDetailsLayout
105
+ loading={true}
106
+ data={{
107
+ contracts: [],
108
+ orgUnit: {
109
+ contractMode: "Single",
110
+ customerGroup: { customerIds: [] },
111
+ id: routeParams.orgUnitId,
112
+ name: "",
113
+ path: {
114
+ ids: "",
115
+ names: "",
116
+ },
117
+ },
118
+ user: {
119
+ name: "",
120
+ roles: [],
121
+ id: "",
122
+ orgUnit: {
123
+ id: routeParams.orgUnitId,
124
+ name: "",
125
+ },
126
+ },
127
+ }}
128
+ />
129
+ );
109
130
 
110
131
  default:
111
132
  return <LoadingTabsLayoutContent />;
@@ -35,7 +35,7 @@ export const withAuthLoader = async <T>(
35
35
  clientContext: { cookie, userId, ...clientContext },
36
36
  };
37
37
  } catch (error) {
38
- console.error("[withAuthLoader] Auth validation failed:", error);
38
+ console.error("Auth validation failed:", error);
39
39
 
40
40
  data.res?.writeHead(302, { Location: "/" });
41
41
  data.res?.end();
@@ -28,7 +28,6 @@ export const withAuthProvider = <T,>(
28
28
  return null;
29
29
  }
30
30
 
31
- // Se autorizado, renderiza o componente envolvido no provider
32
31
  return (
33
32
  <BuyerPortalProvider clientContext={props?.clientContext}>
34
33
  <Component {...props.data} clientContext={props?.clientContext} />
@@ -1,5 +1,6 @@
1
1
  import { type ComponentType } from "react";
2
2
 
3
+ import { withAuth } from "./withAuth";
3
4
  import { withBuyerPortal } from "./withBuyerPortal";
4
5
 
5
6
  /**
@@ -13,7 +14,7 @@ type ProviderHOC = (Component: ComponentType<any>) => ComponentType<any>;
13
14
  * Default project providers applied to all pages.
14
15
  * Order: right to left (like pipe/compose)
15
16
  */
16
- const projectProviders: ProviderHOC[] = [withBuyerPortal];
17
+ const projectProviders: ProviderHOC[] = [withAuth, withBuyerPortal];
17
18
 
18
19
  /**
19
20
  * HOC that applies all default project providers.
@@ -12,10 +12,6 @@ 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
-
19
15
  const { email, name, orgUnit, role } = await usersClient.getUserById(
20
16
  orgUnitId,
21
17
  userId,
@@ -1,81 +1,101 @@
1
+ import { getContractsByOrgUnitIdService } from "../features/contracts/services";
1
2
  import { OrgUnitsDetailsLayout } from "../features/org-units/layouts";
3
+ import { getOrgUnitBasicDataService } from "../features/org-units/services";
2
4
  import { withErrorBoundary } from "../features/shared/components";
3
- import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
4
- import { useAuth } from "../features/shared/hooks";
5
5
  import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
6
6
  import {
7
+ type ClientContext,
7
8
  withLoaderErrorBoundary,
9
+ withAuthLoader,
8
10
  withProviders,
9
11
  } from "../features/shared/utils";
10
- import {
11
- ClientContext,
12
- getClientContext,
13
- } from "../features/shared/utils/getClientContext";
12
+ import { getUserByIdService } from "../features/users/services";
14
13
 
15
- import type { LoaderData } from "../features/shared/types";
14
+ import type { ContractData } from "../features/contracts/types";
15
+ import type { OrgUnitBasicData } from "../features/org-units/types";
16
+ import type { AuthRouteProps, LoaderData } from "../features/shared/types";
17
+ import type { UserData } from "../features/users/types";
16
18
 
17
19
  export type OrgUnitDetailsPageData = {
18
20
  data: {
19
- orgUnitId: string;
20
- userId: string;
21
- cookie: string;
22
- curPayload: any;
21
+ orgUnit: OrgUnitBasicData;
22
+ contracts: ContractData[];
23
+ user: UserData | null;
23
24
  };
24
25
  context: {
25
26
  clientContext: ClientContext;
26
27
  };
27
28
  hasError?: boolean;
28
- error?: ErrorBoundaryProps;
29
+ error?: {
30
+ error: {
31
+ message: string;
32
+ name: string;
33
+ stack?: string;
34
+ };
35
+ tags: {
36
+ component: string;
37
+ errorType: string;
38
+ };
39
+ };
29
40
  };
30
41
 
31
42
  type OrgUnitDetailsPageQuery = {
32
43
  orgUnitId: string;
33
- cookie: string;
34
44
  };
35
45
 
36
- export async function loader(
46
+ const loaderFunction = async (
37
47
  data: LoaderData<OrgUnitDetailsPageQuery>
38
- ): Promise<OrgUnitDetailsPageData> {
48
+ ): Promise<AuthRouteProps<OrgUnitDetailsPageData>> => {
39
49
  const { orgUnitId } = data.query;
40
50
 
41
- const { cookie, userId, ...clientContext } = await getClientContext(data);
51
+ if (!orgUnitId) {
52
+ throw new Error(`Missing required query param: orgUnitId=${orgUnitId}`);
53
+ }
42
54
 
43
- return {
44
- data: {
55
+ return withAuthLoader(data, async ({ cookie, userId, ...clientContext }) => {
56
+ const orgUnit = await getOrgUnitBasicDataService({
57
+ id: orgUnitId,
58
+ cookie,
59
+ });
60
+
61
+ const user = await getUserByIdService({ orgUnitId, userId, cookie });
62
+
63
+ const contracts = await getContractsByOrgUnitIdService({
45
64
  orgUnitId,
46
- userId,
47
65
  cookie,
48
- curPayload: data.req.cookies,
49
- },
50
- context: {
51
- clientContext: { cookie, userId, ...clientContext },
52
- },
53
- };
54
- }
66
+ });
67
+
68
+ return {
69
+ data: {
70
+ contracts,
71
+ orgUnit,
72
+ user,
73
+ },
74
+ context: {
75
+ clientContext: { cookie, userId, ...clientContext },
76
+ },
77
+ };
78
+ });
79
+ };
55
80
 
56
- // export const loader = withLoaderErrorBoundary(loaderFunction, {
57
- // componentName: "OrgUnitDetailsPage",
58
- // redirectToError: true,
59
- // });
81
+ export const loader = withLoaderErrorBoundary(loaderFunction, {
82
+ componentName: "OrgUnitDetailsPage",
83
+ redirectToError: true,
84
+ });
60
85
 
61
86
  const OrgUnitDetailsPage = ({
62
87
  data,
63
88
  hasError,
64
89
  error,
65
90
  }: OrgUnitDetailsPageData) => {
66
- if (hasError) {
67
- return <ErrorTabsLayout error={error} />;
68
- }
69
-
70
- const { isAuthenticated, isLoading } = useAuth(data.cookie);
71
- console.log(">> Context", data.cookie);
72
-
73
- if (isLoading || isAuthenticated === null) {
74
- return <OrgUnitsDetailsLayout loading={true} orgUnitId="" userId="" />;
75
- }
76
-
77
91
  return (
78
- <OrgUnitsDetailsLayout orgUnitId={data.orgUnitId} userId={data.userId} />
92
+ <>
93
+ {hasError ? (
94
+ <ErrorTabsLayout error={error} />
95
+ ) : (
96
+ <OrgUnitsDetailsLayout data={data} />
97
+ )}
98
+ </>
79
99
  );
80
100
  };
81
101
 
@@ -1,26 +1,29 @@
1
+ import { getContractDetailsService } from "../features/contracts/services";
2
+ import { getOrgUnitBasicDataService } from "../features/org-units/services";
1
3
  import { ProfileLayout } from "../features/profile/layouts";
2
- import { PageLoader, withErrorBoundary } from "../features/shared/components";
4
+ import { withErrorBoundary } from "../features/shared/components";
3
5
  import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
4
- import { useAuth } from "../features/shared/hooks";
5
6
  import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
6
7
  import {
7
8
  type ClientContext,
8
- withProviders,
9
- getClientContext,
10
9
  withLoaderErrorBoundary,
10
+ withAuthLoader,
11
+ withProviders,
11
12
  } from "../features/shared/utils";
13
+ import { getUserByIdService } from "../features/users/services";
12
14
 
13
- import type { LoaderData } from "../features/shared/types";
15
+ import type { ContractData } from "../features/contracts/types";
16
+ import type { OrgUnitBasicData } from "../features/org-units/types";
17
+ import type { AuthRouteProps, LoaderData } from "../features/shared/types";
18
+ import type { UserData } from "../features/users/types";
14
19
 
15
20
  export type ProfilePageData = {
16
- data: {
17
- contractId: string;
18
- orgUnitId: string;
19
- userId: string;
20
- cookie: string;
21
- };
21
+ data: ContractData | null;
22
22
  context: {
23
23
  clientContext: ClientContext;
24
+ currentOrgUnit: OrgUnitBasicData | null;
25
+ currentContract: ContractData | null;
26
+ currentUser: UserData | null;
24
27
  };
25
28
  hasError?: boolean;
26
29
  error?: ErrorBoundaryProps;
@@ -29,55 +32,68 @@ export type ProfilePageData = {
29
32
  export type ProfilePageQuery = {
30
33
  contractId: string;
31
34
  orgUnitId: string;
32
- userId: string;
33
35
  };
34
36
 
35
- const loaderFunction = async (
37
+ export async function loaderFunction(
36
38
  data: LoaderData<ProfilePageQuery>
37
- ): Promise<ProfilePageData> => {
39
+ ): Promise<AuthRouteProps<ProfilePageData>> {
38
40
  const { contractId, orgUnitId } = data.query;
39
41
 
40
- const { cookie, userId, ...clientContext } = await getClientContext(data);
42
+ return withAuthLoader(
43
+ data,
44
+ async ({ customerId, cookie, userId, ...clientContext }) => {
45
+ if (!contractId || !orgUnitId) {
46
+ return {
47
+ data: null,
48
+ context: {
49
+ clientContext: { customerId, cookie, userId, ...clientContext },
50
+ currentOrgUnit: null,
51
+ currentContract: null,
52
+ currentUser: null,
53
+ },
54
+ };
55
+ }
41
56
 
42
- return {
43
- data: {
44
- contractId,
45
- orgUnitId,
46
- userId,
47
- cookie,
48
- },
49
- context: {
50
- clientContext: { cookie, userId, ...clientContext },
51
- },
52
- hasError: false,
53
- error: undefined,
54
- };
55
- };
57
+ const [orgUnit, contract, user] = await Promise.all([
58
+ getOrgUnitBasicDataService({
59
+ cookie,
60
+ id: orgUnitId,
61
+ }),
62
+ getContractDetailsService({
63
+ contractId,
64
+ cookie,
65
+ unitId: orgUnitId,
66
+ }),
67
+ getUserByIdService({ orgUnitId, userId, cookie }),
68
+ ]);
69
+
70
+ return {
71
+ data: contract,
72
+ context: {
73
+ clientContext: { customerId, cookie, userId, ...clientContext },
74
+ currentOrgUnit: orgUnit,
75
+ currentContract: contract,
76
+ currentUser: user,
77
+ },
78
+ };
79
+ }
80
+ );
81
+ }
56
82
 
57
83
  export const loader = withLoaderErrorBoundary(loaderFunction, {
58
84
  componentName: "ProfilePage",
59
85
  redirectToError: true,
60
86
  });
61
87
 
62
- const ProfilePage = ({ data, hasError, error }: ProfilePageData) => {
63
- if (hasError) {
64
- return <ErrorTabsLayout error={error} />;
65
- }
66
-
67
- const { isAuthenticated, isLoading } = useAuth(data.cookie);
68
-
69
- if (isLoading || isAuthenticated === null) {
70
- return <PageLoader />;
71
- }
72
-
73
- return (
74
- <ProfileLayout
75
- orgUnitId={data.orgUnitId}
76
- contractId={data.contractId}
77
- userId={data.userId}
78
- />
79
- );
80
- };
88
+ const ProfilePage = ({ data, hasError, error }: ProfilePageData) => (
89
+ <>
90
+ {hasError ? (
91
+ <ErrorTabsLayout error={error} />
92
+ ) : (
93
+ <ProfileLayout data={data} />
94
+ )}
95
+ </>
96
+ );
81
97
 
82
98
  export default withProviders(
83
99
  withErrorBoundary(ProfilePage, {
@@ -1,5 +1,4 @@
1
1
  @import "../features/profile/components/ProfileSummary/profile-summary.scss";
2
- @import "../features/shared/components/PageLoader/page-loader.scss";
3
2
  @import "./layouts";
4
3
 
5
4
  // ----------------------------------------------------------
@@ -1,22 +0,0 @@
1
- import { type QueryOptions, useQuery } from "../../shared/hooks";
2
- import { getContractDetailsService } from "../services";
3
-
4
- export const useContractDetails = (
5
- contractId: string,
6
- unitId: string,
7
- options?: QueryOptions<AwaitedType<typeof getContractDetailsService>>
8
- ) => {
9
- const { data, error, isLoading, refetch } = useQuery(
10
- `api/contract-details/${unitId}`,
11
- ({ cookie }) =>
12
- getContractDetailsService({ contractId, cookie, unitId: unitId }),
13
- options
14
- );
15
-
16
- return {
17
- contract: data,
18
- hasContractError: error,
19
- isContractLoading: isLoading,
20
- refetchContract: refetch,
21
- };
22
- };
@@ -1,20 +0,0 @@
1
- import { type QueryOptions, useQuery } from "../../shared/hooks";
2
- import { getContractsByOrgUnitIdService } from "../services";
3
-
4
- export const useContractsByOrgUnitId = (
5
- orgUnitId: string,
6
- options?: QueryOptions<AwaitedType<typeof getContractsByOrgUnitIdService>>
7
- ) => {
8
- const { data, error, isLoading, refetch } = useQuery(
9
- `api/contracts-by-org-unit-id/${orgUnitId}`,
10
- ({ cookie }) => getContractsByOrgUnitIdService({ orgUnitId, cookie }),
11
- options
12
- );
13
-
14
- return {
15
- contracts: data ?? [],
16
- hasContractsError: error,
17
- isContractsLoading: isLoading,
18
- refetchContracts: refetch,
19
- };
20
- };
@@ -1,20 +0,0 @@
1
- import { type QueryOptions, useQuery } from "../../shared/hooks";
2
- import { getOrgUnitBasicDataService } from "../services";
3
-
4
- export const useOrgUnitBasicData = (
5
- id: string,
6
- options?: QueryOptions<AwaitedType<typeof getOrgUnitBasicDataService>>
7
- ) => {
8
- const { data, error, isLoading, refetch } = useQuery(
9
- `api/org-unit-basic-data/${id}`,
10
- ({ cookie }) => getOrgUnitBasicDataService({ id, cookie }),
11
- options
12
- );
13
-
14
- return {
15
- orgUnit: data,
16
- hasOrgUnitError: error,
17
- isOrgUnitLoading: isLoading,
18
- refetchOrgUnit: refetch,
19
- };
20
- };
@@ -1,47 +0,0 @@
1
- import { Skeleton } from "@faststore/ui";
2
-
3
- import { useBuyerPortal } from "../../hooks";
4
- import { BaseTabsLayout } from "../../layouts";
5
-
6
- /**
7
- * PageLoader component displays skeleton loaders while page data is being fetched.
8
- * Used when cookies are not yet available during pre-fetch scenarios.
9
- */
10
- export const PageLoader = () => {
11
- const { currentOrgUnit, currentUser } = useBuyerPortal();
12
- return (
13
- <BaseTabsLayout data-fs-bp-page-loader>
14
- <BaseTabsLayout.Navbar
15
- orgUnit={currentOrgUnit}
16
- pageName="Loading"
17
- person={{
18
- name: currentUser?.name ?? "",
19
- role: currentUser?.role ?? "",
20
- id: currentUser?.id ?? "",
21
- }}
22
- loading={true}
23
- />
24
- <BaseTabsLayout.Container>
25
- <BaseTabsLayout.SidebarMenu
26
- verticalLinks={[]}
27
- showLetterHighlight={false}
28
- loading={true}
29
- />
30
- <BaseTabsLayout.Content>
31
- <div data-fs-bp-page-loader>
32
- <div data-fs-bp-page-loader-header>
33
- <Skeleton size={{ width: "12rem", height: "2rem" }} />
34
- <Skeleton size={{ width: "8rem", height: "1.5rem" }} />
35
- </div>
36
-
37
- <div data-fs-bp-page-loader-content>
38
- <Skeleton size={{ width: "100%", height: "4rem" }} />
39
- <Skeleton size={{ width: "100%", height: "8rem" }} />
40
- <Skeleton size={{ width: "100%", height: "8rem" }} />
41
- </div>
42
- </div>
43
- </BaseTabsLayout.Content>
44
- </BaseTabsLayout.Container>
45
- </BaseTabsLayout>
46
- );
47
- };
@@ -1 +0,0 @@
1
- export { PageLoader } from "./PageLoader";
@@ -1,22 +0,0 @@
1
- @import "@faststore/ui/src/components/atoms/Skeleton/styles.scss";
2
-
3
- [data-fs-bp-page-loader] {
4
- padding: var(--fs-spacing-3);
5
- width: 100%;
6
- min-height: 100vh;
7
- display: flex;
8
- flex-direction: column;
9
- gap: var(--fs-spacing-4);
10
- }
11
-
12
- [data-fs-bp-page-loader-header] {
13
- display: flex;
14
- flex-direction: column;
15
- gap: var(--fs-spacing-2);
16
- }
17
-
18
- [data-fs-bp-page-loader-content] {
19
- display: flex;
20
- flex-direction: column;
21
- gap: var(--fs-spacing-3);
22
- }
@@ -1,50 +0,0 @@
1
- import { useEffect, useState } from "react";
2
-
3
- import { useRouter } from "next/router";
4
-
5
- import { authClient } from "../clients/Auth";
6
- export type UseAuthResult = {
7
- isAuthenticated: boolean | null;
8
- isLoading: boolean;
9
- };
10
-
11
- /**
12
- * Client-side hook to validate user authentication.
13
- * Checks access with the server and redirects to home if unauthorized.
14
- *
15
- * @returns Object containing authentication status and loading state
16
- */
17
- export const useAuth = (cookie: string): UseAuthResult => {
18
- const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
19
- const [isLoading, setIsLoading] = useState(true);
20
- const router = useRouter();
21
-
22
- useEffect(() => {
23
- const validateAccess = async () => {
24
- setIsLoading(true);
25
-
26
- try {
27
- const hasAccess = await authClient.validateAccess({ cookie });
28
-
29
- if (!hasAccess) {
30
- router.push("/");
31
- setIsAuthenticated(false);
32
- } else {
33
- setIsAuthenticated(true);
34
- }
35
- } catch {
36
- router.push("/");
37
- setIsAuthenticated(false);
38
- } finally {
39
- setIsLoading(false);
40
- }
41
- };
42
-
43
- validateAccess();
44
- }, [router]);
45
-
46
- return {
47
- isAuthenticated,
48
- isLoading,
49
- };
50
- };