authscape-usermanagement 1.0.22 → 1.0.26

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/index.js CHANGED
@@ -1,5 +1,202 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CSVUsersUpload = CSVUsersUpload;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _system = require("@mui/system");
10
+ var _Dialog = _interopRequireDefault(require("@mui/material/Dialog"));
11
+ var _DialogActions = _interopRequireDefault(require("@mui/material/DialogActions"));
12
+ var _DialogContent = _interopRequireDefault(require("@mui/material/DialogContent"));
13
+ var _DialogContentText = _interopRequireDefault(require("@mui/material/DialogContentText"));
14
+ var _DialogTitle = _interopRequireDefault(require("@mui/material/DialogTitle"));
15
+ var _material = require("@mui/material");
16
+ var _authscape = require("authscape");
17
+ var _Stepper = _interopRequireDefault(require("@mui/material/Stepper"));
18
+ var _Step = _interopRequireDefault(require("@mui/material/Step"));
19
+ var _StepButton = _interopRequireDefault(require("@mui/material/StepButton"));
20
+ var _CloudDownloadRounded = _interopRequireDefault(require("@mui/icons-material/CloudDownloadRounded"));
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
24
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
25
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
26
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
27
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
28
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
29
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
30
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
31
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
32
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
33
+ function CSVUsersUpload(_ref) {
34
+ var customFields = _ref.customFields,
35
+ showDialog = _ref.showDialog,
36
+ _onClose = _ref.onClose;
37
+ var _React$useState = _react["default"].useState(0),
38
+ _React$useState2 = _slicedToArray(_React$useState, 2),
39
+ activeStep = _React$useState2[0],
40
+ setActiveStep = _React$useState2[1];
41
+ var _React$useState3 = _react["default"].useState({}),
42
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
43
+ completed = _React$useState4[0],
44
+ setCompleted = _React$useState4[1];
45
+ var steps = ['Download CSV Template', 'Upload CSV Template'];
46
+ var totalSteps = function totalSteps() {
47
+ return steps.length;
48
+ };
49
+ var completedSteps = function completedSteps() {
50
+ return Object.keys(completed).length;
51
+ };
52
+ var isLastStep = function isLastStep() {
53
+ return activeStep === totalSteps() - 1;
54
+ };
55
+ var allStepsCompleted = function allStepsCompleted() {
56
+ return completedSteps() === totalSteps();
57
+ };
58
+ var handleNext = function handleNext() {
59
+ var newActiveStep = isLastStep() && !allStepsCompleted() ?
60
+ // It's the last step, but not all steps have been completed,
61
+ // find the first step that has been completed
62
+ steps.findIndex(function (step, i) {
63
+ return !(i in completed);
64
+ }) : activeStep + 1;
65
+ setActiveStep(newActiveStep);
66
+ };
67
+ var handleBack = function handleBack() {
68
+ setActiveStep(function (prevActiveStep) {
69
+ return prevActiveStep - 1;
70
+ });
71
+ };
72
+ var handleStep = function handleStep(step) {
73
+ return function () {
74
+ setActiveStep(step);
75
+ };
76
+ };
77
+ var handleComplete = function handleComplete() {
78
+ alert("done");
79
+ // const newCompleted = completed;
80
+ // newCompleted[activeStep] = true;
81
+ // setCompleted(newCompleted);
82
+ // handleNext();
83
+ };
84
+
85
+ var handleReset = function handleReset() {
86
+ setActiveStep(0);
87
+ setCompleted({});
88
+ };
89
+ return /*#__PURE__*/_react["default"].createElement(_Dialog["default"], {
90
+ open: showDialog,
91
+ onClose: function onClose() {
92
+ if (_onClose != null) {
93
+ _onClose();
94
+ }
95
+ },
96
+ fullWidth: true
97
+ }, /*#__PURE__*/_react["default"].createElement(_DialogTitle["default"], null, "Upload users"), /*#__PURE__*/_react["default"].createElement(_DialogContent["default"], null, /*#__PURE__*/_react["default"].createElement(_DialogContentText["default"], null, "Upload multiple users using a CSV sheet"), /*#__PURE__*/_react["default"].createElement(_system.Box, {
98
+ sx: {
99
+ paddingBottom: 0,
100
+ paddingTop: 2
101
+ }
102
+ }, /*#__PURE__*/_react["default"].createElement(_Stepper["default"], {
103
+ nonLinear: true,
104
+ activeStep: activeStep
105
+ }, steps.map(function (label, index) {
106
+ return /*#__PURE__*/_react["default"].createElement(_Step["default"], {
107
+ key: label,
108
+ completed: completed[index]
109
+ }, /*#__PURE__*/_react["default"].createElement(_StepButton["default"], {
110
+ color: "inherit",
111
+ onClick: handleStep(index)
112
+ }, label));
113
+ })), /*#__PURE__*/_react["default"].createElement("div", null, allStepsCompleted() ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_material.Typography, {
114
+ sx: {
115
+ mt: 2,
116
+ mb: 1
117
+ }
118
+ }, "All steps completed - you're finished"), /*#__PURE__*/_react["default"].createElement(_system.Box, {
119
+ sx: {
120
+ display: 'flex',
121
+ flexDirection: 'row',
122
+ pt: 2
123
+ }
124
+ }, /*#__PURE__*/_react["default"].createElement(_system.Box, {
125
+ sx: {
126
+ flex: '1 1 auto'
127
+ }
128
+ }), /*#__PURE__*/_react["default"].createElement(_material.Button, {
129
+ onClick: handleReset
130
+ }, "Reset"))) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_system.Box, {
131
+ sx: {
132
+ paddingTop: 4,
133
+ paddingBottom: 4
134
+ }
135
+ }, activeStep == 0 && /*#__PURE__*/_react["default"].createElement(_system.Box, {
136
+ sx: {
137
+ fontSize: 14
138
+ }
139
+ }, "Download our CSV template to make sure your CSV is formatted correctly.", /*#__PURE__*/_react["default"].createElement(_material.Button, {
140
+ startIcon: /*#__PURE__*/_react["default"].createElement(_CloudDownloadRounded["default"], null),
141
+ variant: "contained",
142
+ sx: {
143
+ marginTop: 2
144
+ },
145
+ onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
146
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
147
+ while (1) switch (_context.prev = _context.next) {
148
+ case 0:
149
+ _context.next = 2;
150
+ return (0, _authscape.apiService)().DownloadFile("/UserManagement/GetDownloadTemplate?customFields=" + JSON.stringify(customFields), "DownloadFile.csv", function () {});
151
+ case 2:
152
+ case "end":
153
+ return _context.stop();
154
+ }
155
+ }, _callee);
156
+ }))
157
+ }, "Download Template")), activeStep == 1 && /*#__PURE__*/_react["default"].createElement(_system.Box, null, /*#__PURE__*/_react["default"].createElement(_authscape.FileUploader, {
158
+ url: "/UserManagement/UploadUsers",
159
+ onUploadCompleted: function onUploadCompleted(results) {
160
+ if (_onClose != null) {
161
+ _onClose();
162
+ }
163
+ }
164
+ }))), /*#__PURE__*/_react["default"].createElement(_system.Box, {
165
+ sx: {
166
+ display: 'flex',
167
+ flexDirection: 'row',
168
+ pt: 2
169
+ }
170
+ }, /*#__PURE__*/_react["default"].createElement(_material.Button, {
171
+ color: "inherit",
172
+ disabled: activeStep === 0,
173
+ onClick: handleBack,
174
+ sx: {
175
+ mr: 1
176
+ }
177
+ }, "Back"), /*#__PURE__*/_react["default"].createElement(_system.Box, {
178
+ sx: {
179
+ flex: '1 1 auto'
180
+ }
181
+ }), activeStep !== steps.length - 1 && /*#__PURE__*/_react["default"].createElement(_material.Button, {
182
+ onClick: handleNext,
183
+ sx: {
184
+ mr: 1
185
+ }
186
+ }, "Next"))))), /*#__PURE__*/_react["default"].createElement(_system.Box, {
187
+ sx: {
188
+ height: 200
189
+ }
190
+ })), /*#__PURE__*/_react["default"].createElement(_DialogActions["default"], null, /*#__PURE__*/_react["default"].createElement(_material.Button, {
191
+ onClick: function onClick() {
192
+ if (_onClose != null) {
193
+ _onClose();
194
+ }
195
+ }
196
+ }, "Cancel")));
197
+ }
198
+ "use strict";
199
+
3
200
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
201
  Object.defineProperty(exports, "__esModule", {
5
202
  value: true
@@ -42,8 +239,6 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
42
239
  function UserEditor(_ref) {
43
240
  var _ref$userId = _ref.userId,
44
241
  userId = _ref$userId === void 0 ? null : _ref$userId,
45
- _ref$customFields = _ref.customFields,
46
- customFields = _ref$customFields === void 0 ? null : _ref$customFields,
47
242
  _ref$onSaved = _ref.onSaved,
48
243
  onSaved = _ref$onSaved === void 0 ? null : _ref$onSaved,
49
244
  _ref$onPasswordChange = _ref.onPasswordChanged,
@@ -95,10 +290,14 @@ function UserEditor(_ref) {
95
290
  _useState20 = _slicedToArray(_useState19, 2),
96
291
  permissions = _useState20[0],
97
292
  setPermissions = _useState20[1];
98
- var _useState21 = (0, _react.useState)(null),
293
+ var _useState21 = (0, _react.useState)([]),
99
294
  _useState22 = _slicedToArray(_useState21, 2),
100
- user = _useState22[0],
101
- setUser = _useState22[1];
295
+ customFields = _useState22[0],
296
+ setCustomFields = _useState22[1];
297
+ var _useState23 = (0, _react.useState)(null),
298
+ _useState24 = _slicedToArray(_useState23, 2),
299
+ user = _useState24[0],
300
+ setUser = _useState24[1];
102
301
  var ITEM_HEIGHT = 48;
103
302
  var ITEM_PADDING_TOP = 8;
104
303
  var MenuProps = {
@@ -109,18 +308,18 @@ function UserEditor(_ref) {
109
308
  }
110
309
  }
111
310
  };
112
- var _useState23 = (0, _react.useState)(""),
113
- _useState24 = _slicedToArray(_useState23, 2),
114
- newPassword = _useState24[0],
115
- setNewPassword = _useState24[1];
116
311
  var _useState25 = (0, _react.useState)(""),
117
312
  _useState26 = _slicedToArray(_useState25, 2),
118
- confirmPassword = _useState26[0],
119
- setConfirmPassword = _useState26[1];
120
- var _useState27 = (0, _react.useState)(0),
313
+ newPassword = _useState26[0],
314
+ setNewPassword = _useState26[1];
315
+ var _useState27 = (0, _react.useState)(""),
121
316
  _useState28 = _slicedToArray(_useState27, 2),
122
- tabValue = _useState28[0],
123
- setTabValue = _useState28[1];
317
+ confirmPassword = _useState28[0],
318
+ setConfirmPassword = _useState28[1];
319
+ var _useState29 = (0, _react.useState)(0),
320
+ _useState30 = _slicedToArray(_useState29, 2),
321
+ tabValue = _useState30[0],
322
+ setTabValue = _useState30[1];
124
323
  var handleTabChange = function handleTabChange(event, newValue) {
125
324
  setTabValue(newValue);
126
325
  };
@@ -177,6 +376,9 @@ function UserEditor(_ref) {
177
376
  if (response.data.location != null) {
178
377
  setLocation(response.data.location);
179
378
  }
379
+ if (response.data.userCustomFields != null) {
380
+ setCustomFields(response.data.userCustomFields);
381
+ }
180
382
 
181
383
  // assign all selected roles
182
384
  if (response.data.roles != null) {
@@ -243,7 +445,7 @@ function UserEditor(_ref) {
243
445
  item: true,
244
446
  xs: 6
245
447
  }, /*#__PURE__*/_react["default"].createElement(_reactHookForm.Controller, {
246
- name: field.name,
448
+ name: field.customFieldId,
247
449
  control: control,
248
450
  rules: {
249
451
  required: field.isRequired
@@ -256,7 +458,7 @@ function UserEditor(_ref) {
256
458
  defaultValue: result,
257
459
  margin: "normal",
258
460
  fullWidth: true
259
- }, register(field.name, {
461
+ }, register(field.customFieldId, {
260
462
  required: field.isRequired
261
463
  }), renderField));
262
464
  }
@@ -423,8 +625,11 @@ function UserEditor(_ref) {
423
625
  userCustomFields = [];
424
626
  customFields && customFields.forEach(function (customField) {
425
627
  userCustomFields.push({
628
+ customFieldId: customField.customFieldId,
426
629
  name: customField.name,
427
- value: data[customField.name]
630
+ isRequired: customField.isRequired,
631
+ customFieldType: customField.customFieldType,
632
+ value: data[customField.customFieldId]
428
633
  });
429
634
  });
430
635
  _context5.next = 4;
@@ -799,11 +1004,6 @@ var _material = require("@mui/material");
799
1004
  var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
800
1005
  var _UploadRounded = _interopRequireDefault(require("@mui/icons-material/UploadRounded"));
801
1006
  var _CloseRounded = _interopRequireDefault(require("@mui/icons-material/CloseRounded"));
802
- var _Dialog = _interopRequireDefault(require("@mui/material/Dialog"));
803
- var _DialogActions = _interopRequireDefault(require("@mui/material/DialogActions"));
804
- var _DialogContent = _interopRequireDefault(require("@mui/material/DialogContent"));
805
- var _DialogContentText = _interopRequireDefault(require("@mui/material/DialogContentText"));
806
- var _DialogTitle = _interopRequireDefault(require("@mui/material/DialogTitle"));
807
1007
  var _authscape = require("authscape");
808
1008
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
809
1009
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -818,14 +1018,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
818
1018
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
819
1019
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
820
1020
  // import { UserEditor } from './UserEditor'; // remove when done
821
-
1021
+ // import { CSVUsersUpload } from './CSVUsersUpload'; // remove when done
822
1022
  function UserManagement(_ref) {
823
- var _ref$customFields = _ref.customFields,
824
- customFields = _ref$customFields === void 0 ? null : _ref$customFields,
825
- _ref$height = _ref.height,
1023
+ var _ref$height = _ref.height,
826
1024
  height = _ref$height === void 0 ? "50vh" : _ref$height,
827
1025
  _ref$onUploadComplete = _ref.onUploadCompleted,
828
- _onUploadCompleted = _ref$onUploadComplete === void 0 ? null : _ref$onUploadComplete,
1026
+ onUploadCompleted = _ref$onUploadComplete === void 0 ? null : _ref$onUploadComplete,
829
1027
  _ref$onPasswordChange = _ref.onPasswordChanged,
830
1028
  onPasswordChanged = _ref$onPasswordChange === void 0 ? null : _ref$onPasswordChange;
831
1029
  var _useState = (0, _react.useState)(null),
@@ -1010,32 +1208,15 @@ function UserManagement(_ref) {
1010
1208
  }
1011
1209
  }, /*#__PURE__*/_react["default"].createElement(UserEditor, {
1012
1210
  userId: showUserDetails,
1013
- customFields: customFields,
1014
1211
  onPasswordChanged: onPasswordChanged,
1015
1212
  onSaved: function onSaved() {
1016
1213
  setDataGridRefreshKey(dataGridRefreshKey + 1);
1017
1214
  setShowUserDetails(null);
1018
1215
  }
1019
- }))))), /*#__PURE__*/_react["default"].createElement(_Dialog["default"], {
1020
- open: uploadUsersShowDialog,
1216
+ }))))), /*#__PURE__*/_react["default"].createElement(CSVUsersUpload, {
1217
+ showDialog: uploadUsersShowDialog,
1021
1218
  onClose: function onClose() {
1022
1219
  setUploadUsersShowDialog(false);
1023
- },
1024
- fullWidth: true
1025
- }, /*#__PURE__*/_react["default"].createElement(_DialogTitle["default"], null, "Upload users"), /*#__PURE__*/_react["default"].createElement(_DialogContent["default"], null, /*#__PURE__*/_react["default"].createElement(_DialogContentText["default"], null, "Upload multiple users using a CSV sheet"), /*#__PURE__*/_react["default"].createElement(_system.Box, {
1026
- sx: {
1027
- height: 200
1028
- }
1029
- }, /*#__PURE__*/_react["default"].createElement(_authscape.FileUploader, {
1030
- url: "/UserManagement/UploadUsers",
1031
- onUploadCompleted: function onUploadCompleted(results) {
1032
- if (_onUploadCompleted != null) {
1033
- _onUploadCompleted(results);
1034
- }
1035
- }
1036
- }))), /*#__PURE__*/_react["default"].createElement(_DialogActions["default"], null, /*#__PURE__*/_react["default"].createElement(_material.Button, {
1037
- onClick: function onClick() {
1038
- setUploadUsersShowDialog(false);
1039
1220
  }
1040
- }, "Cancel"))));
1221
+ }));
1041
1222
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape-usermanagement",
3
- "version": "1.0.22",
3
+ "version": "1.0.26",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,236 @@
1
+ import React, {useEffect, useState, useRef} from 'react';
2
+ import { Box } from '@mui/system';
3
+ import Dialog from '@mui/material/Dialog';
4
+ import DialogActions from '@mui/material/DialogActions';
5
+ import DialogContent from '@mui/material/DialogContent';
6
+ import DialogContentText from '@mui/material/DialogContentText';
7
+ import DialogTitle from '@mui/material/DialogTitle';
8
+ import { Button, Typography } from '@mui/material';
9
+ import { FileUploader, apiService } from 'authscape';
10
+ import Stepper from '@mui/material/Stepper';
11
+ import Step from '@mui/material/Step';
12
+ import StepButton from '@mui/material/StepButton';
13
+ import CloudDownloadRoundedIcon from '@mui/icons-material/CloudDownloadRounded';
14
+
15
+ export function CSVUsersUpload({customFields, showDialog, onClose}) {
16
+
17
+ const [activeStep, setActiveStep] = React.useState(0);
18
+ const [completed, setCompleted] = React.useState({});
19
+
20
+ const steps = ['Download CSV Template', 'Upload CSV Template'];
21
+
22
+ const totalSteps = () => {
23
+ return steps.length;
24
+ };
25
+
26
+ const completedSteps = () => {
27
+ return Object.keys(completed).length;
28
+ };
29
+
30
+ const isLastStep = () => {
31
+ return activeStep === totalSteps() - 1;
32
+ };
33
+
34
+ const allStepsCompleted = () => {
35
+ return completedSteps() === totalSteps();
36
+ };
37
+
38
+ const handleNext = () => {
39
+ const newActiveStep =
40
+ isLastStep() && !allStepsCompleted()
41
+ ? // It's the last step, but not all steps have been completed,
42
+ // find the first step that has been completed
43
+ steps.findIndex((step, i) => !(i in completed))
44
+ : activeStep + 1;
45
+
46
+ setActiveStep(newActiveStep);
47
+ };
48
+
49
+ const handleBack = () => {
50
+ setActiveStep((prevActiveStep) => prevActiveStep - 1);
51
+ };
52
+
53
+ const handleStep = (step) => () => {
54
+ setActiveStep(step);
55
+ };
56
+
57
+ const handleComplete = () => {
58
+
59
+ alert("done")
60
+ // const newCompleted = completed;
61
+ // newCompleted[activeStep] = true;
62
+ // setCompleted(newCompleted);
63
+ // handleNext();
64
+ };
65
+
66
+ const handleReset = () => {
67
+ setActiveStep(0);
68
+ setCompleted({});
69
+ };
70
+
71
+ return (
72
+ <Dialog
73
+ open={showDialog}
74
+ onClose={() => {
75
+ if (onClose != null)
76
+ {
77
+ onClose();
78
+ }
79
+ }}
80
+ fullWidth={true}>
81
+ <DialogTitle>
82
+ {"Upload users"}
83
+ </DialogTitle>
84
+ <DialogContent>
85
+ <DialogContentText>
86
+ Upload multiple users using a CSV sheet
87
+ </DialogContentText>
88
+
89
+ <Box sx={{paddingBottom:0, paddingTop:2}}>
90
+
91
+ <Stepper nonLinear activeStep={activeStep}>
92
+ {steps.map((label, index) => (
93
+ <Step key={label} completed={completed[index]}>
94
+ <StepButton color="inherit" onClick={handleStep(index)}>
95
+ {label}
96
+ </StepButton>
97
+ </Step>
98
+ ))}
99
+ </Stepper>
100
+ <div>
101
+ {allStepsCompleted() ? (
102
+ <React.Fragment>
103
+ <Typography sx={{ mt: 2, mb: 1 }}>
104
+ All steps completed - you&apos;re finished
105
+ </Typography>
106
+ <Box sx={{ display: 'flex', flexDirection: 'row', pt: 2 }}>
107
+ <Box sx={{ flex: '1 1 auto' }} />
108
+ <Button onClick={handleReset}>Reset</Button>
109
+ </Box>
110
+ </React.Fragment>
111
+ ) : (
112
+ <React.Fragment>
113
+ {/* <Typography sx={{ mt: 2, mb: 1, py: 1 }}>
114
+ Step {activeStep + 1}
115
+ </Typography> */}
116
+
117
+ <Box sx={{paddingTop:4, paddingBottom:4}}>
118
+ {activeStep == 0 &&
119
+ <Box sx={{fontSize:14}}>
120
+ Download our CSV template to make sure your CSV is formatted correctly.
121
+
122
+ <Button startIcon={<CloudDownloadRoundedIcon />} variant="contained" sx={{marginTop:2}} onClick={async () => {
123
+
124
+ await apiService().DownloadFile("/UserManagement/GetDownloadTemplate?customFields=" + JSON.stringify(customFields), "DownloadFile.csv", () => {
125
+
126
+ });
127
+
128
+ // alert("download template")
129
+ }}>Download Template</Button>
130
+ </Box>
131
+ }
132
+
133
+ {/* {activeStep == 1 &&
134
+ <Box>
135
+ Select your company
136
+ </Box>
137
+ } */}
138
+
139
+ {activeStep == 1 &&
140
+ <Box>
141
+ <FileUploader url={"/UserManagement/UploadUsers"} onUploadCompleted={(results) => {
142
+
143
+ if (onClose != null)
144
+ {
145
+ onClose();
146
+ }
147
+
148
+ }} />
149
+ </Box>
150
+ }
151
+
152
+ </Box>
153
+
154
+ <Box sx={{ display: 'flex', flexDirection: 'row', pt: 2 }}>
155
+ <Button
156
+ color="inherit"
157
+ disabled={activeStep === 0}
158
+ onClick={handleBack}
159
+ sx={{ mr: 1 }}>
160
+ Back
161
+ </Button>
162
+ <Box sx={{ flex: '1 1 auto' }} />
163
+
164
+ {/* {activeStep} {steps.length -1} */}
165
+
166
+ {(activeStep !== steps.length - 1) &&
167
+ <Button onClick={handleNext} sx={{ mr: 1 }}>
168
+ Next
169
+ </Button>
170
+ }
171
+
172
+ {/* {(activeStep === steps.length - 1) &&
173
+ <Box>
174
+ <Button onClick={handleComplete}>
175
+ {completedSteps() === totalSteps() - 1
176
+ ? 'Finish'
177
+ : 'Complete Step'}
178
+ </Button>
179
+ </Box>
180
+ } */}
181
+ </Box>
182
+ </React.Fragment>
183
+ )}
184
+ </div>
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+ </Box>
220
+
221
+ <Box sx={{height:200}}>
222
+
223
+ </Box>
224
+
225
+ </DialogContent>
226
+ <DialogActions>
227
+ <Button onClick={() => {
228
+ if (onClose != null)
229
+ {
230
+ onClose();
231
+ }
232
+ }}>Cancel</Button>
233
+ </DialogActions>
234
+ </Dialog>
235
+ )
236
+ }
package/src/UserEditor.js CHANGED
@@ -17,7 +17,7 @@ import { Tab, Tabs } from '@mui/material';
17
17
  import BusinessRoundedIcon from '@mui/icons-material/BusinessRounded';
