@proteinjs/user-ui 1.2.31 → 1.3.0
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/dist/generated/index.d.ts +2 -0
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +5 -3
- package/dist/generated/index.js.map +1 -1
- package/dist/src/form/InviteRecordFormCustomization.d.ts +25 -0
- package/dist/src/form/InviteRecordFormCustomization.d.ts.map +1 -0
- package/dist/src/form/InviteRecordFormCustomization.js +173 -0
- package/dist/src/form/InviteRecordFormCustomization.js.map +1 -0
- package/dist/test/InviteRecordFormCustomization.test.d.ts +2 -0
- package/dist/test/InviteRecordFormCustomization.test.d.ts.map +1 -0
- package/dist/test/InviteRecordFormCustomization.test.js +51 -0
- package/dist/test/InviteRecordFormCustomization.test.js.map +1 -0
- package/generated/index.ts +5 -3
- package/package.json +10 -4
- package/src/form/InviteRecordFormCustomization.tsx +92 -0
- package/test/InviteRecordFormCustomization.test.ts +69 -0
- package/dist/src/pages/SendInvite.d.ts +0 -3
- package/dist/src/pages/SendInvite.d.ts.map +0 -1
- package/dist/src/pages/SendInvite.js +0 -169
- package/dist/src/pages/SendInvite.js.map +0 -1
- package/src/pages/SendInvite.tsx +0 -111
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,qBAAqB,CAAC;AAC7B,OAAO,eAAe,CAAC;AACvB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,eAAe,CAAC;AACvB,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,QAAQ,CAAC;AAChB,OAAO,OAAO,CAAC;AACf,OAAO,WAAW,CAAC;AACnB,OAAO,cAAc,CAAC;AACtB,OAAO,kBAAkB,CAAC;AA+B1B,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,qBAAqB,CAAC;AAC7B,OAAO,eAAe,CAAC;AACvB,OAAO,eAAe,CAAC;AACvB,OAAO,kBAAkB,CAAC;AAC1B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,eAAe,CAAC;AACvB,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,QAAQ,CAAC;AAChB,OAAO,OAAO,CAAC;AACf,OAAO,WAAW,CAAC;AACnB,OAAO,cAAc,CAAC;AACtB,OAAO,kBAAkB,CAAC;AA+B1B,cAAc,UAAU,CAAC"}
|
package/dist/generated/index.js
CHANGED
|
@@ -17,6 +17,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
require("@mui/icons-material");
|
|
19
19
|
require("@mui/material");
|
|
20
|
+
require("@proteinjs/db");
|
|
21
|
+
require("@proteinjs/db-ui");
|
|
20
22
|
require("@proteinjs/reflection");
|
|
21
23
|
require("@proteinjs/server-api");
|
|
22
24
|
require("@proteinjs/ui");
|
|
@@ -28,18 +30,18 @@ require("react-dom");
|
|
|
28
30
|
require("react-helmet");
|
|
29
31
|
require("react-router-dom");
|
|
30
32
|
/** Generate Source Graph */
|
|
31
|
-
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"/Omit\"},{\"v\":\"@proteinjs/user-ui/
|
|
33
|
+
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"/Omit\"},{\"v\":\"@proteinjs/user-ui/InviteRecordFormCustomization\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"InviteRecordFormCustomization\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa2/packages/proteinjs/packages/user/packages/ui/src/form/InviteRecordFormCustomization.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/InviteRecordFormCustomization\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"table\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getFieldLayout\",\"returnType\":{\"packageName\":\"\",\"name\":\"string[] | string[][]\",\"filePath\":null,\"qualifiedName\":\"/string[] | string[][]\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"invite\",\"type\":{\"packageName\":\"\",\"name\":\"Invite | undefined\",\"filePath\":null,\"qualifiedName\":\"/Invite | undefined\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"defaultFieldLayout\",\"type\":{\"packageName\":\"\",\"name\":\"string[] | string[][]\",\"filePath\":null,\"qualifiedName\":\"/string[] | string[][]\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"getFormButtons\",\"returnType\":{\"packageName\":\"\",\"name\":\"FormButtons<any>\",\"filePath\":null,\"qualifiedName\":\"/FormButtons<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"invite\",\"type\":{\"packageName\":\"\",\"name\":\"Invite | undefined\",\"filePath\":null,\"qualifiedName\":\"/Invite | undefined\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"defaultFormButtons\",\"type\":{\"packageName\":\"\",\"name\":\"FormButtons<any>\",\"filePath\":null,\"qualifiedName\":\"/FormButtons<any>\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"sendButton\",\"returnType\":{\"packageName\":\"\",\"name\":\"FormButton<any>\",\"filePath\":null,\"qualifiedName\":\"/FormButton<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[{\"name\":\"invite\",\"type\":{\"packageName\":\"\",\"name\":\"Invite | undefined\",\"filePath\":null,\"qualifiedName\":\"/Invite | undefined\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"revokeButton\",\"returnType\":{\"packageName\":\"\",\"name\":\"FormButton<any>\",\"filePath\":null,\"qualifiedName\":\"/FormButton<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[{\"name\":\"invite\",\"type\":{\"packageName\":\"\",\"name\":\"Invite | undefined\",\"filePath\":null,\"qualifiedName\":\"/Invite | undefined\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"isAdmin\",\"returnType\":{\"packageName\":\"\",\"name\":\"boolean\",\"filePath\":null,\"qualifiedName\":\"/boolean\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]}],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db-ui\",\"name\":\"RecordFormCustomization\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db-ui/RecordFormCustomization\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/db-ui/RecordFormCustomization\"},{\"v\":\"@proteinjs/user-ui/forgotPasswordPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"forgotPasswordPage\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa2/packages/proteinjs/packages/user/packages/ui/src/pages/ForgotPassword.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/forgotPasswordPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/ui/Page\"},{\"v\":\"@proteinjs/user-ui/loginPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"loginPage\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa2/packages/proteinjs/packages/user/packages/ui/src/pages/Login.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/loginPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/user-ui/passwordResetPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"passwordResetPage\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa2/packages/proteinjs/packages/user/packages/ui/src/pages/PasswordReset.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/passwordResetPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/user-ui/signupPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"signupPage\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa2/packages/proteinjs/packages/user/packages/ui/src/pages/Signup.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/signupPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}}],\"edges\":[{\"v\":\"@proteinjs/user-ui/InviteRecordFormCustomization\",\"w\":\"@proteinjs/db-ui/RecordFormCustomization\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/user-ui/forgotPasswordPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-ui/loginPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-ui/passwordResetPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-ui/signupPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"}]}";
|
|
32
34
|
/** Generate Source Links */
|
|
35
|
+
var InviteRecordFormCustomization_1 = require("../src/form/InviteRecordFormCustomization");
|
|
33
36
|
var ForgotPassword_1 = require("../src/pages/ForgotPassword");
|
|
34
37
|
var Login_1 = require("../src/pages/Login");
|
|
35
38
|
var PasswordReset_1 = require("../src/pages/PasswordReset");
|
|
36
|
-
var SendInvite_1 = require("../src/pages/SendInvite");
|
|
37
39
|
var Signup_1 = require("../src/pages/Signup");
|
|
38
40
|
var sourceLinks = {
|
|
41
|
+
'@proteinjs/user-ui/InviteRecordFormCustomization': InviteRecordFormCustomization_1.InviteRecordFormCustomization,
|
|
39
42
|
'@proteinjs/user-ui/forgotPasswordPage': ForgotPassword_1.forgotPasswordPage,
|
|
40
43
|
'@proteinjs/user-ui/loginPage': Login_1.loginPage,
|
|
41
44
|
'@proteinjs/user-ui/passwordResetPage': PasswordReset_1.passwordResetPage,
|
|
42
|
-
'@proteinjs/user-ui/invitePage': SendInvite_1.invitePage,
|
|
43
45
|
'@proteinjs/user-ui/signupPage': Signup_1.signupPage,
|
|
44
46
|
};
|
|
45
47
|
/** Load Source Graph and Links */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,+BAA6B;AAC7B,yBAAuB;AACvB,iCAA+B;AAC/B,iCAA+B;AAC/B,yBAAuB;AACvB,2BAAyB;AACzB,2BAAyB;AACzB,kBAAgB;AAChB,iBAAe;AACf,qBAAmB;AACnB,wBAAsB;AACtB,4BAA0B;AAG1B,4BAA4B;AAE5B,IAAM,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,+BAA6B;AAC7B,yBAAuB;AACvB,yBAAuB;AACvB,4BAA0B;AAC1B,iCAA+B;AAC/B,iCAA+B;AAC/B,yBAAuB;AACvB,2BAAyB;AACzB,2BAAyB;AACzB,kBAAgB;AAChB,iBAAe;AACf,qBAAmB;AACnB,wBAAsB;AACtB,4BAA0B;AAG1B,4BAA4B;AAE5B,IAAM,WAAW,GAAG,0kOAA0kO,CAAC;AAG/lO,4BAA4B;AAE5B,2FAA0F;AAC1F,8DAAiE;AACjE,4CAA+C;AAC/C,4DAA+D;AAC/D,8CAAiD;AAEjD,IAAM,WAAW,GAAG;IACnB,kDAAkD,EAAE,6DAA6B;IACjF,uCAAuC,EAAE,mCAAkB;IAC3D,8BAA8B,EAAE,iBAAS;IACzC,sCAAsC,EAAE,iCAAiB;IACzD,+BAA+B,EAAE,mBAAU;CAC3C,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FormButtons } from '@proteinjs/ui';
|
|
2
|
+
import { RecordFormCustomization } from '@proteinjs/db-ui';
|
|
3
|
+
import { Invite } from '@proteinjs/user';
|
|
4
|
+
/**
|
|
5
|
+
* Makes the invite record surface the ONE place invites are managed: the new-record form sends an
|
|
6
|
+
* invite, and an existing invite row can be revoked.
|
|
7
|
+
*
|
|
8
|
+
* Both actions go through `SignupService` rather than raw record writes, because an invite is more
|
|
9
|
+
* than its row — sending mints a token, sets its expiry, stamps the inviter, and emails the signup
|
|
10
|
+
* link; revoking is the invite domain's own delete. Inserting or deleting the row directly would
|
|
11
|
+
* produce invites that can never be redeemed.
|
|
12
|
+
*/
|
|
13
|
+
export declare class InviteRecordFormCustomization extends RecordFormCustomization {
|
|
14
|
+
table: import("@proteinjs/db").Table<Invite>;
|
|
15
|
+
getFieldLayout(invite: Invite | undefined, defaultFieldLayout: string[] | string[][]): string[] | string[][];
|
|
16
|
+
getFormButtons(invite: Invite | undefined, defaultFormButtons: FormButtons<any>): FormButtons<any>;
|
|
17
|
+
private sendButton;
|
|
18
|
+
private revokeButton;
|
|
19
|
+
/**
|
|
20
|
+
* The same admin gate the standalone invite page carried, so these actions aren't offered to users
|
|
21
|
+
* who can't perform them. `SignupService.serviceMetadata.auth` is what actually enforces it.
|
|
22
|
+
*/
|
|
23
|
+
private isAdmin;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=InviteRecordFormCustomization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InviteRecordFormCustomization.d.ts","sourceRoot":"","sources":["../../../src/form/InviteRecordFormCustomization.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsB,WAAW,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAmB,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAoB,MAAM,EAAoB,MAAM,iBAAiB,CAAC;AAG7E;;;;;;;;GAQG;AACH,qBAAa,6BAA8B,SAAQ,uBAAuB;IACjE,KAAK,wCAAiB;IAE7B,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE;IAK5G,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,kBAAkB,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC;IASlG,OAAO,CAAC,UAAU;IA+BlB,OAAO,CAAC,YAAY;IAsBpB;;;OAGG;IACH,OAAO,CAAC,OAAO;CAGhB"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
+
function step(op) {
|
|
42
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
44
|
+
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;
|
|
45
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
+
switch (op[0]) {
|
|
47
|
+
case 0: case 1: t = op; break;
|
|
48
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
+
default:
|
|
52
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
+
if (t[2]) _.ops.pop();
|
|
57
|
+
_.trys.pop(); continue;
|
|
58
|
+
}
|
|
59
|
+
op = body.call(thisArg, _);
|
|
60
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.InviteRecordFormCustomization = void 0;
|
|
66
|
+
var db_ui_1 = require("@proteinjs/db-ui");
|
|
67
|
+
var user_1 = require("@proteinjs/user");
|
|
68
|
+
var util_1 = require("@proteinjs/util");
|
|
69
|
+
/**
|
|
70
|
+
* Makes the invite record surface the ONE place invites are managed: the new-record form sends an
|
|
71
|
+
* invite, and an existing invite row can be revoked.
|
|
72
|
+
*
|
|
73
|
+
* Both actions go through `SignupService` rather than raw record writes, because an invite is more
|
|
74
|
+
* than its row — sending mints a token, sets its expiry, stamps the inviter, and emails the signup
|
|
75
|
+
* link; revoking is the invite domain's own delete. Inserting or deleting the row directly would
|
|
76
|
+
* produce invites that can never be redeemed.
|
|
77
|
+
*/
|
|
78
|
+
var InviteRecordFormCustomization = /** @class */ (function (_super) {
|
|
79
|
+
__extends(InviteRecordFormCustomization, _super);
|
|
80
|
+
function InviteRecordFormCustomization() {
|
|
81
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
82
|
+
_this.table = user_1.tables.Invite;
|
|
83
|
+
return _this;
|
|
84
|
+
}
|
|
85
|
+
InviteRecordFormCustomization.prototype.getFieldLayout = function (invite, defaultFieldLayout) {
|
|
86
|
+
// Sending an invite takes only an email; the token, its expiry, and the inviter are minted server-side.
|
|
87
|
+
return invite ? defaultFieldLayout : ['email'];
|
|
88
|
+
};
|
|
89
|
+
InviteRecordFormCustomization.prototype.getFormButtons = function (invite, defaultFormButtons) {
|
|
90
|
+
var formButtons = __assign({}, defaultFormButtons);
|
|
91
|
+
delete formButtons['create'];
|
|
92
|
+
delete formButtons['delete'];
|
|
93
|
+
formButtons['send'] = this.sendButton(invite);
|
|
94
|
+
formButtons['revoke'] = this.revokeButton(invite);
|
|
95
|
+
return formButtons;
|
|
96
|
+
};
|
|
97
|
+
InviteRecordFormCustomization.prototype.sendButton = function (invite) {
|
|
98
|
+
var _this = this;
|
|
99
|
+
return {
|
|
100
|
+
name: 'Send invite',
|
|
101
|
+
accessibility: {
|
|
102
|
+
hidden: !!invite || !this.isAdmin(),
|
|
103
|
+
},
|
|
104
|
+
style: {
|
|
105
|
+
color: 'primary',
|
|
106
|
+
variant: 'contained',
|
|
107
|
+
},
|
|
108
|
+
onClick: function (fields) { return __awaiter(_this, void 0, void 0, function () {
|
|
109
|
+
var email, response;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
email = fields.email.field.value && fields.email.field.value.trim();
|
|
114
|
+
if (!email) {
|
|
115
|
+
return [2 /*return*/, 'Please enter an email address.'];
|
|
116
|
+
}
|
|
117
|
+
if (!util_1.emailRegex.test(email)) {
|
|
118
|
+
return [2 /*return*/, 'Please enter a valid email address.'];
|
|
119
|
+
}
|
|
120
|
+
return [4 /*yield*/, (0, user_1.getSignupService)().sendInvite(email)];
|
|
121
|
+
case 1:
|
|
122
|
+
response = _a.sent();
|
|
123
|
+
if (response.sent === false) {
|
|
124
|
+
return [2 /*return*/, response.error || 'Failed to send invite.'];
|
|
125
|
+
}
|
|
126
|
+
return [2 /*return*/, "Sent invite to ".concat(email)];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}); },
|
|
130
|
+
progressMessage: function () { return "Sending invite"; },
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
InviteRecordFormCustomization.prototype.revokeButton = function (invite) {
|
|
134
|
+
var _this = this;
|
|
135
|
+
return {
|
|
136
|
+
name: 'Revoke',
|
|
137
|
+
accessibility: {
|
|
138
|
+
hidden: !invite || !this.isAdmin(),
|
|
139
|
+
},
|
|
140
|
+
style: {
|
|
141
|
+
color: 'primary',
|
|
142
|
+
variant: 'text',
|
|
143
|
+
},
|
|
144
|
+
// The row is gone once revoked, so return to the table rather than leave a form over nothing.
|
|
145
|
+
redirect: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
return [2 /*return*/, { path: (0, db_ui_1.recordTableLink)(user_1.tables.Invite) }];
|
|
148
|
+
});
|
|
149
|
+
}); },
|
|
150
|
+
onClick: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
151
|
+
return __generator(this, function (_a) {
|
|
152
|
+
switch (_a.label) {
|
|
153
|
+
case 0: return [4 /*yield*/, (0, user_1.getSignupService)().revokeInvite(invite.email)];
|
|
154
|
+
case 1:
|
|
155
|
+
_a.sent();
|
|
156
|
+
return [2 /*return*/, "Revoked invite to ".concat(invite.email)];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}); },
|
|
160
|
+
progressMessage: function () { return "Revoking invite"; },
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* The same admin gate the standalone invite page carried, so these actions aren't offered to users
|
|
165
|
+
* who can't perform them. `SignupService.serviceMetadata.auth` is what actually enforces it.
|
|
166
|
+
*/
|
|
167
|
+
InviteRecordFormCustomization.prototype.isAdmin = function () {
|
|
168
|
+
return user_1.UserAuth.hasRole('admin');
|
|
169
|
+
};
|
|
170
|
+
return InviteRecordFormCustomization;
|
|
171
|
+
}(db_ui_1.RecordFormCustomization));
|
|
172
|
+
exports.InviteRecordFormCustomization = InviteRecordFormCustomization;
|
|
173
|
+
//# sourceMappingURL=InviteRecordFormCustomization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InviteRecordFormCustomization.js","sourceRoot":"","sources":["../../../src/form/InviteRecordFormCustomization.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0CAA4E;AAC5E,wCAA6E;AAC7E,wCAA6C;AAE7C;;;;;;;;GAQG;AACH;IAAmD,iDAAuB;IAA1E;QAAA,qEA6EC;QA5EQ,WAAK,GAAG,aAAM,CAAC,MAAM,CAAC;;IA4E/B,CAAC;IA1EC,sDAAc,GAAd,UAAe,MAA0B,EAAE,kBAAyC;QAClF,wGAAwG;QACxG,OAAO,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,sDAAc,GAAd,UAAe,MAA0B,EAAE,kBAAoC;QAC7E,IAAM,WAAW,gBAAQ,kBAAkB,CAAE,CAAC;QAC9C,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC7B,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC9C,WAAW,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAClD,OAAO,WAAW,CAAC;IACrB,CAAC;IAEO,kDAAU,GAAlB,UAAmB,MAA0B;QAA7C,iBA6BC;QA5BC,OAAO;YACL,IAAI,EAAE,aAAa;YACnB,a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;gCACP,qBAAM,IAAA,uBAAgB,GAAE,CAAC,YAAY,CAAE,MAAiB,CAAC,KAAK,CAAC,EAAA;;4BAA/D,SAA+D,CAAC;4BAChE,sBAAO,4BAAsB,MAAiB,CAAC,KAAK,CAAE,EAAC;;;iBACxD;YACD,eAAe,EAAE,cAAM,OAAA,iBAAiB,EAAjB,CAAiB;SACzC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACK,+CAAO,GAAf;QACE,OAAO,eAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IACH,oCAAC;AAAD,CAAC,AA7ED,CAAmD,+BAAuB,GA6EzE;AA7EY,sEAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InviteRecordFormCustomization.test.d.ts","sourceRoot":"","sources":["../../test/InviteRecordFormCustomization.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var user_1 = require("@proteinjs/user");
|
|
4
|
+
var InviteRecordFormCustomization_1 = require("../src/form/InviteRecordFormCustomization");
|
|
5
|
+
var setRoles = function (roles) {
|
|
6
|
+
user_1.UserAuth.userRepo = {
|
|
7
|
+
getUser: function () { return ({ email: 'someone@n3xa.io', roles: roles }); },
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
var defaultFormButtons = function () { return ({
|
|
11
|
+
delete: { name: 'Delete', style: {} },
|
|
12
|
+
save: { name: 'Save', style: {} },
|
|
13
|
+
create: { name: 'Create', style: {} },
|
|
14
|
+
}); };
|
|
15
|
+
var defaultFieldLayout = ['email', 'token', 'tokenExpiresAt', 'invitedBy'];
|
|
16
|
+
var existingInvite = { id: 'invite-1', email: 'invitee@n3xa.io' };
|
|
17
|
+
var visibleButtons = function (record) {
|
|
18
|
+
var buttons = new InviteRecordFormCustomization_1.InviteRecordFormCustomization().getFormButtons(record, defaultFormButtons());
|
|
19
|
+
return Object.keys(buttons).filter(function (name) { var _a; return !((_a = buttons[name].accessibility) === null || _a === void 0 ? void 0 : _a.hidden); });
|
|
20
|
+
};
|
|
21
|
+
describe('Invite record form customization', function () {
|
|
22
|
+
afterEach(function () {
|
|
23
|
+
user_1.UserAuth.userRepo = undefined;
|
|
24
|
+
});
|
|
25
|
+
it('replaces raw record create/delete with send/revoke', function () {
|
|
26
|
+
setRoles(['admin']);
|
|
27
|
+
var buttons = new InviteRecordFormCustomization_1.InviteRecordFormCustomization().getFormButtons(existingInvite, defaultFormButtons());
|
|
28
|
+
expect(Object.keys(buttons)).not.toContain('create');
|
|
29
|
+
expect(Object.keys(buttons)).not.toContain('delete');
|
|
30
|
+
});
|
|
31
|
+
it('offers an admin Send invite on the new-record form and Revoke on an existing invite', function () {
|
|
32
|
+
setRoles(['admin']);
|
|
33
|
+
expect(visibleButtons(undefined)).toContain('send');
|
|
34
|
+
expect(visibleButtons(undefined)).not.toContain('revoke');
|
|
35
|
+
expect(visibleButtons(existingInvite)).toContain('revoke');
|
|
36
|
+
expect(visibleButtons(existingInvite)).not.toContain('send');
|
|
37
|
+
});
|
|
38
|
+
it('offers a non-admin neither action', function () {
|
|
39
|
+
setRoles([]);
|
|
40
|
+
expect(visibleButtons(undefined)).not.toContain('send');
|
|
41
|
+
expect(visibleButtons(undefined)).not.toContain('revoke');
|
|
42
|
+
expect(visibleButtons(existingInvite)).not.toContain('send');
|
|
43
|
+
expect(visibleButtons(existingInvite)).not.toContain('revoke');
|
|
44
|
+
});
|
|
45
|
+
it('asks only for an email when sending, and shows the whole record otherwise', function () {
|
|
46
|
+
var customization = new InviteRecordFormCustomization_1.InviteRecordFormCustomization();
|
|
47
|
+
expect(customization.getFieldLayout(undefined, defaultFieldLayout)).toEqual(['email']);
|
|
48
|
+
expect(customization.getFieldLayout(existingInvite, defaultFieldLayout)).toEqual(defaultFieldLayout);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=InviteRecordFormCustomization.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InviteRecordFormCustomization.test.js","sourceRoot":"","sources":["../../test/InviteRecordFormCustomization.test.ts"],"names":[],"mappings":";;AACA,wCAAmD;AACnD,2FAA0F;AAa1F,IAAM,QAAQ,GAAG,UAAC,KAAe;IAC9B,eAAyC,CAAC,QAAQ,GAAG;QACpD,OAAO,EAAE,cAAM,OAAA,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,OAAA,EAAE,CAAC,EAArC,CAAqC;KACrD,CAAC;AACJ,CAAC,CAAC;AAEF,IAAM,kBAAkB,GAAG,cAAwB,OAAA,CAAC;IAClD,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE;IACrC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE;IACjC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE;CACtC,CAAC,EAJiD,CAIjD,CAAC;AAEH,IAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,WAAW,CAAC,CAAC;AAC7E,IAAM,cAAc,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAY,CAAC;AAE9E,IAAM,cAAc,GAAG,UAAC,MAA0B;IAChD,IAAM,OAAO,GAAG,IAAI,6DAA6B,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACjG,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,UAAC,IAAI,YAAK,OAAA,CAAC,CAAA,MAAA,OAAO,CAAC,IAAI,CAAC,CAAC,aAAa,0CAAE,MAAM,CAAA,CAAA,EAAA,CAAC,CAAC;AACrF,CAAC,CAAC;AAEF,QAAQ,CAAC,kCAAkC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AC,QAAQ,CAAC,CAAC;QAC1D,MAAM,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC7D,MAAM,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2EAA2E,EAAE;QAC9E,IAAM,aAAa,GAAG,IAAI,6DAA6B,EAAE,CAAC;QAC1D,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QACvF,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACvG,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/generated/index.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import '@mui/icons-material';
|
|
4
4
|
import '@mui/material';
|
|
5
|
+
import '@proteinjs/db';
|
|
6
|
+
import '@proteinjs/db-ui';
|
|
5
7
|
import '@proteinjs/reflection';
|
|
6
8
|
import '@proteinjs/server-api';
|
|
7
9
|
import '@proteinjs/ui';
|
|
@@ -16,22 +18,22 @@ import 'react-router-dom';
|
|
|
16
18
|
|
|
17
19
|
/** Generate Source Graph */
|
|
18
20
|
|
|
19
|
-
const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"/Omit\"},{\"v\":\"@proteinjs/user-ui/
|
|
21
|
+
const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"/Omit\"},{\"v\":\"@proteinjs/user-ui/InviteRecordFormCustomization\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"InviteRecordFormCustomization\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa2/packages/proteinjs/packages/user/packages/ui/src/form/InviteRecordFormCustomization.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/InviteRecordFormCustomization\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"table\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getFieldLayout\",\"returnType\":{\"packageName\":\"\",\"name\":\"string[] | string[][]\",\"filePath\":null,\"qualifiedName\":\"/string[] | string[][]\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"invite\",\"type\":{\"packageName\":\"\",\"name\":\"Invite | undefined\",\"filePath\":null,\"qualifiedName\":\"/Invite | undefined\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"defaultFieldLayout\",\"type\":{\"packageName\":\"\",\"name\":\"string[] | string[][]\",\"filePath\":null,\"qualifiedName\":\"/string[] | string[][]\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"getFormButtons\",\"returnType\":{\"packageName\":\"\",\"name\":\"FormButtons<any>\",\"filePath\":null,\"qualifiedName\":\"/FormButtons<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"invite\",\"type\":{\"packageName\":\"\",\"name\":\"Invite | undefined\",\"filePath\":null,\"qualifiedName\":\"/Invite | undefined\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"defaultFormButtons\",\"type\":{\"packageName\":\"\",\"name\":\"FormButtons<any>\",\"filePath\":null,\"qualifiedName\":\"/FormButtons<any>\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"sendButton\",\"returnType\":{\"packageName\":\"\",\"name\":\"FormButton<any>\",\"filePath\":null,\"qualifiedName\":\"/FormButton<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[{\"name\":\"invite\",\"type\":{\"packageName\":\"\",\"name\":\"Invite | undefined\",\"filePath\":null,\"qualifiedName\":\"/Invite | undefined\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"revokeButton\",\"returnType\":{\"packageName\":\"\",\"name\":\"FormButton<any>\",\"filePath\":null,\"qualifiedName\":\"/FormButton<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[{\"name\":\"invite\",\"type\":{\"packageName\":\"\",\"name\":\"Invite | undefined\",\"filePath\":null,\"qualifiedName\":\"/Invite | undefined\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"isAdmin\",\"returnType\":{\"packageName\":\"\",\"name\":\"boolean\",\"filePath\":null,\"qualifiedName\":\"/boolean\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]}],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db-ui\",\"name\":\"RecordFormCustomization\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db-ui/RecordFormCustomization\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/db-ui/RecordFormCustomization\"},{\"v\":\"@proteinjs/user-ui/forgotPasswordPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"forgotPasswordPage\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa2/packages/proteinjs/packages/user/packages/ui/src/pages/ForgotPassword.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/forgotPasswordPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/ui/Page\"},{\"v\":\"@proteinjs/user-ui/loginPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"loginPage\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa2/packages/proteinjs/packages/user/packages/ui/src/pages/Login.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/loginPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/user-ui/passwordResetPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"passwordResetPage\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa2/packages/proteinjs/packages/user/packages/ui/src/pages/PasswordReset.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/passwordResetPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/user-ui/signupPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"signupPage\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa2/packages/proteinjs/packages/user/packages/ui/src/pages/Signup.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/signupPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}}],\"edges\":[{\"v\":\"@proteinjs/user-ui/InviteRecordFormCustomization\",\"w\":\"@proteinjs/db-ui/RecordFormCustomization\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/user-ui/forgotPasswordPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-ui/loginPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-ui/passwordResetPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-ui/signupPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"}]}";
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
/** Generate Source Links */
|
|
23
25
|
|
|
26
|
+
import { InviteRecordFormCustomization } from '../src/form/InviteRecordFormCustomization';
|
|
24
27
|
import { forgotPasswordPage } from '../src/pages/ForgotPassword';
|
|
25
28
|
import { loginPage } from '../src/pages/Login';
|
|
26
29
|
import { passwordResetPage } from '../src/pages/PasswordReset';
|
|
27
|
-
import { invitePage } from '../src/pages/SendInvite';
|
|
28
30
|
import { signupPage } from '../src/pages/Signup';
|
|
29
31
|
|
|
30
32
|
const sourceLinks = {
|
|
33
|
+
'@proteinjs/user-ui/InviteRecordFormCustomization': InviteRecordFormCustomization,
|
|
31
34
|
'@proteinjs/user-ui/forgotPasswordPage': forgotPasswordPage,
|
|
32
35
|
'@proteinjs/user-ui/loginPage': loginPage,
|
|
33
36
|
'@proteinjs/user-ui/passwordResetPage': passwordResetPage,
|
|
34
|
-
'@proteinjs/user-ui/invitePage': invitePage,
|
|
35
37
|
'@proteinjs/user-ui/signupPage': signupPage,
|
|
36
38
|
};
|
|
37
39
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/user-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "User ui components",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -18,15 +18,18 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"clean": "rm -rf dist/ generated/ node_modules/",
|
|
20
20
|
"build": "reflection-build && tsc",
|
|
21
|
-
"watch": "reflection-watch"
|
|
21
|
+
"watch": "reflection-watch",
|
|
22
|
+
"test": "jest --passWithNoTests"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"@mui/icons-material": "5.14.11",
|
|
25
26
|
"@mui/material": "5.14.11",
|
|
27
|
+
"@proteinjs/db": "^1.26.0",
|
|
28
|
+
"@proteinjs/db-ui": "^1.6.0",
|
|
26
29
|
"@proteinjs/reflection": "^1.1.12",
|
|
27
30
|
"@proteinjs/server-api": "^3.0.10",
|
|
28
|
-
"@proteinjs/ui": "^4.
|
|
29
|
-
"@proteinjs/user": "^1.
|
|
31
|
+
"@proteinjs/ui": "^4.4.0",
|
|
32
|
+
"@proteinjs/user": "^1.6.0",
|
|
30
33
|
"@proteinjs/util": "^1.6.1",
|
|
31
34
|
"moment": "2.29.4",
|
|
32
35
|
"react": "18.2.0",
|
|
@@ -36,6 +39,7 @@
|
|
|
36
39
|
},
|
|
37
40
|
"devDependencies": {
|
|
38
41
|
"@proteinjs/reflection-build": "^1.4.10",
|
|
42
|
+
"@types/jest": "^29.5.12",
|
|
39
43
|
"@types/node": "14.0.13",
|
|
40
44
|
"@types/react": "18.2.23",
|
|
41
45
|
"@types/react-dom": "18.2.8",
|
|
@@ -45,6 +49,8 @@
|
|
|
45
49
|
"eslint": "8.57.0",
|
|
46
50
|
"eslint-config-prettier": "9.1.0",
|
|
47
51
|
"eslint-plugin-prettier": "5.1.3",
|
|
52
|
+
"jest": "^29.7.0",
|
|
53
|
+
"ts-jest": "^29.1.2",
|
|
48
54
|
"typescript": "5.2.2"
|
|
49
55
|
},
|
|
50
56
|
"main": "./dist/generated/index.js",
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Fields, FormButton, FormButtons } from '@proteinjs/ui';
|
|
2
|
+
import { RecordFormCustomization, recordTableLink } from '@proteinjs/db-ui';
|
|
3
|
+
import { getSignupService, Invite, tables, UserAuth } from '@proteinjs/user';
|
|
4
|
+
import { emailRegex } from '@proteinjs/util';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Makes the invite record surface the ONE place invites are managed: the new-record form sends an
|
|
8
|
+
* invite, and an existing invite row can be revoked.
|
|
9
|
+
*
|
|
10
|
+
* Both actions go through `SignupService` rather than raw record writes, because an invite is more
|
|
11
|
+
* than its row — sending mints a token, sets its expiry, stamps the inviter, and emails the signup
|
|
12
|
+
* link; revoking is the invite domain's own delete. Inserting or deleting the row directly would
|
|
13
|
+
* produce invites that can never be redeemed.
|
|
14
|
+
*/
|
|
15
|
+
export class InviteRecordFormCustomization extends RecordFormCustomization {
|
|
16
|
+
public table = tables.Invite;
|
|
17
|
+
|
|
18
|
+
getFieldLayout(invite: Invite | undefined, defaultFieldLayout: string[] | string[][]): string[] | string[][] {
|
|
19
|
+
// Sending an invite takes only an email; the token, its expiry, and the inviter are minted server-side.
|
|
20
|
+
return invite ? defaultFieldLayout : ['email'];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getFormButtons(invite: Invite | undefined, defaultFormButtons: FormButtons<any>): FormButtons<any> {
|
|
24
|
+
const formButtons = { ...defaultFormButtons };
|
|
25
|
+
delete formButtons['create'];
|
|
26
|
+
delete formButtons['delete'];
|
|
27
|
+
formButtons['send'] = this.sendButton(invite);
|
|
28
|
+
formButtons['revoke'] = this.revokeButton(invite);
|
|
29
|
+
return formButtons;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private sendButton(invite: Invite | undefined): FormButton<any> {
|
|
33
|
+
return {
|
|
34
|
+
name: 'Send invite',
|
|
35
|
+
accessibility: {
|
|
36
|
+
hidden: !!invite || !this.isAdmin(),
|
|
37
|
+
},
|
|
38
|
+
style: {
|
|
39
|
+
color: 'primary',
|
|
40
|
+
variant: 'contained',
|
|
41
|
+
},
|
|
42
|
+
onClick: async (fields: Fields) => {
|
|
43
|
+
const email = fields.email.field.value && fields.email.field.value.trim();
|
|
44
|
+
if (!email) {
|
|
45
|
+
return 'Please enter an email address.';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!emailRegex.test(email)) {
|
|
49
|
+
return 'Please enter a valid email address.';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const response = await getSignupService().sendInvite(email);
|
|
53
|
+
if (response.sent === false) {
|
|
54
|
+
return response.error || 'Failed to send invite.';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return `Sent invite to ${email}`;
|
|
58
|
+
},
|
|
59
|
+
progressMessage: () => `Sending invite`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private revokeButton(invite: Invite | undefined): FormButton<any> {
|
|
64
|
+
return {
|
|
65
|
+
name: 'Revoke',
|
|
66
|
+
accessibility: {
|
|
67
|
+
hidden: !invite || !this.isAdmin(),
|
|
68
|
+
},
|
|
69
|
+
style: {
|
|
70
|
+
color: 'primary',
|
|
71
|
+
variant: 'text',
|
|
72
|
+
},
|
|
73
|
+
// The row is gone once revoked, so return to the table rather than leave a form over nothing.
|
|
74
|
+
redirect: async () => {
|
|
75
|
+
return { path: recordTableLink(tables.Invite) };
|
|
76
|
+
},
|
|
77
|
+
onClick: async () => {
|
|
78
|
+
await getSignupService().revokeInvite((invite as Invite).email);
|
|
79
|
+
return `Revoked invite to ${(invite as Invite).email}`;
|
|
80
|
+
},
|
|
81
|
+
progressMessage: () => `Revoking invite`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The same admin gate the standalone invite page carried, so these actions aren't offered to users
|
|
87
|
+
* who can't perform them. `SignupService.serviceMetadata.auth` is what actually enforces it.
|
|
88
|
+
*/
|
|
89
|
+
private isAdmin(): boolean {
|
|
90
|
+
return UserAuth.hasRole('admin');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { FormButtons } from '@proteinjs/ui';
|
|
2
|
+
import { Invite, UserAuth } from '@proteinjs/user';
|
|
3
|
+
import { InviteRecordFormCustomization } from '../src/form/InviteRecordFormCustomization';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Invites are managed from the invite record surface: the new-record form sends one, an existing
|
|
7
|
+
* invite row revokes one. Both actions are admin-only — `SignupService.serviceMetadata.auth` is the
|
|
8
|
+
* enforcement (covered in @proteinjs/user-server), and these assertions cover the affordances, so a
|
|
9
|
+
* non-admin is never offered a button that can only fail.
|
|
10
|
+
*
|
|
11
|
+
* `UserAuth` reads from a static repo; stubbing it directly is how the server-side authz tests do it.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
type UserAuthInternals = { userRepo?: { getUser: () => { email: string; roles: string[] } } };
|
|
15
|
+
|
|
16
|
+
const setRoles = (roles: string[]) => {
|
|
17
|
+
(UserAuth as unknown as UserAuthInternals).userRepo = {
|
|
18
|
+
getUser: () => ({ email: 'someone@n3xa.io', roles }),
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const defaultFormButtons = (): FormButtons<any> => ({
|
|
23
|
+
delete: { name: 'Delete', style: {} },
|
|
24
|
+
save: { name: 'Save', style: {} },
|
|
25
|
+
create: { name: 'Create', style: {} },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const defaultFieldLayout = ['email', 'token', 'tokenExpiresAt', 'invitedBy'];
|
|
29
|
+
const existingInvite = { id: 'invite-1', email: 'invitee@n3xa.io' } as Invite;
|
|
30
|
+
|
|
31
|
+
const visibleButtons = (record: Invite | undefined) => {
|
|
32
|
+
const buttons = new InviteRecordFormCustomization().getFormButtons(record, defaultFormButtons());
|
|
33
|
+
return Object.keys(buttons).filter((name) => !buttons[name].accessibility?.hidden);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
describe('Invite record form customization', () => {
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
(UserAuth as unknown as UserAuthInternals).userRepo = undefined;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('replaces raw record create/delete with send/revoke', () => {
|
|
42
|
+
setRoles(['admin']);
|
|
43
|
+
const buttons = new InviteRecordFormCustomization().getFormButtons(existingInvite, defaultFormButtons());
|
|
44
|
+
expect(Object.keys(buttons)).not.toContain('create');
|
|
45
|
+
expect(Object.keys(buttons)).not.toContain('delete');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('offers an admin Send invite on the new-record form and Revoke on an existing invite', () => {
|
|
49
|
+
setRoles(['admin']);
|
|
50
|
+
expect(visibleButtons(undefined)).toContain('send');
|
|
51
|
+
expect(visibleButtons(undefined)).not.toContain('revoke');
|
|
52
|
+
expect(visibleButtons(existingInvite)).toContain('revoke');
|
|
53
|
+
expect(visibleButtons(existingInvite)).not.toContain('send');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('offers a non-admin neither action', () => {
|
|
57
|
+
setRoles([]);
|
|
58
|
+
expect(visibleButtons(undefined)).not.toContain('send');
|
|
59
|
+
expect(visibleButtons(undefined)).not.toContain('revoke');
|
|
60
|
+
expect(visibleButtons(existingInvite)).not.toContain('send');
|
|
61
|
+
expect(visibleButtons(existingInvite)).not.toContain('revoke');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('asks only for an email when sending, and shows the whole record otherwise', () => {
|
|
65
|
+
const customization = new InviteRecordFormCustomization();
|
|
66
|
+
expect(customization.getFieldLayout(undefined, defaultFieldLayout)).toEqual(['email']);
|
|
67
|
+
expect(customization.getFieldLayout(existingInvite, defaultFieldLayout)).toEqual(defaultFieldLayout);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SendInvite.d.ts","sourceRoot":"","sources":["../../../src/pages/SendInvite.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAkD,MAAM,eAAe,CAAC;AAKrF,eAAO,MAAM,UAAU,EAAE,IA2BxB,CAAC"}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
-
};
|
|
56
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
exports.invitePage = void 0;
|
|
58
|
-
var react_1 = __importDefault(require("react"));
|
|
59
|
-
var ui_1 = require("@proteinjs/ui");
|
|
60
|
-
var user_1 = require("@proteinjs/user");
|
|
61
|
-
var util_1 = require("@proteinjs/util");
|
|
62
|
-
var material_1 = require("@mui/material");
|
|
63
|
-
exports.invitePage = {
|
|
64
|
-
name: 'Send an Invite',
|
|
65
|
-
path: user_1.uiRoutes.admin.invite,
|
|
66
|
-
auth: {
|
|
67
|
-
roles: ['admin'],
|
|
68
|
-
},
|
|
69
|
-
component: function () { return (react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 4, mt: 2 },
|
|
70
|
-
react_1.default.createElement(ui_1.FormPage, { gridItemProps: { width: '400px' } },
|
|
71
|
-
react_1.default.createElement(ui_1.Form, { name: 'Send an Invite', createFields: function () { return new InviteFields(); }, fieldLayout: ['email'], buttons: buttons })),
|
|
72
|
-
react_1.default.createElement(ui_1.FormPage, { gridItemProps: { width: '400px' } },
|
|
73
|
-
react_1.default.createElement(ui_1.Form, { name: 'Revoke an Invite', createFields: function () { return new RevokeInviteFields(); }, fieldLayout: ['email'], buttons: revokeInviteButtons })))); },
|
|
74
|
-
};
|
|
75
|
-
var InviteFields = /** @class */ (function (_super) {
|
|
76
|
-
__extends(InviteFields, _super);
|
|
77
|
-
function InviteFields() {
|
|
78
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
79
|
-
_this.email = (0, ui_1.textField)({
|
|
80
|
-
name: 'email',
|
|
81
|
-
});
|
|
82
|
-
return _this;
|
|
83
|
-
}
|
|
84
|
-
InviteFields.create = function () {
|
|
85
|
-
return new InviteFields();
|
|
86
|
-
};
|
|
87
|
-
return InviteFields;
|
|
88
|
-
}(ui_1.Fields));
|
|
89
|
-
var buttons = {
|
|
90
|
-
signup: {
|
|
91
|
-
name: 'Send',
|
|
92
|
-
style: {
|
|
93
|
-
color: 'primary',
|
|
94
|
-
variant: 'contained',
|
|
95
|
-
},
|
|
96
|
-
onClick: function (fields, buttons) { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
-
var email, response;
|
|
98
|
-
return __generator(this, function (_a) {
|
|
99
|
-
switch (_a.label) {
|
|
100
|
-
case 0:
|
|
101
|
-
email = fields.email.field.value && fields.email.field.value.trim();
|
|
102
|
-
if (!email) {
|
|
103
|
-
return [2 /*return*/, 'Please enter an email address.'];
|
|
104
|
-
}
|
|
105
|
-
if (!util_1.emailRegex.test(email)) {
|
|
106
|
-
return [2 /*return*/, 'Please enter a valid email address.'];
|
|
107
|
-
}
|
|
108
|
-
return [4 /*yield*/, (0, user_1.getSignupService)().sendInvite(email)];
|
|
109
|
-
case 1:
|
|
110
|
-
response = _a.sent();
|
|
111
|
-
if (response.sent === false) {
|
|
112
|
-
return [2 /*return*/, response.error || 'Failed to send invite.'];
|
|
113
|
-
}
|
|
114
|
-
return [2 /*return*/, "Successfully sent invite to ".concat(email, "!")];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}); },
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
var RevokeInviteFields = /** @class */ (function (_super) {
|
|
121
|
-
__extends(RevokeInviteFields, _super);
|
|
122
|
-
function RevokeInviteFields() {
|
|
123
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
124
|
-
_this.email = (0, ui_1.textField)({
|
|
125
|
-
name: 'email',
|
|
126
|
-
});
|
|
127
|
-
return _this;
|
|
128
|
-
}
|
|
129
|
-
RevokeInviteFields.create = function () {
|
|
130
|
-
return new InviteFields();
|
|
131
|
-
};
|
|
132
|
-
return RevokeInviteFields;
|
|
133
|
-
}(ui_1.Fields));
|
|
134
|
-
var revokeInviteButtons = {
|
|
135
|
-
signup: {
|
|
136
|
-
name: 'Revoke',
|
|
137
|
-
style: {
|
|
138
|
-
color: 'primary',
|
|
139
|
-
variant: 'contained',
|
|
140
|
-
},
|
|
141
|
-
onClick: function (fields, buttons) { return __awaiter(void 0, void 0, void 0, function () {
|
|
142
|
-
var email, _a;
|
|
143
|
-
return __generator(this, function (_b) {
|
|
144
|
-
switch (_b.label) {
|
|
145
|
-
case 0:
|
|
146
|
-
email = fields.email.field.value && fields.email.field.value.trim();
|
|
147
|
-
if (!email) {
|
|
148
|
-
return [2 /*return*/, 'Please enter an email address.'];
|
|
149
|
-
}
|
|
150
|
-
if (!util_1.emailRegex.test(email)) {
|
|
151
|
-
return [2 /*return*/, 'Please enter a valid email address.'];
|
|
152
|
-
}
|
|
153
|
-
_b.label = 1;
|
|
154
|
-
case 1:
|
|
155
|
-
_b.trys.push([1, 3, , 4]);
|
|
156
|
-
return [4 /*yield*/, (0, user_1.getSignupService)().revokeInvite(email)];
|
|
157
|
-
case 2:
|
|
158
|
-
_b.sent();
|
|
159
|
-
return [3 /*break*/, 4];
|
|
160
|
-
case 3:
|
|
161
|
-
_a = _b.sent();
|
|
162
|
-
return [2 /*return*/, "Revoke invite failed."];
|
|
163
|
-
case 4: return [2 /*return*/, "Successfully revoked invite to ".concat(email, ".")];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}); },
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
//# sourceMappingURL=SendInvite.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file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AAE,OAAwC;;;;;wBAC5E,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;wBAE1E,IAAI,CAAC,KAAK,EAAE;4BACV,sBAAO,gCAAgC,EAAC;yBACzC;wBAED,IAAI,CAAC,iBAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;4BAC3B,sBAAO,qCAAqC,EAAC;yBAC9C;;;;wBAGC,qBAAM,IAAA,uBAAgB,GAAE,CAAC,YAAY,CAAC,KAAK,CAAC,EAAA;;wBAA5C,SAA4C,CAAC;;;;wBAE7C,sBAAO,uBAAuB,EAAC;4BAGjC,sBAAO,yCAAkC,KAAK,MAAG,EAAC;;;aACnD;KACF;CACF,CAAC"}
|
package/src/pages/SendInvite.tsx
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Page, Form, Fields, textField, FormButtons, FormPage } from '@proteinjs/ui';
|
|
3
|
-
import { getSignupService, uiRoutes } from '@proteinjs/user';
|
|
4
|
-
import { emailRegex } from '@proteinjs/util';
|
|
5
|
-
import { Stack } from '@mui/material';
|
|
6
|
-
|
|
7
|
-
export const invitePage: Page = {
|
|
8
|
-
name: 'Send an Invite',
|
|
9
|
-
path: uiRoutes.admin.invite,
|
|
10
|
-
auth: {
|
|
11
|
-
roles: ['admin'],
|
|
12
|
-
},
|
|
13
|
-
component: () => (
|
|
14
|
-
<Stack direction='column' spacing={4} mt={2}>
|
|
15
|
-
<FormPage gridItemProps={{ width: '400px' }}>
|
|
16
|
-
<Form<InviteFields, typeof buttons>
|
|
17
|
-
name='Send an Invite'
|
|
18
|
-
createFields={() => new InviteFields()}
|
|
19
|
-
fieldLayout={['email']}
|
|
20
|
-
buttons={buttons}
|
|
21
|
-
/>
|
|
22
|
-
</FormPage>
|
|
23
|
-
|
|
24
|
-
<FormPage gridItemProps={{ width: '400px' }}>
|
|
25
|
-
<Form<RevokeInviteFields, typeof revokeInviteButtons>
|
|
26
|
-
name='Revoke an Invite'
|
|
27
|
-
createFields={() => new RevokeInviteFields()}
|
|
28
|
-
fieldLayout={['email']}
|
|
29
|
-
buttons={revokeInviteButtons}
|
|
30
|
-
/>
|
|
31
|
-
</FormPage>
|
|
32
|
-
</Stack>
|
|
33
|
-
),
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
class InviteFields extends Fields {
|
|
37
|
-
static create() {
|
|
38
|
-
return new InviteFields();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
email = textField<InviteFields>({
|
|
42
|
-
name: 'email',
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const buttons: FormButtons<InviteFields> = {
|
|
47
|
-
signup: {
|
|
48
|
-
name: 'Send',
|
|
49
|
-
style: {
|
|
50
|
-
color: 'primary',
|
|
51
|
-
variant: 'contained',
|
|
52
|
-
},
|
|
53
|
-
onClick: async (fields: InviteFields, buttons: FormButtons<InviteFields>) => {
|
|
54
|
-
const email = fields.email.field.value && fields.email.field.value.trim();
|
|
55
|
-
|
|
56
|
-
if (!email) {
|
|
57
|
-
return 'Please enter an email address.';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (!emailRegex.test(email)) {
|
|
61
|
-
return 'Please enter a valid email address.';
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const response = await getSignupService().sendInvite(email);
|
|
65
|
-
if (response.sent === false) {
|
|
66
|
-
return response.error || 'Failed to send invite.';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return `Successfully sent invite to ${email}!`;
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
class RevokeInviteFields extends Fields {
|
|
75
|
-
static create() {
|
|
76
|
-
return new InviteFields();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
email = textField<InviteFields>({
|
|
80
|
-
name: 'email',
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const revokeInviteButtons: FormButtons<RevokeInviteFields> = {
|
|
85
|
-
signup: {
|
|
86
|
-
name: 'Revoke',
|
|
87
|
-
style: {
|
|
88
|
-
color: 'primary',
|
|
89
|
-
variant: 'contained',
|
|
90
|
-
},
|
|
91
|
-
onClick: async (fields: RevokeInviteFields, buttons: FormButtons<RevokeInviteFields>) => {
|
|
92
|
-
const email = fields.email.field.value && fields.email.field.value.trim();
|
|
93
|
-
|
|
94
|
-
if (!email) {
|
|
95
|
-
return 'Please enter an email address.';
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!emailRegex.test(email)) {
|
|
99
|
-
return 'Please enter a valid email address.';
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
await getSignupService().revokeInvite(email);
|
|
104
|
-
} catch {
|
|
105
|
-
return `Revoke invite failed.`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return `Successfully revoked invite to ${email}.`;
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
};
|