@proteinjs/ui 2.0.4 → 2.0.6
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/CHANGELOG.md +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/container/AccountAuth.d.ts +23 -0
- package/dist/src/container/AccountAuth.d.ts.map +1 -0
- package/dist/src/container/AccountAuth.js +91 -0
- package/dist/src/container/AccountAuth.js.map +1 -0
- package/dist/src/container/AccountIconButton.d.ts +3 -9
- package/dist/src/container/AccountIconButton.d.ts.map +1 -1
- package/dist/src/container/AccountIconButton.js +9 -68
- package/dist/src/container/AccountIconButton.js.map +1 -1
- package/dist/src/container/PageContainer.d.ts +5 -7
- package/dist/src/container/PageContainer.d.ts.map +1 -1
- package/dist/src/container/PageContainer.js +2 -2
- package/dist/src/container/PageContainer.js.map +1 -1
- package/index.ts +1 -0
- package/package.json +5 -5
- package/src/container/AccountAuth.tsx +62 -0
- package/src/container/AccountIconButton.tsx +7 -39
- package/src/container/PageContainer.tsx +27 -16
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.6](https://github.com/proteinjs/ui/compare/@proteinjs/ui@2.0.5...@proteinjs/ui@2.0.6) (2024-05-17)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* allow custom account menu in page container ([9fdb291](https://github.com/proteinjs/ui/commit/9fdb291e8595d9ec8a05b395a413e4bc05ead59b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [2.0.4](https://github.com/proteinjs/ui/compare/@proteinjs/ui@2.0.3...@proteinjs/ui@2.0.4) (2024-05-10)
|
|
7
18
|
|
|
8
19
|
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './src/form/fields/TextField';
|
|
|
7
7
|
export * from './src/form/container/FormPaper';
|
|
8
8
|
export * from './src/form/container/FormPage';
|
|
9
9
|
export * from './src/container/PageContainer';
|
|
10
|
+
export * from './src/container/AccountAuth';
|
|
10
11
|
export * from './src/container/NavMenu';
|
|
11
12
|
export * from './src/list/NestedList';
|
|
12
13
|
export * from './src/table/Table';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAElC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,6BAA6B,CAAC;AAE5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAE9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AAExC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAElC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,6BAA6B,CAAC;AAE5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAE9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AAExC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./src/form/fields/TextField"), exports);
|
|
|
23
23
|
__exportStar(require("./src/form/container/FormPaper"), exports);
|
|
24
24
|
__exportStar(require("./src/form/container/FormPage"), exports);
|
|
25
25
|
__exportStar(require("./src/container/PageContainer"), exports);
|
|
26
|
+
__exportStar(require("./src/container/AccountAuth"), exports);
|
|
26
27
|
__exportStar(require("./src/container/NavMenu"), exports);
|
|
27
28
|
__exportStar(require("./src/list/NestedList"), exports);
|
|
28
29
|
__exportStar(require("./src/table/Table"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,oDAAkC;AAElC,kDAAgC;AAChC,mDAAiC;AACjC,wDAAsC;AAEtC,8DAA4C;AAE5C,iEAA+C;AAC/C,gEAA8C;AAE9C,gEAA8C;AAC9C,0DAAwC;AAExC,wDAAsC;AAEtC,oDAAkC;AAClC,0DAAwC;AACxC,0DAAwC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,oDAAkC;AAElC,kDAAgC;AAChC,mDAAiC;AACjC,wDAAsC;AAEtC,8DAA4C;AAE5C,iEAA+C;AAC/C,gEAA8C;AAE9C,gEAA8C;AAC9C,8DAA4C;AAC5C,0DAAwC;AAExC,wDAAsC;AAEtC,oDAAkC;AAClC,0DAAwC;AACxC,0DAAwC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Page } from '../router/Page';
|
|
3
|
+
import { LinkOrDialog } from './NavMenu';
|
|
4
|
+
export type AccountAuth = {
|
|
5
|
+
isLoggedIn: boolean;
|
|
6
|
+
canViewPage: (page: Page) => boolean;
|
|
7
|
+
/** Either a dialog component, or a path to be redirected to */
|
|
8
|
+
login: LinkOrDialog;
|
|
9
|
+
logout: () => Promise<string>;
|
|
10
|
+
};
|
|
11
|
+
interface LoginProps {
|
|
12
|
+
auth: AccountAuth;
|
|
13
|
+
loginClicked: boolean;
|
|
14
|
+
setLoginClicked: React.Dispatch<React.SetStateAction<boolean>>;
|
|
15
|
+
}
|
|
16
|
+
export declare function LoginComponent({ auth, loginClicked, setLoginClicked }: LoginProps): React.JSX.Element | null;
|
|
17
|
+
export declare function useAuthActions(auth: AccountAuth | undefined, loginClicked: boolean, setLoginClicked: React.Dispatch<React.SetStateAction<boolean>>): {
|
|
18
|
+
login: () => void;
|
|
19
|
+
logout: () => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
export declare function qualifiedPath(path: string): string;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=AccountAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountAuth.d.ts","sourceRoot":"","sources":["../../../src/container/AccountAuth.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;IACrC,+DAA+D;IAC/D,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/B,CAAC;AAEF,UAAU,UAAU;IAClB,IAAI,EAAE,WAAW,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;CAChE;AAED,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,eAAe,EAAE,EAAE,UAAU,4BAQjF;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,YAAY,EAAE,OAAO,EACrB,eAAe,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;;;EAqB/D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,UAMzC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.qualifiedPath = exports.useAuthActions = exports.LoginComponent = void 0;
|
|
43
|
+
var react_1 = __importDefault(require("react"));
|
|
44
|
+
var react_router_dom_1 = require("react-router-dom");
|
|
45
|
+
function LoginComponent(_a) {
|
|
46
|
+
var auth = _a.auth, loginClicked = _a.loginClicked, setLoginClicked = _a.setLoginClicked;
|
|
47
|
+
if (!loginClicked || !auth || typeof auth.login === 'string') {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
var LoginComponent = auth.login;
|
|
51
|
+
return react_1.default.createElement(LoginComponent, { onClose: function () { return setLoginClicked(false); } });
|
|
52
|
+
}
|
|
53
|
+
exports.LoginComponent = LoginComponent;
|
|
54
|
+
function useAuthActions(auth, loginClicked, setLoginClicked) {
|
|
55
|
+
var _this = this;
|
|
56
|
+
var navigate = (0, react_router_dom_1.useNavigate)();
|
|
57
|
+
var logout = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
58
|
+
var redirectPath;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
if (!auth) {
|
|
63
|
+
return [2 /*return*/];
|
|
64
|
+
}
|
|
65
|
+
return [4 /*yield*/, auth.logout()];
|
|
66
|
+
case 1:
|
|
67
|
+
redirectPath = _a.sent();
|
|
68
|
+
navigate(qualifiedPath(redirectPath));
|
|
69
|
+
return [2 /*return*/];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}); };
|
|
73
|
+
var login = function () {
|
|
74
|
+
if (auth && typeof auth.login === 'string') {
|
|
75
|
+
navigate(qualifiedPath(auth.login));
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
setLoginClicked(!loginClicked);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return { login: login, logout: logout };
|
|
82
|
+
}
|
|
83
|
+
exports.useAuthActions = useAuthActions;
|
|
84
|
+
function qualifiedPath(path) {
|
|
85
|
+
if (path.startsWith('/')) {
|
|
86
|
+
return path;
|
|
87
|
+
}
|
|
88
|
+
return "/".concat(path);
|
|
89
|
+
}
|
|
90
|
+
exports.qualifiedPath = qualifiedPath;
|
|
91
|
+
//# sourceMappingURL=AccountAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountAuth.js","sourceRoot":"","sources":["../../../src/container/AccountAuth.tsx"],"names":[],"mappings":";;;;;;;;;;;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,IAAI,CAAC;KACb;IAED,OAAO,WAAI,IAAI,CAAE,CAAC;AACpB,CAAC;AAND,sCAMC"}
|
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { LinkOrDialog } from './NavMenu';
|
|
3
|
-
import {
|
|
3
|
+
import { AccountAuth } from './AccountAuth';
|
|
4
4
|
export type AccountIconButtonProps = {
|
|
5
5
|
loginClicked: boolean;
|
|
6
6
|
setLoginClicked: React.Dispatch<React.SetStateAction<boolean>>;
|
|
7
|
-
auth?:
|
|
8
|
-
isLoggedIn: boolean;
|
|
9
|
-
canViewPage: (page: Page) => boolean;
|
|
10
|
-
/** Either a dialog component, or a path to be redirected to */
|
|
11
|
-
login: LinkOrDialog;
|
|
12
|
-
logout: () => Promise<string>;
|
|
13
|
-
};
|
|
7
|
+
auth?: AccountAuth;
|
|
14
8
|
profileMenuItems?: {
|
|
15
9
|
menuItemChildren: React.ReactNode;
|
|
16
|
-
action
|
|
10
|
+
action?: LinkOrDialog;
|
|
17
11
|
}[];
|
|
18
12
|
};
|
|
19
13
|
export declare const AccountIconButton: ({ loginClicked, setLoginClicked, auth, profileMenuItems, }: AccountIconButtonProps) => React.JSX.Element | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountIconButton.d.ts","sourceRoot":"","sources":["../../../src/container/AccountIconButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"AccountIconButton.d.ts","sourceRoot":"","sources":["../../../src/container/AccountIconButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAiD,MAAM,eAAe,CAAC;AAE3F,MAAM,MAAM,sBAAsB,GAAG;IACnC,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC/D,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,gBAAgB,CAAC,EAAE;QAAE,gBAAgB,EAAE,KAAK,CAAC,SAAS,CAAC;QAAC,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,EAAE,CAAC;CACnF,CAAC;AAEF,eAAO,MAAM,iBAAiB,+DAK3B,sBAAsB,6BAqFxB,CAAC"}
|
|
@@ -1,40 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
@@ -45,12 +9,14 @@ var material_1 = require("@mui/material");
|
|
|
45
9
|
var AccountCircle_1 = __importDefault(require("@mui/icons-material/AccountCircle"));
|
|
46
10
|
var react_router_dom_1 = require("react-router-dom");
|
|
47
11
|
var Logout_1 = __importDefault(require("@mui/icons-material/Logout"));
|
|
12
|
+
var AccountAuth_1 = require("./AccountAuth");
|
|
48
13
|
var AccountIconButton = function (_a) {
|
|
49
14
|
var loginClicked = _a.loginClicked, setLoginClicked = _a.setLoginClicked, auth = _a.auth, profileMenuItems = _a.profileMenuItems;
|
|
50
15
|
var navigate = (0, react_router_dom_1.useNavigate)();
|
|
51
|
-
var _b =
|
|
52
|
-
var _c = react_1.default.useState(1),
|
|
53
|
-
var _d = react_1.default.useState(
|
|
16
|
+
var _b = (0, AccountAuth_1.useAuthActions)(auth, loginClicked, setLoginClicked), logout = _b.logout, login = _b.login;
|
|
17
|
+
var _c = react_1.default.useState(-1), selectedProfileMenuItem = _c[0], setSelectedProfileMenuItem = _c[1];
|
|
18
|
+
var _d = react_1.default.useState(1), selectedIndex = _d[0], setSelectedIndex = _d[1];
|
|
19
|
+
var _e = react_1.default.useState(null), anchorEl = _e[0], setAccountMenuAnchorEl = _e[1];
|
|
54
20
|
var open = Boolean(anchorEl);
|
|
55
21
|
if (!auth) {
|
|
56
22
|
return null;
|
|
@@ -69,7 +35,7 @@ var AccountIconButton = function (_a) {
|
|
|
69
35
|
profileMenuItems &&
|
|
70
36
|
profileMenuItems.map(function (profileMenuItem, index) { return (react_1.default.createElement(material_1.MenuItem, { key: index, onClick: function (event) {
|
|
71
37
|
if (typeof profileMenuItem.action === 'string') {
|
|
72
|
-
navigate(qualifiedPath(profileMenuItem.action));
|
|
38
|
+
navigate((0, AccountAuth_1.qualifiedPath)(profileMenuItem.action));
|
|
73
39
|
return;
|
|
74
40
|
}
|
|
75
41
|
else if (isFunction(profileMenuItem.action)) {
|
|
@@ -80,28 +46,15 @@ var AccountIconButton = function (_a) {
|
|
|
80
46
|
setSelectedIndex(index);
|
|
81
47
|
}
|
|
82
48
|
}, selected: selectedIndex === index }, profileMenuItem.menuItemChildren)); }),
|
|
83
|
-
react_1.default.createElement(material_1.MenuItem, { key: 'logout', onClick:
|
|
84
|
-
var redirectPath;
|
|
85
|
-
return __generator(this, function (_a) {
|
|
86
|
-
switch (_a.label) {
|
|
87
|
-
case 0: return [4 /*yield*/, auth.logout()];
|
|
88
|
-
case 1:
|
|
89
|
-
redirectPath = _a.sent();
|
|
90
|
-
navigate(qualifiedPath(redirectPath));
|
|
91
|
-
return [2 /*return*/];
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}); } },
|
|
49
|
+
react_1.default.createElement(material_1.MenuItem, { key: 'logout', onClick: logout },
|
|
95
50
|
react_1.default.createElement(material_1.ListItemIcon, null,
|
|
96
51
|
react_1.default.createElement(Logout_1.default, null)),
|
|
97
52
|
react_1.default.createElement(material_1.Typography, null, "Logout"))),
|
|
98
53
|
react_1.default.createElement(ProfileMenuItemAction, null)));
|
|
99
54
|
}
|
|
100
55
|
return (react_1.default.createElement("div", null,
|
|
101
|
-
react_1.default.createElement(material_1.Button, { color: 'inherit', onClick:
|
|
102
|
-
|
|
103
|
-
} }, "Login"),
|
|
104
|
-
react_1.default.createElement(Login, null)));
|
|
56
|
+
react_1.default.createElement(material_1.Button, { color: 'inherit', onClick: login }, "Login"),
|
|
57
|
+
react_1.default.createElement(AccountAuth_1.LoginComponent, { auth: auth, loginClicked: loginClicked, setLoginClicked: setLoginClicked })));
|
|
105
58
|
function ProfileMenuItemAction() {
|
|
106
59
|
if (selectedProfileMenuItem == -1 || !auth || !profileMenuItems) {
|
|
107
60
|
return null;
|
|
@@ -115,18 +68,6 @@ var AccountIconButton = function (_a) {
|
|
|
115
68
|
}
|
|
116
69
|
return null;
|
|
117
70
|
}
|
|
118
|
-
function Login() {
|
|
119
|
-
if (!loginClicked || !auth || typeof auth.login === 'string') {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
return react_1.default.createElement(auth.login, { onClose: function () { return setLoginClicked(false); } });
|
|
123
|
-
}
|
|
124
|
-
function qualifiedPath(path) {
|
|
125
|
-
if (path.startsWith('/')) {
|
|
126
|
-
return path;
|
|
127
|
-
}
|
|
128
|
-
return "/".concat(path);
|
|
129
|
-
}
|
|
130
71
|
};
|
|
131
72
|
exports.AccountIconButton = AccountIconButton;
|
|
132
73
|
function isDialog(prop) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountIconButton.js","sourceRoot":"","sources":["../../../src/container/AccountIconButton.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AccountIconButton.js","sourceRoot":"","sources":["../../../src/container/AccountIconButton.tsx"],"names":[],"mappings":";;;;;;AAAA,gDAA0B;AAC1B,0CAA6F;AAC7F,oFAA8D;AAC9D,qDAA+C;AAE/C,sEAAoD;AACpD,6CAA2F;AASpF,IAAM,iBAAiB,GAAG,UAAC,EAKT;QAJvB,YAAY,kBAAA,EACZ,eAAe,qBAAA,EACf,IAAI,UAAA,EACJ,gBAAgB,sBAAA;IAEhB,IAAM,QAAQ,GAAG,IAAA,8BAAW,GAAE,CAAC;IACzB,IAAA,KAAoB,IAAA,4BAAc,EAAC,IAAI,EAAE,YAAY,EAAE,eAAe,CAAC,EAArE,MAAM,YAAA,EAAE,KAAK,WAAwD,CAAC;IACxE,IAAA,KAAwD,eAAK,CAAC,QAAQ,CAAS,CAAC,CAAC,CAAC,EAAjF,uBAAuB,QAAA,EAAE,0BAA0B,QAA8B,CAAC;IACnF,IAAA,KAAoC,eAAK,CAAC,QAAQ,CAAS,CAAC,CAAC,EAA5D,aAAa,QAAA,EAAE,gBAAgB,QAA6B,CAAC;IAC9D,IAAA,KAAqC,eAAK,CAAC,QAAQ,CAAqB,IAAI,CAAC,EAA5E,QAAQ,QAAA,EAAE,sBAAsB,QAA4C,CAAC;IACpF,IAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE/B,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,IAAI,CAAC;KACb;IAED,IAAI,IAAI,CAAC,UAAU,EAAE;QACnB,OAAO,CACL;YACE,8BAAC,qBAAU,IACT,EAAE,EAAE;oBACF,SAAS,EAAE;wBACT,KAAK,EAAE,MAAM;wBACb,eAAe,EAAE,aAAa;qBAC/B;oBACD,eAAe,EAAE,aAAa;iBAC/B,EACD,OAAO,EAAE,UAAC,KAAK,IAAK,OAAA,sBAAsB,CAAC,KAAK,CAAC,aAAa,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ACP,CAAC;IAEF,SAAS,qBAAqB;QAC5B,IAAI,uBAAuB,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,gBAAgB,EAAE;YAC/D,OAAO,IAAI,CAAC;SACb;QAED,IAAM,QAAQ,GAAG,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;QAC3D,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE;YACvC,OAAO,IAAI,CAAC;SACb;QAED,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YAC7B,OAAO,8BAAC,QAAQ,CAAC,MAAM,IAAC,OAAO,EAAE,cAAM,OAAA,0BAA0B,CAAC,CAAC,CAAC,CAAC,EAA9B,CAA8B,GAAI,CAAC;SAC3E;QAED,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AA1FW,QAAA,iBAAiB,qBA0F5B;AAEF,SAAS,QAAQ,CAAC,IAAS;IACzB,OAAO,OAAO,IAAI,KAAK,UAAU,IAAI,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;AACnE,CAAC;AAED,SAAS,UAAU,CAAC,IAAS;IAC3B,OAAO,OAAO,IAAI,KAAK,UAAU,CAAC;AACpC,CAAC"}
|
|
@@ -3,24 +3,22 @@ import { AppBarProps, ToolbarProps } from '@mui/material';
|
|
|
3
3
|
import { NavigateFunction } from 'react-router-dom';
|
|
4
4
|
import { Page } from '../router/Page';
|
|
5
5
|
import { LinkOrDialog, NavMenuItem } from './NavMenu';
|
|
6
|
+
import { AccountIconButtonProps } from './AccountIconButton';
|
|
7
|
+
import { AccountAuth } from './AccountAuth';
|
|
6
8
|
export type PageContainerProps = {
|
|
7
9
|
page: Page;
|
|
8
|
-
auth?:
|
|
9
|
-
isLoggedIn: boolean;
|
|
10
|
-
canViewPage: (page: Page) => boolean;
|
|
11
|
-
login: LinkOrDialog;
|
|
12
|
-
logout: () => Promise<string>;
|
|
13
|
-
};
|
|
10
|
+
auth?: AccountAuth;
|
|
14
11
|
appName?: string;
|
|
15
12
|
toolbarChildren?: React.ReactNode;
|
|
16
13
|
/** An array of menu items, each containing a React node and an action triggered when selected, either a string, dialog component, or a function. */
|
|
17
14
|
profileMenuItems?: {
|
|
18
15
|
menuItemChildren: React.ReactNode;
|
|
19
|
-
action
|
|
16
|
+
action?: LinkOrDialog;
|
|
20
17
|
}[];
|
|
21
18
|
navMenuItems?: NavMenuItem[];
|
|
22
19
|
appBarProps?: AppBarProps;
|
|
23
20
|
toolbarProps?: ToolbarProps;
|
|
21
|
+
CustomAccountIconButton?: React.ComponentType<AccountIconButtonProps>;
|
|
24
22
|
};
|
|
25
23
|
declare const Page: React.MemoExoticComponent<({ auth, page, navigate, loginClicked, setLoginClicked, }: {
|
|
26
24
|
auth: PageContainerProps['auth'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageContainer.d.ts","sourceRoot":"","sources":["../../../src/container/PageContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"PageContainer.d.ts","sourceRoot":"","sources":["../../../src/container/PageContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAgD,WAAW,EAAE,YAAY,EAAa,MAAM,eAAe,CAAC;AAEnH,OAAO,EAAE,gBAAgB,EAAe,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAW,WAAW,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAqB,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAClC,oJAAoJ;IACpJ,gBAAgB,CAAC,EAAE;QAAE,gBAAgB,EAAE,KAAK,CAAC,SAAS,CAAC;QAAC,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,EAAE,CAAC;IAClF,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;IAC7B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,uBAAuB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,sBAAsB,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,IAAI;UAQA,kBAAkB,CAAC,MAAM,CAAC;UAC1B,kBAAkB,CAAC,MAAM,CAAC;cACtB,gBAAgB;kBACZ,OAAO;oCACW,OAAO,KAAK,IAAI;+BAiBnD,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,qBAqFtD"}
|
|
@@ -44,7 +44,7 @@ var Page = react_1.default.memo(function (_a) {
|
|
|
44
44
|
});
|
|
45
45
|
function PageContainer(props) {
|
|
46
46
|
var navigate = (0, react_router_dom_1.useNavigate)();
|
|
47
|
-
var page = props.page, auth = props.auth, navMenuItems = props.navMenuItems, appName = props.appName, toolbarChildren = props.toolbarChildren, profileMenuItems = props.profileMenuItems, appBarProps = props.appBarProps, toolbarProps = props.toolbarProps;
|
|
47
|
+
var page = props.page, auth = props.auth, navMenuItems = props.navMenuItems, appName = props.appName, toolbarChildren = props.toolbarChildren, profileMenuItems = props.profileMenuItems, appBarProps = props.appBarProps, toolbarProps = props.toolbarProps, CustomAccountIconButton = props.CustomAccountIconButton;
|
|
48
48
|
var _a = react_1.default.useState(false), loginClicked = _a[0], setLoginClicked = _a[1];
|
|
49
49
|
var _b = react_1.default.useState(false), navMenuOpen = _b[0], setNavMenuOpen = _b[1];
|
|
50
50
|
react_1.default.useEffect(function () {
|
|
@@ -79,7 +79,7 @@ function PageContainer(props) {
|
|
|
79
79
|
appName && (react_1.default.createElement(material_1.Typography, { variant: 'h5', sx: { flexGrow: 1, color: 'common.white' } }, appName)),
|
|
80
80
|
toolbarChildren,
|
|
81
81
|
react_1.default.createElement("div", { style: { flexGrow: 1 } }),
|
|
82
|
-
react_1.default.createElement(AccountIconButton_1.AccountIconButton, __assign({ loginClicked: loginClicked, setLoginClicked: setLoginClicked, auth: auth }, (profileMenuItems ? { profileMenuItems: profileMenuItems } : {}))))),
|
|
82
|
+
CustomAccountIconButton ? (react_1.default.createElement(CustomAccountIconButton, { loginClicked: loginClicked, setLoginClicked: setLoginClicked, auth: auth })) : (react_1.default.createElement(AccountIconButton_1.AccountIconButton, __assign({ loginClicked: loginClicked, setLoginClicked: setLoginClicked, auth: auth }, (profileMenuItems ? { profileMenuItems: profileMenuItems } : {})))))),
|
|
83
83
|
navMenuItems && (react_1.default.createElement(NavMenu_1.NavMenu, { navMenuItems: navMenuItems, navMenuOpen: navMenuOpen, setNavMenuOpen: setNavMenuOpen })),
|
|
84
84
|
react_1.default.createElement(Page, { auth: auth, page: page, navigate: navigate, loginClicked: loginClicked, setLoginClicked: setLoginClicked })));
|
|
85
85
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageContainer.js","sourceRoot":"","sources":["../../../src/container/PageContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"PageContainer.js","sourceRoot":"","sources":["../../../src/container/PageContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,0CAAmH;AACnH,kEAAgD;AAChD,qDAAiE;AAEjE,6DAA4D;AAC5D,qCAA+D;AAC/D,yDAAgF;AAGhF,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,O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ACF,KAAK,EAAE,EAAE,eAAe,EAAE,aAAa,EAAE;oBAEzC,8BAAC,cAAQ,OAAG,CACD,CACd;gBACA,OAAO,IAAI,CACV,8BAAC,qBAAU,IAAC,OAAO,EAAC,IAAI,EAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,IAChE,OAAO,CACG,CACd;gBACA,eAAe;gBAChB,uCAAK,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAQ;gBAClC,uBAAuB,CAAC,CAAC,CAAC,CACzB,8BAAC,uBAAuB,IAAC,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,GAAI,CACtG,CAAC,CAAC,CAAC,CACF,8BAAC,qCAAiB,aAChB,YAAY,EAAE,YAAY,EAC1B,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,IAAI,IACN,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,kBAAA,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAClD,CACH,CACO,CACH;QACR,YAAY,IAAI,CACf,8BAAC,iBAAO,IAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,GAAI,CAClG;QACD,8BAAC,IAAI,IAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,GAAI,CAC9G,CACP,CAAC;AACJ,CAAC;AArFD,sCAqFC"}
|
package/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './src/form/container/FormPaper';
|
|
|
11
11
|
export * from './src/form/container/FormPage';
|
|
12
12
|
|
|
13
13
|
export * from './src/container/PageContainer';
|
|
14
|
+
export * from './src/container/AccountAuth';
|
|
14
15
|
export * from './src/container/NavMenu';
|
|
15
16
|
|
|
16
17
|
export * from './src/list/NestedList';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/ui",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "UI libs",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@emotion/styled": "11.11.0",
|
|
26
26
|
"@mui/icons-material": "5.14.11",
|
|
27
27
|
"@mui/material": "5.14.11",
|
|
28
|
-
"@proteinjs/reflection": "1.1.
|
|
29
|
-
"@proteinjs/util": "1.1.
|
|
28
|
+
"@proteinjs/reflection": "1.1.5",
|
|
29
|
+
"@proteinjs/util": "1.1.2",
|
|
30
30
|
"history": "5.0.0",
|
|
31
31
|
"moment": "2.29.4",
|
|
32
32
|
"query-string": "6.13.2",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"string": "3.3.3"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@proteinjs/reflection-build": "1.0.
|
|
40
|
+
"@proteinjs/reflection-build": "1.0.19",
|
|
41
41
|
"@types/node": "14.0.13",
|
|
42
42
|
"@types/react": "18.2.23",
|
|
43
43
|
"@types/react-dom": "18.2.8",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
},
|
|
54
54
|
"main": "./dist/generated/index.js",
|
|
55
55
|
"types": "./dist/generated/index.d.ts",
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "a51c4c8944bc140db08655a5f1d059515165edae"
|
|
57
57
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Page } from '../router/Page';
|
|
3
|
+
import { LinkOrDialog } from './NavMenu';
|
|
4
|
+
import { useNavigate } from 'react-router-dom';
|
|
5
|
+
|
|
6
|
+
export type AccountAuth = {
|
|
7
|
+
isLoggedIn: boolean;
|
|
8
|
+
canViewPage: (page: Page) => boolean;
|
|
9
|
+
/** Either a dialog component, or a path to be redirected to */
|
|
10
|
+
login: LinkOrDialog;
|
|
11
|
+
logout: () => Promise<string>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
interface LoginProps {
|
|
15
|
+
auth: AccountAuth;
|
|
16
|
+
loginClicked: boolean;
|
|
17
|
+
setLoginClicked: React.Dispatch<React.SetStateAction<boolean>>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function LoginComponent({ auth, loginClicked, setLoginClicked }: LoginProps) {
|
|
21
|
+
if (!loginClicked || !auth || typeof auth.login === 'string') {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const LoginComponent = auth.login as React.ComponentType<{ onClose: () => void }>;
|
|
26
|
+
|
|
27
|
+
return <LoginComponent onClose={() => setLoginClicked(false)} />;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function useAuthActions(
|
|
31
|
+
auth: AccountAuth | undefined,
|
|
32
|
+
loginClicked: boolean,
|
|
33
|
+
setLoginClicked: React.Dispatch<React.SetStateAction<boolean>>
|
|
34
|
+
) {
|
|
35
|
+
const navigate = useNavigate();
|
|
36
|
+
|
|
37
|
+
const logout = async () => {
|
|
38
|
+
if (!auth) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const redirectPath = await auth.logout();
|
|
42
|
+
navigate(qualifiedPath(redirectPath));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const login = () => {
|
|
46
|
+
if (auth && typeof auth.login === 'string') {
|
|
47
|
+
navigate(qualifiedPath(auth.login));
|
|
48
|
+
} else {
|
|
49
|
+
setLoginClicked(!loginClicked);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return { login, logout };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function qualifiedPath(path: string) {
|
|
57
|
+
if (path.startsWith('/')) {
|
|
58
|
+
return path;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return `/${path}`;
|
|
62
|
+
}
|
|
@@ -3,20 +3,14 @@ import { Button, IconButton, ListItemIcon, Menu, MenuItem, Typography } from '@m
|
|
|
3
3
|
import AccountCircle from '@mui/icons-material/AccountCircle';
|
|
4
4
|
import { useNavigate } from 'react-router-dom';
|
|
5
5
|
import { LinkOrDialog } from './NavMenu';
|
|
6
|
-
import { Page } from '../router/Page';
|
|
7
6
|
import LogoutIcon from '@mui/icons-material/Logout';
|
|
7
|
+
import { AccountAuth, LoginComponent, qualifiedPath, useAuthActions } from './AccountAuth';
|
|
8
8
|
|
|
9
9
|
export type AccountIconButtonProps = {
|
|
10
10
|
loginClicked: boolean;
|
|
11
11
|
setLoginClicked: React.Dispatch<React.SetStateAction<boolean>>;
|
|
12
|
-
auth?:
|
|
13
|
-
|
|
14
|
-
canViewPage: (page: Page) => boolean;
|
|
15
|
-
/** Either a dialog component, or a path to be redirected to */
|
|
16
|
-
login: LinkOrDialog;
|
|
17
|
-
logout: () => Promise<string>;
|
|
18
|
-
};
|
|
19
|
-
profileMenuItems?: { menuItemChildren: React.ReactNode; action: LinkOrDialog | (() => void) }[];
|
|
12
|
+
auth?: AccountAuth;
|
|
13
|
+
profileMenuItems?: { menuItemChildren: React.ReactNode; action?: LinkOrDialog }[];
|
|
20
14
|
};
|
|
21
15
|
|
|
22
16
|
export const AccountIconButton = ({
|
|
@@ -26,6 +20,7 @@ export const AccountIconButton = ({
|
|
|
26
20
|
profileMenuItems,
|
|
27
21
|
}: AccountIconButtonProps) => {
|
|
28
22
|
const navigate = useNavigate();
|
|
23
|
+
const { logout, login } = useAuthActions(auth, loginClicked, setLoginClicked);
|
|
29
24
|
const [selectedProfileMenuItem, setSelectedProfileMenuItem] = React.useState<number>(-1);
|
|
30
25
|
const [selectedIndex, setSelectedIndex] = React.useState<number>(1);
|
|
31
26
|
const [anchorEl, setAccountMenuAnchorEl] = React.useState<null | HTMLElement>(null);
|
|
@@ -71,13 +66,7 @@ export const AccountIconButton = ({
|
|
|
71
66
|
{profileMenuItem.menuItemChildren}
|
|
72
67
|
</MenuItem>
|
|
73
68
|
))}
|
|
74
|
-
<MenuItem
|
|
75
|
-
key='logout'
|
|
76
|
-
onClick={async (event) => {
|
|
77
|
-
const redirectPath = await auth.logout();
|
|
78
|
-
navigate(qualifiedPath(redirectPath));
|
|
79
|
-
}}
|
|
80
|
-
>
|
|
69
|
+
<MenuItem key='logout' onClick={logout}>
|
|
81
70
|
<ListItemIcon>
|
|
82
71
|
<LogoutIcon />
|
|
83
72
|
</ListItemIcon>
|
|
@@ -91,15 +80,10 @@ export const AccountIconButton = ({
|
|
|
91
80
|
|
|
92
81
|
return (
|
|
93
82
|
<div>
|
|
94
|
-
<Button
|
|
95
|
-
color='inherit'
|
|
96
|
-
onClick={(event) =>
|
|
97
|
-
auth && typeof auth.login === 'string' ? navigate(qualifiedPath(auth.login)) : setLoginClicked(!loginClicked)
|
|
98
|
-
}
|
|
99
|
-
>
|
|
83
|
+
<Button color='inherit' onClick={login}>
|
|
100
84
|
Login
|
|
101
85
|
</Button>
|
|
102
|
-
<
|
|
86
|
+
<LoginComponent auth={auth} loginClicked={loginClicked} setLoginClicked={setLoginClicked} />
|
|
103
87
|
</div>
|
|
104
88
|
);
|
|
105
89
|
|
|
@@ -119,22 +103,6 @@ export const AccountIconButton = ({
|
|
|
119
103
|
|
|
120
104
|
return null;
|
|
121
105
|
}
|
|
122
|
-
|
|
123
|
-
function Login() {
|
|
124
|
-
if (!loginClicked || !auth || typeof auth.login === 'string') {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return <auth.login onClose={() => setLoginClicked(false)} />;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function qualifiedPath(path: string) {
|
|
132
|
-
if (path.startsWith('/')) {
|
|
133
|
-
return path;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return `/${path}`;
|
|
137
|
-
}
|
|
138
106
|
};
|
|
139
107
|
|
|
140
108
|
function isDialog(prop: any): prop is React.ComponentType<{ onClose: () => void }> {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { AppBar, Toolbar, Box, IconButton, Typography,
|
|
2
|
+
import { AppBar, Toolbar, Box, IconButton, Typography, AppBarProps, ToolbarProps, MenuProps } from '@mui/material';
|
|
3
3
|
import MenuIcon from '@mui/icons-material/Menu';
|
|
4
4
|
import { NavigateFunction, useNavigate } from 'react-router-dom';
|
|
5
5
|
import { Page } from '../router/Page';
|
|
6
6
|
import { createUrlParams } from '../router/createUrlParams';
|
|
7
7
|
import { LinkOrDialog, NavMenu, NavMenuItem } from './NavMenu';
|
|
8
|
-
import { AccountIconButton } from './AccountIconButton';
|
|
8
|
+
import { AccountIconButton, AccountIconButtonProps } from './AccountIconButton';
|
|
9
|
+
import { AccountAuth } from './AccountAuth';
|
|
9
10
|
|
|
10
11
|
function qualifiedPath(path: string) {
|
|
11
12
|
if (path.startsWith('/')) {
|
|
@@ -17,19 +18,15 @@ function qualifiedPath(path: string) {
|
|
|
17
18
|
|
|
18
19
|
export type PageContainerProps = {
|
|
19
20
|
page: Page;
|
|
20
|
-
auth?:
|
|
21
|
-
isLoggedIn: boolean;
|
|
22
|
-
canViewPage: (page: Page) => boolean;
|
|
23
|
-
login: LinkOrDialog;
|
|
24
|
-
logout: () => Promise<string>;
|
|
25
|
-
};
|
|
21
|
+
auth?: AccountAuth;
|
|
26
22
|
appName?: string;
|
|
27
23
|
toolbarChildren?: React.ReactNode;
|
|
28
24
|
/** An array of menu items, each containing a React node and an action triggered when selected, either a string, dialog component, or a function. */
|
|
29
|
-
profileMenuItems?: { menuItemChildren: React.ReactNode; action
|
|
25
|
+
profileMenuItems?: { menuItemChildren: React.ReactNode; action?: LinkOrDialog }[];
|
|
30
26
|
navMenuItems?: NavMenuItem[];
|
|
31
27
|
appBarProps?: AppBarProps;
|
|
32
28
|
toolbarProps?: ToolbarProps;
|
|
29
|
+
CustomAccountIconButton?: React.ComponentType<AccountIconButtonProps>;
|
|
33
30
|
};
|
|
34
31
|
|
|
35
32
|
const Page = React.memo(
|
|
@@ -65,7 +62,17 @@ const Page = React.memo(
|
|
|
65
62
|
|
|
66
63
|
export function PageContainer(props: PageContainerProps) {
|
|
67
64
|
const navigate = useNavigate();
|
|
68
|
-
const {
|
|
65
|
+
const {
|
|
66
|
+
page,
|
|
67
|
+
auth,
|
|
68
|
+
navMenuItems,
|
|
69
|
+
appName,
|
|
70
|
+
toolbarChildren,
|
|
71
|
+
profileMenuItems,
|
|
72
|
+
appBarProps,
|
|
73
|
+
toolbarProps,
|
|
74
|
+
CustomAccountIconButton,
|
|
75
|
+
} = props;
|
|
69
76
|
const [loginClicked, setLoginClicked] = React.useState(false);
|
|
70
77
|
const [navMenuOpen, setNavMenuOpen] = React.useState(false);
|
|
71
78
|
|
|
@@ -120,12 +127,16 @@ export function PageContainer(props: PageContainerProps) {
|
|
|
120
127
|
)}
|
|
121
128
|
{toolbarChildren}
|
|
122
129
|
<div style={{ flexGrow: 1 }}></div>
|
|
123
|
-
|
|
124
|
-
loginClicked={loginClicked}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
{CustomAccountIconButton ? (
|
|
131
|
+
<CustomAccountIconButton loginClicked={loginClicked} setLoginClicked={setLoginClicked} auth={auth} />
|
|
132
|
+
) : (
|
|
133
|
+
<AccountIconButton
|
|
134
|
+
loginClicked={loginClicked}
|
|
135
|
+
setLoginClicked={setLoginClicked}
|
|
136
|
+
auth={auth}
|
|
137
|
+
{...(profileMenuItems ? { profileMenuItems } : {})}
|
|
138
|
+
/>
|
|
139
|
+
)}
|
|
129
140
|
</Toolbar>
|
|
130
141
|
</AppBar>
|
|
131
142
|
{navMenuItems && (
|