@vtex/faststore-plugin-buyer-portal 1.1.107 → 1.1.108
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 +1 -1
- package/src/features/custom-fields/layouts/CustomFieldsLayout/CustomFieldsLayout.tsx +1 -0
- package/src/features/shared/clients/Auth.ts +25 -0
- package/src/features/shared/clients/Client.ts +11 -1
- package/src/features/shared/services/index.ts +4 -0
- package/src/features/shared/services/validate-access.service.ts +11 -0
- package/src/features/shared/types/AuthRouteProps.ts +5 -0
- package/src/features/shared/types/index.ts +1 -0
- package/src/features/shared/utils/constants.ts +4 -4
- package/src/features/shared/utils/index.ts +5 -0
- package/src/features/shared/utils/withAuth.tsx +31 -0
- package/src/features/shared/utils/withAuthLoader.ts +47 -0
- package/src/features/shared/utils/withAuthProvider.tsx +38 -0
- package/src/features/shared/utils/withBuyerPortal.tsx +24 -0
- package/src/features/shared/utils/withProviders.tsx +35 -0
- package/src/pages/address-details.tsx +95 -91
- package/src/pages/addresses.tsx +63 -63
- package/src/pages/budgets-details.tsx +44 -43
- package/src/pages/budgets.tsx +58 -56
- package/src/pages/buying-policies.tsx +84 -78
- package/src/pages/buying-policy-details.tsx +43 -44
- package/src/pages/collections.tsx +59 -60
- package/src/pages/cost-centers.tsx +48 -51
- package/src/pages/credit-cards.tsx +44 -49
- package/src/pages/home.tsx +28 -23
- package/src/pages/org-unit-details.tsx +39 -36
- package/src/pages/org-units.tsx +86 -90
- package/src/pages/payment-methods.tsx +41 -42
- package/src/pages/po-numbers.tsx +43 -46
- package/src/pages/profile.tsx +54 -52
- package/src/pages/releases.tsx +43 -41
- package/src/pages/role-details.tsx +57 -60
- package/src/pages/roles.tsx +42 -39
- package/src/pages/user-details.tsx +58 -58
- package/src/pages/users.tsx +83 -80
|
@@ -2,16 +2,14 @@ import { BuyingPolicyDetailsLayout } from "../features/buying-policies/layouts/B
|
|
|
2
2
|
import { getBuyingPolicyService } from "../features/buying-policies/services";
|
|
3
3
|
import { getContractDetailsService } from "../features/contracts/services";
|
|
4
4
|
import { getOrgUnitBasicDataService } from "../features/org-units/services";
|
|
5
|
-
import {
|
|
6
|
-
BuyerPortalProvider,
|
|
7
|
-
withErrorBoundary,
|
|
8
|
-
} from "../features/shared/components";
|
|
5
|
+
import { withErrorBoundary } from "../features/shared/components";
|
|
9
6
|
import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
|
|
10
7
|
import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
|
|
11
8
|
import {
|
|
12
9
|
type ClientContext,
|
|
13
|
-
getClientContext,
|
|
14
10
|
withLoaderErrorBoundary,
|
|
11
|
+
withAuthLoader,
|
|
12
|
+
withProviders,
|
|
15
13
|
} from "../features/shared/utils";
|
|
16
14
|
import { getUserByIdService } from "../features/users/services";
|
|
17
15
|
|
|
@@ -19,7 +17,7 @@ import type { GetAddressesServiceProps } from "../features/addresses/services";
|
|
|
19
17
|
import type { BuyingPolicy } from "../features/buying-policies/types";
|
|
20
18
|
import type { ContractData } from "../features/contracts/types";
|
|
21
19
|
import type { OrgUnitBasicData } from "../features/org-units/types";
|
|
22
|
-
import type { LoaderData } from "../features/shared/types";
|
|
20
|
+
import type { AuthRouteProps, LoaderData } from "../features/shared/types";
|
|
23
21
|
import type { UserData } from "../features/users/types";
|
|
24
22
|
|
|
25
23
|
export type BuyingPolicyDetailsPageData = {
|
|
@@ -42,42 +40,42 @@ export type BuyingPolicyDetailsPageQuery = GetAddressesServiceProps & {
|
|
|
42
40
|
|
|
43
41
|
const loaderFunction = async (
|
|
44
42
|
data: LoaderData<BuyingPolicyDetailsPageQuery>
|
|
45
|
-
): Promise<BuyingPolicyDetailsPageData
|
|
43
|
+
): Promise<AuthRouteProps<BuyingPolicyDetailsPageData>> => {
|
|
46
44
|
const { contractId, orgUnitId, buyingPolicyId } = data.query;
|
|
47
45
|
|
|
48
|
-
|
|
46
|
+
return withAuthLoader(data, async ({ cookie, userId, ...clientContext }) => {
|
|
47
|
+
const currentOrgUnit = await getOrgUnitBasicDataService({
|
|
48
|
+
id: orgUnitId,
|
|
49
|
+
cookie,
|
|
50
|
+
});
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
id: orgUnitId,
|
|
52
|
-
cookie,
|
|
53
|
-
});
|
|
52
|
+
const user = await getUserByIdService({ orgUnitId, userId, cookie });
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
const contract = await getContractDetailsService({
|
|
55
|
+
contractId,
|
|
56
|
+
cookie,
|
|
57
|
+
unitId: orgUnitId,
|
|
58
|
+
});
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const buyingPolicy = await getBuyingPolicyService({
|
|
61
|
+
orgUnitId,
|
|
62
|
+
contractId,
|
|
63
|
+
buyingPolicyId,
|
|
64
|
+
cookie,
|
|
65
|
+
});
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
return {
|
|
68
|
+
data: {
|
|
69
|
+
buyingPolicy,
|
|
70
|
+
},
|
|
71
|
+
context: {
|
|
72
|
+
clientContext: { cookie, userId, ...clientContext },
|
|
73
|
+
currentOrgUnit,
|
|
74
|
+
currentUser: user,
|
|
75
|
+
currentContract: contract,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
68
78
|
});
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
data: {
|
|
72
|
-
buyingPolicy,
|
|
73
|
-
},
|
|
74
|
-
context: {
|
|
75
|
-
clientContext: { cookie, userId, ...clientContext },
|
|
76
|
-
currentOrgUnit,
|
|
77
|
-
currentUser: user,
|
|
78
|
-
currentContract: contract,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
79
|
};
|
|
82
80
|
|
|
83
81
|
export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
@@ -87,22 +85,23 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
|
87
85
|
|
|
88
86
|
const BuyingPolicyDetailsPage = ({
|
|
89
87
|
data,
|
|
90
|
-
context,
|
|
91
88
|
hasError,
|
|
92
89
|
error,
|
|
93
90
|
}: BuyingPolicyDetailsPageData) => (
|
|
94
|
-
|
|
91
|
+
<>
|
|
95
92
|
{hasError ? (
|
|
96
93
|
<ErrorTabsLayout error={error} />
|
|
97
94
|
) : (
|
|
98
95
|
<BuyingPolicyDetailsLayout data={data} />
|
|
99
96
|
)}
|
|
100
|
-
|
|
97
|
+
</>
|
|
101
98
|
);
|
|
102
99
|
|
|
103
|
-
export default
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
100
|
+
export default withProviders(
|
|
101
|
+
withErrorBoundary(BuyingPolicyDetailsPage, {
|
|
102
|
+
tags: {
|
|
103
|
+
component: "BuyingPolicyDetailsPage",
|
|
104
|
+
errorType: "buying_policy_details_error",
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
);
|
|
@@ -5,21 +5,19 @@ import { ScopeCollection } from "../features/collections/types";
|
|
|
5
5
|
import { getContractDetailsService } from "../features/contracts/services";
|
|
6
6
|
import { ContractData } from "../features/contracts/types";
|
|
7
7
|
import { getOrgUnitBasicDataService } from "../features/org-units/services";
|
|
8
|
-
import {
|
|
9
|
-
BuyerPortalProvider,
|
|
10
|
-
withErrorBoundary,
|
|
11
|
-
} from "../features/shared/components";
|
|
8
|
+
import { withErrorBoundary } from "../features/shared/components";
|
|
12
9
|
import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
|
|
13
10
|
import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
|
|
14
11
|
import {
|
|
15
12
|
type ClientContext,
|
|
16
|
-
getClientContext,
|
|
17
13
|
getValidPage,
|
|
18
14
|
withLoaderErrorBoundary,
|
|
15
|
+
withAuthLoader,
|
|
16
|
+
withProviders,
|
|
19
17
|
} from "../features/shared/utils";
|
|
20
18
|
|
|
21
19
|
import type { OrgUnitBasicData } from "../features/org-units/types";
|
|
22
|
-
import type { LoaderData } from "../features/shared/types";
|
|
20
|
+
import type { AuthRouteProps, LoaderData } from "../features/shared/types";
|
|
23
21
|
|
|
24
22
|
export type CollectionsData = {
|
|
25
23
|
collections: ScopeCollection[];
|
|
@@ -45,58 +43,58 @@ export type CollectionsQuery = {
|
|
|
45
43
|
|
|
46
44
|
const loaderFunction = async (
|
|
47
45
|
data: LoaderData<CollectionsQuery>
|
|
48
|
-
): Promise<CollectionsData
|
|
46
|
+
): Promise<AuthRouteProps<CollectionsData>> => {
|
|
49
47
|
const { contractId, orgUnitId, search = "", page: pageString } = data.query;
|
|
50
48
|
|
|
51
49
|
const page = getValidPage(pageString);
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
getContractDetailsService({ contractId, cookie, unitId: orgUnitId }),
|
|
58
|
-
]);
|
|
59
|
-
|
|
60
|
-
const [enabledCollections, allCollections, contractCollections] =
|
|
61
|
-
await Promise.all([
|
|
62
|
-
getCollectionsFromScopeService({
|
|
63
|
-
cookie,
|
|
64
|
-
contractId,
|
|
65
|
-
unitId: orgUnitId,
|
|
66
|
-
filterByScope: true,
|
|
67
|
-
name: search,
|
|
68
|
-
page,
|
|
69
|
-
}),
|
|
70
|
-
getCollectionsFromScopeService({
|
|
71
|
-
cookie,
|
|
72
|
-
contractId,
|
|
73
|
-
unitId: orgUnitId,
|
|
74
|
-
filterByScope: false,
|
|
75
|
-
page: 1,
|
|
76
|
-
}),
|
|
77
|
-
getCollectionsFromContractService({
|
|
78
|
-
contractId,
|
|
79
|
-
cookie,
|
|
80
|
-
unitId: orgUnitId,
|
|
81
|
-
}),
|
|
51
|
+
return withAuthLoader(data, async ({ cookie, ...clientContext }) => {
|
|
52
|
+
const [currentOrgUnit, contract] = await Promise.all([
|
|
53
|
+
getOrgUnitBasicDataService({ id: orgUnitId, cookie }),
|
|
54
|
+
getContractDetailsService({ contractId, cookie, unitId: orgUnitId }),
|
|
82
55
|
]);
|
|
83
56
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
57
|
+
const [enabledCollections, allCollections, contractCollections] =
|
|
58
|
+
await Promise.all([
|
|
59
|
+
getCollectionsFromScopeService({
|
|
60
|
+
cookie,
|
|
61
|
+
contractId,
|
|
62
|
+
unitId: orgUnitId,
|
|
63
|
+
filterByScope: true,
|
|
64
|
+
name: search,
|
|
65
|
+
page,
|
|
66
|
+
}),
|
|
67
|
+
getCollectionsFromScopeService({
|
|
68
|
+
cookie,
|
|
69
|
+
contractId,
|
|
70
|
+
unitId: orgUnitId,
|
|
71
|
+
filterByScope: false,
|
|
72
|
+
page: 1,
|
|
73
|
+
}),
|
|
74
|
+
getCollectionsFromContractService({
|
|
75
|
+
contractId,
|
|
76
|
+
cookie,
|
|
77
|
+
unitId: orgUnitId,
|
|
78
|
+
}),
|
|
79
|
+
]);
|
|
87
80
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
drawerCollections
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
const isContractEmpty =
|
|
82
|
+
!Array.isArray(contractCollections) || contractCollections?.length === 0;
|
|
83
|
+
const drawerCollections = allCollections.filter((col) => !col.isEnabled);
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
collections: enabledCollections,
|
|
87
|
+
drawerCollections,
|
|
88
|
+
isContractEmpty,
|
|
89
|
+
search,
|
|
90
|
+
page,
|
|
91
|
+
context: {
|
|
92
|
+
clientContext: { cookie, ...clientContext },
|
|
93
|
+
currentContract: contract,
|
|
94
|
+
currentOrgUnit,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
});
|
|
100
98
|
};
|
|
101
99
|
|
|
102
100
|
export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
@@ -105,7 +103,6 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
|
105
103
|
});
|
|
106
104
|
|
|
107
105
|
const CollectionsPage = ({
|
|
108
|
-
context,
|
|
109
106
|
collections,
|
|
110
107
|
drawerCollections,
|
|
111
108
|
isContractEmpty,
|
|
@@ -114,7 +111,7 @@ const CollectionsPage = ({
|
|
|
114
111
|
hasError,
|
|
115
112
|
error,
|
|
116
113
|
}: CollectionsData) => (
|
|
117
|
-
|
|
114
|
+
<>
|
|
118
115
|
{hasError ? (
|
|
119
116
|
<ErrorTabsLayout error={error} />
|
|
120
117
|
) : (
|
|
@@ -126,12 +123,14 @@ const CollectionsPage = ({
|
|
|
126
123
|
isContractEmpty={isContractEmpty}
|
|
127
124
|
/>
|
|
128
125
|
)}
|
|
129
|
-
|
|
126
|
+
</>
|
|
130
127
|
);
|
|
131
128
|
|
|
132
|
-
export default
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
129
|
+
export default withProviders(
|
|
130
|
+
withErrorBoundary(CollectionsPage, {
|
|
131
|
+
tags: {
|
|
132
|
+
component: "CollectionsPage",
|
|
133
|
+
errorType: "collections_error",
|
|
134
|
+
},
|
|
135
|
+
})
|
|
136
|
+
);
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { getContractDetailsService } from "../features/contracts/services";
|
|
2
2
|
import { CustomFieldsLayout } from "../features/custom-fields/layouts";
|
|
3
3
|
import { getOrgUnitBasicDataService } from "../features/org-units/services";
|
|
4
|
-
import {
|
|
5
|
-
BuyerPortalProvider,
|
|
6
|
-
withErrorBoundary,
|
|
7
|
-
} from "../features/shared/components";
|
|
4
|
+
import { withErrorBoundary } from "../features/shared/components";
|
|
8
5
|
import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
|
|
9
6
|
import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
|
|
10
7
|
import {
|
|
11
8
|
ClientContext,
|
|
12
|
-
getClientContext,
|
|
13
9
|
withLoaderErrorBoundary,
|
|
10
|
+
withAuthLoader,
|
|
11
|
+
withProviders,
|
|
14
12
|
} from "../features/shared/utils";
|
|
15
13
|
import { getUserByIdService } from "../features/users/services";
|
|
16
14
|
|
|
17
15
|
import type { ContractData } from "../features/contracts/types";
|
|
18
16
|
import type { OrgUnitBasicData } from "../features/org-units/types";
|
|
19
|
-
import type { LoaderData } from "../features/shared/types";
|
|
17
|
+
import type { AuthRouteProps, LoaderData } from "../features/shared/types";
|
|
20
18
|
import type { UserData } from "../features/users/types";
|
|
21
19
|
|
|
22
20
|
export type CostCentersPageData = {
|
|
@@ -40,41 +38,43 @@ type OrgUnitsPageQuery = {
|
|
|
40
38
|
|
|
41
39
|
const loaderFunction = async (
|
|
42
40
|
data: LoaderData<OrgUnitsPageQuery>
|
|
43
|
-
): Promise<CostCentersPageData
|
|
44
|
-
const { customerId, cookie, userId, ...clientContext } =
|
|
45
|
-
await getClientContext(data);
|
|
46
|
-
|
|
41
|
+
): Promise<AuthRouteProps<CostCentersPageData>> => {
|
|
47
42
|
const { contractId, orgUnitId, search } = data.query;
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
44
|
+
return withAuthLoader(
|
|
45
|
+
data,
|
|
46
|
+
async ({ customerId, cookie, userId, ...clientContext }) => {
|
|
47
|
+
if (!contractId || !orgUnitId) {
|
|
48
|
+
return {
|
|
49
|
+
data: null,
|
|
50
|
+
context: {
|
|
51
|
+
clientContext: { customerId, cookie, userId, ...clientContext },
|
|
52
|
+
currentContract: null,
|
|
53
|
+
currentUser: null,
|
|
54
|
+
currentOrgUnit: null,
|
|
55
|
+
search: "",
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
const [orgUnit, contract, user] = await Promise.all([
|
|
61
|
+
getOrgUnitBasicDataService({ id: orgUnitId, cookie }),
|
|
62
|
+
getContractDetailsService({ contractId, unitId: orgUnitId, cookie }),
|
|
63
|
+
getUserByIdService({ orgUnitId, userId, cookie }),
|
|
64
|
+
]);
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
return {
|
|
67
|
+
data: contract,
|
|
68
|
+
context: {
|
|
69
|
+
search: search ?? "",
|
|
70
|
+
clientContext: { customerId, cookie, userId, ...clientContext },
|
|
71
|
+
currentOrgUnit: orgUnit,
|
|
72
|
+
currentContract: contract,
|
|
73
|
+
currentUser: user,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
@@ -82,26 +82,23 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
|
82
82
|
redirectToError: true,
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
const CostCentersPage = ({
|
|
86
|
-
data,
|
|
87
|
-
context,
|
|
88
|
-
hasError,
|
|
89
|
-
error,
|
|
90
|
-
}: CostCentersPageData) => {
|
|
85
|
+
const CostCentersPage = ({ data, hasError, error }: CostCentersPageData) => {
|
|
91
86
|
return (
|
|
92
|
-
|
|
87
|
+
<>
|
|
93
88
|
{hasError ? (
|
|
94
89
|
<ErrorTabsLayout error={error} />
|
|
95
90
|
) : (
|
|
96
91
|
<CustomFieldsLayout data={data} customFieldsLabel="Cost Center" />
|
|
97
92
|
)}
|
|
98
|
-
|
|
93
|
+
</>
|
|
99
94
|
);
|
|
100
95
|
};
|
|
101
96
|
|
|
102
|
-
export default
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
97
|
+
export default withProviders(
|
|
98
|
+
withErrorBoundary(CostCentersPage, {
|
|
99
|
+
tags: {
|
|
100
|
+
component: "CostCentersPage",
|
|
101
|
+
errorType: "cost_centers_error",
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
);
|
|
@@ -3,22 +3,20 @@ import { CreditCardLayout } from "../features/credit-cards/layouts";
|
|
|
3
3
|
import { getCreditCardsListService } from "../features/credit-cards/services";
|
|
4
4
|
import { CreditCardData } from "../features/credit-cards/types";
|
|
5
5
|
import { getOrgUnitBasicDataService } from "../features/org-units/services";
|
|
6
|
-
import {
|
|
7
|
-
BuyerPortalProvider,
|
|
8
|
-
withErrorBoundary,
|
|
9
|
-
} from "../features/shared/components";
|
|
6
|
+
import { withErrorBoundary } from "../features/shared/components";
|
|
10
7
|
import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
|
|
11
8
|
import { ErrorTabsLayout } from "../features/shared/layouts/ErrorTabsLayout/ErrorTabsLayout";
|
|
12
9
|
import {
|
|
13
10
|
type ClientContext,
|
|
14
|
-
getClientContext,
|
|
15
11
|
withLoaderErrorBoundary,
|
|
12
|
+
withAuthLoader,
|
|
13
|
+
withProviders,
|
|
16
14
|
} from "../features/shared/utils";
|
|
17
15
|
import { getUserByIdService } from "../features/users/services";
|
|
18
16
|
|
|
19
17
|
import type { ContractData } from "../features/contracts/types";
|
|
20
18
|
import type { OrgUnitBasicData } from "../features/org-units/types";
|
|
21
|
-
import type { LoaderData } from "../features/shared/types";
|
|
19
|
+
import type { AuthRouteProps, LoaderData } from "../features/shared/types";
|
|
22
20
|
import type { UserData } from "../features/users/types";
|
|
23
21
|
|
|
24
22
|
export type CreditCardPageData = {
|
|
@@ -40,38 +38,38 @@ export type CreditCardPageQuery = {
|
|
|
40
38
|
|
|
41
39
|
const loaderFunction = async (
|
|
42
40
|
data: LoaderData<CreditCardPageQuery>
|
|
43
|
-
): Promise<CreditCardPageData
|
|
41
|
+
): Promise<AuthRouteProps<CreditCardPageData>> => {
|
|
44
42
|
const { contractId, orgUnitId } = data.query;
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
]);
|
|
44
|
+
return withAuthLoader(data, async ({ cookie, userId, ...clientContext }) => {
|
|
45
|
+
const [currentOrgUnit, user, contract, creditCards] = await Promise.all([
|
|
46
|
+
getOrgUnitBasicDataService({
|
|
47
|
+
id: orgUnitId,
|
|
48
|
+
cookie,
|
|
49
|
+
}),
|
|
50
|
+
getUserByIdService({ orgUnitId, userId, cookie }),
|
|
51
|
+
getContractDetailsService({
|
|
52
|
+
contractId,
|
|
53
|
+
cookie,
|
|
54
|
+
unitId: orgUnitId,
|
|
55
|
+
}),
|
|
56
|
+
getCreditCardsListService({
|
|
57
|
+
cookie,
|
|
58
|
+
unitId: orgUnitId,
|
|
59
|
+
customerId: contractId,
|
|
60
|
+
}),
|
|
61
|
+
]);
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
return {
|
|
64
|
+
data: creditCards,
|
|
65
|
+
context: {
|
|
66
|
+
clientContext: { cookie, userId, ...clientContext },
|
|
67
|
+
currentOrgUnit,
|
|
68
|
+
currentUser: user,
|
|
69
|
+
currentContract: contract,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
});
|
|
75
73
|
};
|
|
76
74
|
|
|
77
75
|
export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
@@ -79,24 +77,21 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
|
79
77
|
redirectToError: true,
|
|
80
78
|
});
|
|
81
79
|
|
|
82
|
-
const CreditCardsPage = ({
|
|
83
|
-
|
|
84
|
-
context,
|
|
85
|
-
hasError,
|
|
86
|
-
error,
|
|
87
|
-
}: CreditCardPageData) => (
|
|
88
|
-
<BuyerPortalProvider {...context}>
|
|
80
|
+
const CreditCardsPage = ({ data, hasError, error }: CreditCardPageData) => (
|
|
81
|
+
<>
|
|
89
82
|
{hasError ? (
|
|
90
83
|
<ErrorTabsLayout error={error} />
|
|
91
84
|
) : (
|
|
92
85
|
<CreditCardLayout data={data} />
|
|
93
86
|
)}
|
|
94
|
-
|
|
87
|
+
</>
|
|
95
88
|
);
|
|
96
89
|
|
|
97
|
-
export default
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
90
|
+
export default withProviders(
|
|
91
|
+
withErrorBoundary(CreditCardsPage, {
|
|
92
|
+
tags: {
|
|
93
|
+
component: "CreditCardsPage",
|
|
94
|
+
errorType: "credit_cards_error",
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
);
|
package/src/pages/home.tsx
CHANGED
|
@@ -4,12 +4,13 @@ import { getOrgUnitByUserIdService } from "../features/org-units/services";
|
|
|
4
4
|
import { withErrorBoundary } from "../features/shared/components";
|
|
5
5
|
import { ErrorBoundaryProps } from "../features/shared/components/ErrorBoundary/types";
|
|
6
6
|
import {
|
|
7
|
-
getClientContext,
|
|
8
7
|
withLoaderErrorBoundary,
|
|
8
|
+
withAuthLoader,
|
|
9
|
+
withProviders,
|
|
9
10
|
} from "../features/shared/utils";
|
|
10
11
|
import { buyerPortalRoutes } from "../features/shared/utils/buyerPortalRoutes";
|
|
11
12
|
|
|
12
|
-
import type { LoaderData } from "../features/shared/types";
|
|
13
|
+
import type { AuthRouteProps, LoaderData } from "../features/shared/types";
|
|
13
14
|
|
|
14
15
|
export type HomePageData = {
|
|
15
16
|
redirected: boolean;
|
|
@@ -23,28 +24,30 @@ type HomePageQuery = {
|
|
|
23
24
|
|
|
24
25
|
const loaderFunction = async (
|
|
25
26
|
data: LoaderData<HomePageQuery>
|
|
26
|
-
): Promise<HomePageData
|
|
27
|
-
|
|
27
|
+
): Promise<AuthRouteProps<HomePageData>> => {
|
|
28
|
+
return withAuthLoader(data, async ({ userId, cookie }) => {
|
|
29
|
+
const userOrgUnit = await getOrgUnitByUserIdService({ userId, cookie });
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
if (userOrgUnit) {
|
|
32
|
+
data.res?.writeHead(302, {
|
|
33
|
+
Location: buyerPortalRoutes.orgUnitDetails({
|
|
34
|
+
orgUnitId: userOrgUnit.id,
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
data.res?.end();
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
39
|
+
return {
|
|
40
|
+
redirected: true,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
data.res?.writeHead(302, { Location: "/" });
|
|
35
45
|
data.res?.end();
|
|
36
46
|
|
|
37
47
|
return {
|
|
38
48
|
redirected: true,
|
|
39
49
|
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
data.res?.writeHead(302, { Location: "/" });
|
|
43
|
-
data.res?.end();
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
redirected: true,
|
|
47
|
-
};
|
|
50
|
+
});
|
|
48
51
|
};
|
|
49
52
|
|
|
50
53
|
export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
@@ -57,9 +60,11 @@ const HomePage = () => {
|
|
|
57
60
|
return null;
|
|
58
61
|
};
|
|
59
62
|
|
|
60
|
-
export default
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
63
|
+
export default withProviders(
|
|
64
|
+
withErrorBoundary(HomePage, {
|
|
65
|
+
tags: {
|
|
66
|
+
component: "HomePage",
|
|
67
|
+
errorType: "home_error",
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
);
|