Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 0bdef06

Browse files
authored
Merge pull request #2 from maxceem/feature/cross-imports
Cross Imports
2 parents 01c79f1 + e2b98ab commit 0bdef06

File tree

13 files changed

+423
-12
lines changed

13 files changed

+423
-12
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
},
66
moduleNameMapper: {
77
"\\.(css)$": "identity-obj-proxy",
8+
"\\.svg$": "<rootDir>/__mocks__/fileMock.js",
89
},
910
setupFilesAfterEnv: [
1011
"../node_modules/@testing-library/jest-dom/dist/index.js",

package-lock.json

Lines changed: 269 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"eslint-config-prettier": "^6.7.0",
3131
"eslint-config-react-important-stuff": "^2.0.0",
3232
"eslint-plugin-prettier": "^3.1.1",
33+
"file-loader": "^6.2.0",
3334
"identity-obj-proxy": "^3.0.0",
3435
"jest": "^25.2.7",
3536
"jest-cli": "^25.2.7",
@@ -47,6 +48,7 @@
4748
"@reach/router": "^1.3.4",
4849
"express": "^4.17.1",
4950
"react": "^16.12.0",
50-
"react-dom": "^16.12.0"
51+
"react-dom": "^16.12.0",
52+
"react-use": "^15.3.4"
5153
}
5254
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
login: () => {},
3+
logout: () => {},
4+
setAppMenu: () => {},
5+
getAuthUserTokens: () => new Promise(() => {}),
6+
getAuthUserProfile: () => new Promise(() => {}),
7+
};

src/__mocks__/fileMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "";

src/assets/images/home-green.svg

Lines changed: 3 additions & 0 deletions
Loading

src/assets/images/home.svg

Lines changed: 3 additions & 0 deletions
Loading

src/assets/images/react-green.svg

Lines changed: 7 additions & 0 deletions
Loading

src/assets/images/react-grey.svg

Lines changed: 7 additions & 0 deletions
Loading

src/components/AuthDemo/index.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from "react";
2+
import { useAsync } from "react-use";
3+
import {
4+
login,
5+
logout,
6+
getAuthUserTokens,
7+
getAuthUserProfile,
8+
} from "@topcoder/micro-frontends-navbar-app";
9+
10+
const Profile = ({ authUserProfile }) => (
11+
<>
12+
<h3>User Profile</h3>
13+
{authUserProfile.loading ? (
14+
<div>User Profile Loading...</div>
15+
) : authUserProfile.error ? (
16+
<div>Profile Loading Error: {authUserProfile.error.message}</div>
17+
) : (
18+
<ul>
19+
<li>
20+
<strong>Handle: </strong> {authUserProfile.value.handle}
21+
</li>
22+
<li>
23+
<strong>First Name: </strong> {authUserProfile.value.firstName}
24+
</li>
25+
<li>
26+
<strong>Last Name: </strong> {authUserProfile.value.lastName}
27+
</li>
28+
</ul>
29+
)}
30+
</>
31+
);
32+
33+
const AuthDemo = () => {
34+
// see how the `useAsync` hook works here https://github.com/streamich/react-use/blob/master/docs/useAsync.md
35+
const authUserTokens = useAsync(getAuthUserTokens);
36+
const authUserProfile = useAsync(getAuthUserProfile);
37+
38+
return (
39+
<>
40+
<h2>Authentication</h2>
41+
{authUserTokens.loading ? (
42+
<div>Authentication...</div>
43+
) : authUserTokens.error ? (
44+
<div>Authentication Error: {authUserTokens.error.message}</div>
45+
) : (
46+
<div>
47+
{authUserTokens.value.tokenV3 ? (
48+
<div>
49+
User is logged-in <button onClick={logout}>Logout</button>
50+
<Profile authUserProfile={authUserProfile} />
51+
</div>
52+
) : (
53+
<>
54+
User is logged-out <button onClick={login}>Login</button>
55+
</>
56+
)}
57+
</div>
58+
)}
59+
</>
60+
);
61+
};
62+
63+
export default AuthDemo;

0 commit comments

Comments
 (0)