18
18
  import { apiService } from 'authscape';
19
19
 
20
- export function UserEditor({userId = null, customFields = null, onSaved = null, onPasswordChanged = null}) {
20
+ export function UserEditor({userId = null, onSaved = null, onPasswordChanged = null}) {
21
21
 
22
22
  const {control, register, handleSubmit, formState: { errors }, watch, setValue } = useForm();
23
23
 
@@ -35,6 +35,8 @@ export function UserEditor({userId = null, customFields = null, onSaved = null,
35
35
  const [roles, setRole] = useState([]);
36
36
  const [permissions, setPermissions] = useState([]);
37
37
 
38
+ const [customFields, setCustomFields] = useState([]);
39
+
38
40
  const [user, setUser] = useState(null);
39
41
 
40
42
  const ITEM_HEIGHT = 48;
@@ -100,6 +102,11 @@ export function UserEditor({userId = null, customFields = null, onSaved = null,
100
102
  setLocation(response.data.location);
101
103
  }
102
104
 
105
+ if (response.data.userCustomFields != null)
106
+ {
107
+ setCustomFields(response.data.userCustomFields);
108
+ }
109
+
103
110
  // assign all selected roles
104
111
  if (response.data.roles != null)
105
112
  {
@@ -189,7 +196,7 @@ export function UserEditor({userId = null, customFields = null, onSaved = null,
189
196
 
190
197
  return (
191
198
  <Grid item xs={6}>
192
- <Controller name={field.name}
199
+ <Controller name={field.customFieldId}
193
200
  control={control}
194
201
  rules={{
195
202
  required: field.isRequired,
@@ -201,7 +208,7 @@ export function UserEditor({userId = null, customFields = null, onSaved = null,
201
208
  defaultValue={result}
202
209
  margin="normal"
203
210
  fullWidth
204
- {...register(field.name, { required: field.isRequired })}
211
+ {...register(field.customFieldId, { required: field.isRequired })}
205
212
  {...renderField}
206
213
  />
207
214
  }
@@ -353,8 +360,11 @@ export function UserEditor({userId = null, customFields = null, onSaved = null,
353
360
  customFields && customFields.forEach(customField => {
354
361
 
355
362
  userCustomFields.push({
363
+ customFieldId: customField.customFieldId,
356
364
  name: customField.name,
357
- value: data[customField.name]
365
+ isRequired: customField.isRequired,
366
+ customFieldType: customField.customFieldType,
367
+ value: data[customField.customFieldId]
358
368
  });
359
369
  });
360
370
 
@@ -1,18 +1,14 @@
1
1
  import React, {useEffect, useState, useRef} from 'react';
2
2
  import { Box } from '@mui/system';
3
- import { Avatar, Button, Drawer, Grid, TextField } from '@mui/material';
3
+ import { Avatar, Button, Drawer, Grid, Stack, TextField, Typography } from '@mui/material';
4
4
  import IconButton from '@mui/material/IconButton';
5
5
  import UploadRoundedIcon from '@mui/icons-material/UploadRounded';
6
6
  import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
7
- import Dialog from '@mui/material/Dialog';
8
- import DialogActions from '@mui/material/DialogActions';
9
- import DialogContent from '@mui/material/DialogContent';
10
- import DialogContentText from '@mui/material/DialogContentText';
11
- import DialogTitle from '@mui/material/DialogTitle';
12
- import { EditableDatagrid, FileUploader, AutoSaveTextField } from 'authscape';
7
+ import { EditableDatagrid, FileUploader, AutoSaveTextField, apiService } from 'authscape';
13
8
  // import { UserEditor } from './UserEditor'; // remove when done
9
+ // import { CSVUsersUpload } from './CSVUsersUpload'; // remove when done
14
10
 
15
- export default function UserManagement({customFields = null, height = "50vh", onUploadCompleted = null, onPasswordChanged = null}) {
11
+ export default function UserManagement({height = "50vh", onUploadCompleted = null, onPasswordChanged = null}) {
16
12
 
17
13
  const [showUserDetails, setShowUserDetails] = useState(null);
18
14
 
@@ -73,7 +69,6 @@ export default function UserManagement({customFields = null, height = "50vh", on
73
69
  },
74
70
  ];
75
71
 
76
-
77
72
  useEffect(() => {
78
73
 
79
74
  setDataGridRefreshKey(dataGridRefreshKey + 1);
@@ -156,7 +151,6 @@ export default function UserManagement({customFields = null, height = "50vh", on
156
151
 
157
152
  <UserEditor
158
153
  userId={showUserDetails}
159
- customFields={customFields}
160
154
  onPasswordChanged={onPasswordChanged}
161
155
  onSaved={() => {
162
156
 
@@ -173,38 +167,9 @@ export default function UserManagement({customFields = null, height = "50vh", on
173
167
  </Drawer>
174
168
  </Box>
175
169
 
176
- <Dialog
177
- open={uploadUsersShowDialog}
178
- onClose={() => {
179
- setUploadUsersShowDialog(false);
180
- }}
181
- fullWidth={true}>
182
- <DialogTitle>
183
- {"Upload users"}
184
- </DialogTitle>
185
- <DialogContent>
186
- <DialogContentText>
187
- Upload multiple users using a CSV sheet
188
- </DialogContentText>
189
-
190
- <Box sx={{height:200}}>
191
- <FileUploader url={"/UserManagement/UploadUsers"} onUploadCompleted={(results) => {
192
-
193
- if (onUploadCompleted != null)
194
- {
195
- onUploadCompleted(results);
196
- }
197
-
198
- }} />
199
- </Box>
200
-
201
- </DialogContent>
202
- <DialogActions>
203
- <Button onClick={() => {
204
- setUploadUsersShowDialog(false);
205
- }}>Cancel</Button>
206
- </DialogActions>
207
- </Dialog>
170
+ <CSVUsersUpload showDialog={uploadUsersShowDialog} onClose={() => {
171
+ setUploadUsersShowDialog(false);
172
+ }} />
208
173
 
209
174
  </Box>
210
175
  );