@vtex/faststore-plugin-buyer-portal 1.1.115 → 1.1.116-poc-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.
- package/package.json +42 -42
- package/src/features/addresses/layouts/AddressDetailsLayout/AddressDetailsLayout.tsx +1 -0
- package/src/features/addresses/layouts/AddressesLayout/AddressesLayout.tsx +1 -0
- package/src/features/budgets/layouts/BudgetsDetailsLayout/BudgetsDetailsLayout.tsx +1 -0
- package/src/features/collections/layouts/CollectionsLayout/CollectionsLayout.tsx +1 -0
- package/src/features/contracts/hooks/index.ts +2 -0
- package/src/features/contracts/hooks/useContractDetails.ts +22 -0
- package/src/features/contracts/hooks/useContractsByOrgUnitId.ts +20 -0
- package/src/features/credit-cards/layouts/CreditCardsLayout/CreditCardLayout.tsx +1 -0
- package/src/features/custom-fields/layouts/CustomFieldsLayout/CustomFieldsLayout.tsx +1 -0
- package/src/features/org-units/hooks/index.ts +1 -0
- package/src/features/org-units/hooks/useOrgUnitBasicData.ts +20 -0
- package/src/features/org-units/layouts/OrgUnitDetailsLayout/OrgUnitDetailsLayout.tsx +31 -28
- package/src/features/payment-methods/layouts/PaymentMethodsLayout/PaymentMethodsLayout.tsx +1 -0
- package/src/features/profile/layouts/ProfileLayout/ProfileLayout.tsx +33 -16
- package/src/features/shared/components/Error/Error.tsx +12 -13
- package/src/features/shared/components/PageLoader/PageLoader.tsx +36 -11
- package/src/features/shared/components/withErrorBoundary/withErrorBoundary.tsx +6 -7
- package/src/features/shared/hooks/index.ts +1 -0
- package/src/features/shared/hooks/useAuth.ts +54 -0
- package/src/features/shared/hooks/useCookieMonitor.ts +2 -6
- package/src/features/shared/layouts/ContractTabsLayout/ContractTabsLayout.tsx +6 -4
- package/src/features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout.tsx +1 -0
- package/src/features/shared/layouts/LoadingTabsLayout/LoadingTabsLayout.tsx +2 -27
- package/src/features/shared/types/AuthRouteProps.ts +2 -8
- package/src/features/shared/utils/withAuth.tsx +10 -62
- package/src/features/shared/utils/withAuthLoader.ts +0 -28
- package/src/features/shared/utils/withAuthProvider.tsx +11 -81
- package/src/features/shared/utils/withLoaderErrorBoundary.ts +71 -79
- package/src/features/shared/utils/withProviders.tsx +1 -2
- package/src/pages/org-unit-details.tsx +32 -58
- package/src/pages/profile.tsx +46 -64
|
@@ -1,42 +1,29 @@
|
|
|
1
|
-
import { getContractsByOrgUnitIdService } from "../features/contracts/services";
|
|
2
1
|
import { OrgUnitsDetailsLayout } from "../features/org-units/layouts";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { PageLoader, 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,
|
|
8
7
|
withLoaderErrorBoundary,
|
|
9
|
-
withAuthLoader,
|
|
10
8
|
withProviders,
|
|
11
9
|
} from "../features/shared/utils";
|
|
12
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
ClientContext,
|
|
12
|
+
getClientContext,
|
|
13
|
+
} from "../features/shared/utils/getClientContext";
|
|
13
14
|
|
|
14
|
-
import type {
|
|
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";
|
|
15
|
+
import type { LoaderData } from "../features/shared/types";
|
|
18
16
|
|
|
19
17
|
export type OrgUnitDetailsPageData = {
|
|
20
18
|
data: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
user: UserData | null;
|
|
19
|
+
orgUnitId: string;
|
|
20
|
+
userId: string;
|
|
24
21
|
};
|
|
25
22
|
context: {
|
|
26
23
|
clientContext: ClientContext;
|
|
27
24
|
};
|
|
28
25
|
hasError?: boolean;
|
|
29
|
-
error?:
|
|
30
|
-
error: {
|
|
31
|
-
message: string;
|
|
32
|
-
name: string;
|
|
33
|
-
stack?: string;
|
|
34
|
-
};
|
|
35
|
-
tags: {
|
|
36
|
-
component: string;
|
|
37
|
-
errorType: string;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
26
|
+
error?: ErrorBoundaryProps;
|
|
40
27
|
};
|
|
41
28
|
|
|
42
29
|
type OrgUnitDetailsPageQuery = {
|
|
@@ -45,37 +32,20 @@ type OrgUnitDetailsPageQuery = {
|
|
|
45
32
|
|
|
46
33
|
const loaderFunction = async (
|
|
47
34
|
data: LoaderData<OrgUnitDetailsPageQuery>
|
|
48
|
-
): Promise<
|
|
35
|
+
): Promise<OrgUnitDetailsPageData> => {
|
|
49
36
|
const { orgUnitId } = data.query;
|
|
50
37
|
|
|
51
|
-
|
|
52
|
-
throw new Error(`Missing required query param: orgUnitId=${orgUnitId}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
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 });
|
|
38
|
+
const { cookie, userId, ...clientContext } = await getClientContext(data);
|
|
62
39
|
|
|
63
|
-
|
|
40
|
+
return {
|
|
41
|
+
data: {
|
|
64
42
|
orgUnitId,
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
orgUnit,
|
|
72
|
-
user,
|
|
73
|
-
},
|
|
74
|
-
context: {
|
|
75
|
-
clientContext: { cookie, userId, ...clientContext },
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
});
|
|
43
|
+
userId,
|
|
44
|
+
},
|
|
45
|
+
context: {
|
|
46
|
+
clientContext: { cookie, userId, ...clientContext },
|
|
47
|
+
},
|
|
48
|
+
};
|
|
79
49
|
};
|
|
80
50
|
|
|
81
51
|
export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
@@ -88,14 +58,18 @@ const OrgUnitDetailsPage = ({
|
|
|
88
58
|
hasError,
|
|
89
59
|
error,
|
|
90
60
|
}: OrgUnitDetailsPageData) => {
|
|
61
|
+
if (hasError) {
|
|
62
|
+
return <ErrorTabsLayout error={error} />;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
66
|
+
|
|
67
|
+
if (isLoading || isAuthenticated === null) {
|
|
68
|
+
return <PageLoader />;
|
|
69
|
+
}
|
|
70
|
+
|
|
91
71
|
return (
|
|
92
|
-
|
|
93
|
-
{hasError ? (
|
|
94
|
-
<ErrorTabsLayout error={error} />
|
|
95
|
-
) : (
|
|
96
|
-
<OrgUnitsDetailsLayout data={data} />
|
|
97
|
-
)}
|
|
98
|
-
</>
|
|
72
|
+
<OrgUnitsDetailsLayout orgUnitId={data.orgUnitId} userId={data.userId} />
|
|
99
73
|
);
|
|
100
74
|
};
|
|
101
75
|
|
package/src/pages/profile.tsx
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
import { getContractDetailsService } from "../features/contracts/services";
|
|
2
|
-
import { getOrgUnitBasicDataService } from "../features/org-units/services";
|
|
3
1
|
import { ProfileLayout } from "../features/profile/layouts";
|
|
4
|
-
import { withErrorBoundary } from "../features/shared/components";
|
|
2
|
+
import { PageLoader, withErrorBoundary } from "../features/shared/components";
|
|
5
3
|
import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
|
|
4
|
+
import { useAuth } from "../features/shared/hooks";
|
|
6
5
|
import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
|
|
7
6
|
import {
|
|
8
7
|
type ClientContext,
|
|
9
|
-
withLoaderErrorBoundary,
|
|
10
|
-
withAuthLoader,
|
|
11
8
|
withProviders,
|
|
9
|
+
getClientContext,
|
|
10
|
+
withLoaderErrorBoundary,
|
|
12
11
|
} from "../features/shared/utils";
|
|
13
|
-
import { getUserByIdService } from "../features/users/services";
|
|
14
12
|
|
|
15
|
-
import type {
|
|
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";
|
|
13
|
+
import type { LoaderData } from "../features/shared/types";
|
|
19
14
|
|
|
20
15
|
export type ProfilePageData = {
|
|
21
|
-
data:
|
|
16
|
+
data: {
|
|
17
|
+
contractId: string;
|
|
18
|
+
orgUnitId: string;
|
|
19
|
+
userId: string;
|
|
20
|
+
};
|
|
22
21
|
context: {
|
|
23
22
|
clientContext: ClientContext;
|
|
24
|
-
currentOrgUnit: OrgUnitBasicData | null;
|
|
25
|
-
currentContract: ContractData | null;
|
|
26
|
-
currentUser: UserData | null;
|
|
27
23
|
};
|
|
28
24
|
hasError?: boolean;
|
|
29
25
|
error?: ErrorBoundaryProps;
|
|
@@ -32,68 +28,54 @@ export type ProfilePageData = {
|
|
|
32
28
|
export type ProfilePageQuery = {
|
|
33
29
|
contractId: string;
|
|
34
30
|
orgUnitId: string;
|
|
31
|
+
userId: string;
|
|
35
32
|
};
|
|
36
33
|
|
|
37
|
-
|
|
34
|
+
const loaderFunction = async (
|
|
38
35
|
data: LoaderData<ProfilePageQuery>
|
|
39
|
-
): Promise<
|
|
36
|
+
): Promise<ProfilePageData> => {
|
|
40
37
|
const { contractId, orgUnitId } = data.query;
|
|
41
38
|
|
|
42
|
-
|
|
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
|
-
}
|
|
56
|
-
|
|
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
|
-
]);
|
|
39
|
+
const { cookie, userId, ...clientContext } = await getClientContext(data);
|
|
69
40
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
41
|
+
return {
|
|
42
|
+
data: {
|
|
43
|
+
contractId,
|
|
44
|
+
orgUnitId,
|
|
45
|
+
userId,
|
|
46
|
+
},
|
|
47
|
+
context: {
|
|
48
|
+
clientContext: { cookie, userId, ...clientContext },
|
|
49
|
+
},
|
|
50
|
+
hasError: false,
|
|
51
|
+
error: undefined,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
82
54
|
|
|
83
55
|
export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
84
56
|
componentName: "ProfilePage",
|
|
85
57
|
redirectToError: true,
|
|
86
58
|
});
|
|
87
59
|
|
|
88
|
-
const ProfilePage = ({ data, hasError, error }: ProfilePageData) =>
|
|
89
|
-
|
|
90
|
-
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
60
|
+
const ProfilePage = ({ data, hasError, error }: ProfilePageData) => {
|
|
61
|
+
if (hasError) {
|
|
62
|
+
return <ErrorTabsLayout error={error} />;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
66
|
+
|
|
67
|
+
if (isLoading || isAuthenticated === null) {
|
|
68
|
+
return <PageLoader />;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<ProfileLayout
|
|
73
|
+
orgUnitId={data.orgUnitId}
|
|
74
|
+
contractId={data.contractId}
|
|
75
|
+
userId={data.userId}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
97
79
|
|
|
98
80
|
export default withProviders(
|
|
99
81
|
withErrorBoundary(ProfilePage, {
|