@vtex/faststore-plugin-buyer-portal 1.1.116-poc-3 → 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 +1 -1
- package/src/features/contracts/services/get-contract-details.service.ts +4 -0
- package/src/features/org-units/clients/OrgUnitClient.ts +2 -15
- package/src/features/org-units/layouts/OrgUnitDetailsLayout/OrgUnitDetailsLayout.tsx +1 -1
- package/src/features/org-units/services/get-org-unit-basic-data.service.ts +4 -0
- package/src/features/org-units/services/get-org-unit-by-user-id.service.ts +4 -0
- package/src/features/org-units/types/OrgUnitSummaryData.ts +18 -0
- package/src/features/org-units/types/index.ts +2 -0
- package/src/features/profile/layouts/ProfileLayout/ProfileLayout.tsx +12 -10
- package/src/features/shared/hooks/useAuth.ts +2 -4
- package/src/features/shared/layouts/LoadingTabsLayout/LoadingTabsLayout.tsx +4 -0
- package/src/features/users/services/get-user-by-id.service.ts +4 -0
- package/src/pages/org-unit-details.tsx +6 -6
- package/src/pages/profile.tsx +4 -2
package/package.json
CHANGED
|
@@ -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
|
},
|
|
@@ -57,7 +57,7 @@ export const OrgUnitsDetailsLayout = ({
|
|
|
57
57
|
loading = isOrgUnitLoading || isContractsLoading || isUserLoading;
|
|
58
58
|
const isMobile = useMediaQuery(QUERY_TABLET);
|
|
59
59
|
|
|
60
|
-
const isSingleContract = contracts.length <= 1;
|
|
60
|
+
const isSingleContract = !contracts ? true : contracts.length <= 1;
|
|
61
61
|
|
|
62
62
|
const { orgUnit: userUnit } = useOrgUnitByUser(userId);
|
|
63
63
|
|
|
@@ -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
|
+
};
|
|
@@ -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
|
-
|
|
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>
|
|
@@ -3,8 +3,6 @@ import { useEffect, useState } from "react";
|
|
|
3
3
|
import { useRouter } from "next/router";
|
|
4
4
|
|
|
5
5
|
import { authClient } from "../clients/Auth";
|
|
6
|
-
import { ClientContext } from "../utils";
|
|
7
|
-
|
|
8
6
|
export type UseAuthResult = {
|
|
9
7
|
isAuthenticated: boolean | null;
|
|
10
8
|
isLoading: boolean;
|
|
@@ -16,7 +14,7 @@ export type UseAuthResult = {
|
|
|
16
14
|
*
|
|
17
15
|
* @returns Object containing authentication status and loading state
|
|
18
16
|
*/
|
|
19
|
-
export const useAuth = (
|
|
17
|
+
export const useAuth = (cookie: string): UseAuthResult => {
|
|
20
18
|
const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
|
|
21
19
|
const [isLoading, setIsLoading] = useState(true);
|
|
22
20
|
const router = useRouter();
|
|
@@ -26,7 +24,7 @@ export const useAuth = (clientContext: ClientContext): UseAuthResult => {
|
|
|
26
24
|
setIsLoading(true);
|
|
27
25
|
|
|
28
26
|
try {
|
|
29
|
-
const hasAccess = await authClient.validateAccess(
|
|
27
|
+
const hasAccess = await authClient.validateAccess({ cookie });
|
|
30
28
|
|
|
31
29
|
if (!hasAccess) {
|
|
32
30
|
router.push("/");
|
|
@@ -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 {
|
|
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";
|
|
@@ -18,6 +18,7 @@ export type OrgUnitDetailsPageData = {
|
|
|
18
18
|
data: {
|
|
19
19
|
orgUnitId: string;
|
|
20
20
|
userId: string;
|
|
21
|
+
cookie: string;
|
|
21
22
|
};
|
|
22
23
|
context: {
|
|
23
24
|
clientContext: ClientContext;
|
|
@@ -36,12 +37,12 @@ const loaderFunction = async (
|
|
|
36
37
|
const { orgUnitId } = data.query;
|
|
37
38
|
|
|
38
39
|
const { cookie, userId, ...clientContext } = await getClientContext(data);
|
|
39
|
-
console.log(">>> Org Unit Loader", cookie);
|
|
40
40
|
|
|
41
41
|
return {
|
|
42
42
|
data: {
|
|
43
43
|
orgUnitId,
|
|
44
44
|
userId,
|
|
45
|
+
cookie,
|
|
45
46
|
},
|
|
46
47
|
context: {
|
|
47
48
|
clientContext: { cookie, userId, ...clientContext },
|
|
@@ -56,7 +57,6 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
|
56
57
|
|
|
57
58
|
const OrgUnitDetailsPage = ({
|
|
58
59
|
data,
|
|
59
|
-
context,
|
|
60
60
|
hasError,
|
|
61
61
|
error,
|
|
62
62
|
}: OrgUnitDetailsPageData) => {
|
|
@@ -64,11 +64,11 @@ const OrgUnitDetailsPage = ({
|
|
|
64
64
|
return <ErrorTabsLayout error={error} />;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const { isAuthenticated, isLoading } = useAuth(
|
|
68
|
-
console.log(">>
|
|
67
|
+
const { isAuthenticated, isLoading } = useAuth(data.cookie);
|
|
68
|
+
console.log(">> Context", data.cookie);
|
|
69
69
|
|
|
70
70
|
if (isLoading || isAuthenticated === null) {
|
|
71
|
-
return <
|
|
71
|
+
return <OrgUnitsDetailsLayout loading={true} orgUnitId="" userId="" />;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
return (
|
package/src/pages/profile.tsx
CHANGED
|
@@ -17,6 +17,7 @@ export type ProfilePageData = {
|
|
|
17
17
|
contractId: string;
|
|
18
18
|
orgUnitId: string;
|
|
19
19
|
userId: string;
|
|
20
|
+
cookie: string;
|
|
20
21
|
};
|
|
21
22
|
context: {
|
|
22
23
|
clientContext: ClientContext;
|
|
@@ -43,6 +44,7 @@ const loaderFunction = async (
|
|
|
43
44
|
contractId,
|
|
44
45
|
orgUnitId,
|
|
45
46
|
userId,
|
|
47
|
+
cookie,
|
|
46
48
|
},
|
|
47
49
|
context: {
|
|
48
50
|
clientContext: { cookie, userId, ...clientContext },
|
|
@@ -57,12 +59,12 @@ export const loader = withLoaderErrorBoundary(loaderFunction, {
|
|
|
57
59
|
redirectToError: true,
|
|
58
60
|
});
|
|
59
61
|
|
|
60
|
-
const ProfilePage = ({ data,
|
|
62
|
+
const ProfilePage = ({ data, hasError, error }: ProfilePageData) => {
|
|
61
63
|
if (hasError) {
|
|
62
64
|
return <ErrorTabsLayout error={error} />;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
const { isAuthenticated, isLoading } = useAuth(
|
|
67
|
+
const { isAuthenticated, isLoading } = useAuth(data.cookie);
|
|
66
68
|
|
|
67
69
|
if (isLoading || isAuthenticated === null) {
|
|
68
70
|
return <PageLoader />;
|