@sprucelabs/spruce-people-utils 2.1.11 → 2.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.
@@ -10,5 +10,6 @@ export default class SpyPersonSelectInput extends PersonSelectInputViewControlle
10
10
  handleClickSuggestion(person: SearchPerson): Promise<void>;
11
11
  loadCurrentPerson(): Promise<void>;
12
12
  clearOrgId(): void;
13
+ getShouldAllowAddAnonymous(): boolean;
13
14
  InvitePersonVc(onDone?: DoneHandler): SpyInviteInviteViewController;
14
15
  }
@@ -26,6 +26,9 @@ class SpyPersonSelectInput extends PersonSelectInput_vc_1.default {
26
26
  clearOrgId() {
27
27
  this.organizationId = undefined;
28
28
  }
29
+ getShouldAllowAddAnonymous() {
30
+ return this.shouldAllowAddAnonymous;
31
+ }
29
32
  InvitePersonVc(onDone) {
30
33
  const vc = super.InvitePersonVc(onDone);
31
34
  return vc;
@@ -10,5 +10,6 @@ export default class SpyPersonSelectInput extends PersonSelectInputViewControlle
10
10
  handleClickSuggestion(person: SearchPerson): Promise<void>;
11
11
  loadCurrentPerson(): Promise<void>;
12
12
  clearOrgId(): void;
13
+ getShouldAllowAddAnonymous(): boolean;
13
14
  InvitePersonVc(onDone?: DoneHandler): SpyInviteInviteViewController;
14
15
  }
@@ -35,6 +35,9 @@ export default class SpyPersonSelectInput extends PersonSelectInputViewControlle
35
35
  clearOrgId() {
36
36
  this.organizationId = undefined;
37
37
  }
38
+ getShouldAllowAddAnonymous() {
39
+ return this.shouldAllowAddAnonymous;
40
+ }
38
41
  InvitePersonVc(onDone) {
39
42
  const vc = super.InvitePersonVc(onDone);
40
43
  return vc;
@@ -8,6 +8,7 @@ export default class PersonSelectInputViewController extends AbstractViewControl
8
8
  protected locationId?: string;
9
9
  protected shouldIgnoreNextChange: boolean;
10
10
  protected lastLoadedPersonId?: string;
11
+ protected shouldAllowAddAnonymous: boolean;
11
12
  private loadingPromise?;
12
13
  constructor(options: ViewControllerOptions & PersonSelectInputOptions);
13
14
  private handleFocusInput;
@@ -35,5 +36,6 @@ type AutocompleteInput = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Auto
35
36
  export interface PersonSelectInputOptions extends FormInputOptions {
36
37
  organizationId?: string;
37
38
  locationId?: string;
39
+ shouldAllowAddAnonymous?: boolean;
38
40
  }
39
41
  export {};
@@ -8,15 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { AbstractViewController, } from '@sprucelabs/heartwood-view-controllers';
11
- import { assertOptions } from '@sprucelabs/schema';
12
11
  import InvitePersonCardViewController from '../inviting/InvitePersonCard.vc.js';
13
12
  import searchPeopleToSuggestions, { renderLabel, } from './searchPeopleToSuggestions.js';
14
13
  export default class PersonSelectInputViewController extends AbstractViewController {
15
14
  constructor(options) {
16
15
  super(options);
17
16
  this.shouldIgnoreNextChange = false;
18
- this.organizationId = options.organizationId;
19
- this.locationId = options.locationId;
17
+ const { organizationId, locationId, shouldAllowAddAnonymous } = options;
18
+ this.organizationId = organizationId;
19
+ this.locationId = locationId;
20
+ this.shouldAllowAddAnonymous = shouldAllowAddAnonymous !== null && shouldAllowAddAnonymous !== void 0 ? shouldAllowAddAnonymous : true;
20
21
  this.autoCompleteVc = this.Controller('autocompleteInput', Object.assign(Object.assign({}, options), { onChangeRenderedValue: this.handleOnChangeRenderedValue.bind(this), renderedValue: '', onFocus: this.handleFocusInput.bind(this) }));
21
22
  this.mixinControllers({
22
23
  'people.invite-person-card': InvitePersonCardViewController,
@@ -24,7 +25,8 @@ export default class PersonSelectInputViewController extends AbstractViewControl
24
25
  }
25
26
  handleFocusInput() {
26
27
  return __awaiter(this, void 0, void 0, function* () {
27
- if (this.autoCompleteVc.getRenderedValue() === '') {
28
+ if (this.autoCompleteVc.getRenderedValue() === '' &&
29
+ this.shouldAllowAddAnonymous) {
28
30
  this.autoCompleteVc.showSuggestions([this.renderAnonSuggestion()]);
29
31
  }
30
32
  });
@@ -46,19 +48,21 @@ export default class PersonSelectInputViewController extends AbstractViewControl
46
48
  }
47
49
  populateSuggestions(value) {
48
50
  return __awaiter(this, void 0, void 0, function* () {
49
- assertOptions({ organizationId: this.organizationId }, ['organizationId'], `You gotta set an organizationId to your person select input for it to function. Try using 'this.vc.setOrganizationId(...)'!`);
50
51
  try {
51
52
  const people = yield this.search(value);
52
53
  const suggestions = searchPeopleToSuggestions(people, (person) => __awaiter(this, void 0, void 0, function* () { return this.handleClickSuggestion(person); }));
53
- this.autoCompleteVc.showSuggestions([
54
+ const allSuggestions = [
54
55
  ...suggestions,
55
56
  {
56
57
  id: 'invite',
57
58
  label: 'Invite person',
58
59
  onClick: this.handleClickInvitePerson.bind(this),
59
60
  },
60
- this.renderAnonSuggestion(),
61
- ]);
61
+ ];
62
+ if (this.shouldAllowAddAnonymous) {
63
+ allSuggestions.push(this.renderAnonSuggestion());
64
+ }
65
+ this.autoCompleteVc.showSuggestions(allSuggestions);
62
66
  }
63
67
  catch (err) {
64
68
  console.error(err);
@@ -8,6 +8,7 @@ export default class PersonSelectInputViewController extends AbstractViewControl
8
8
  protected locationId?: string;
9
9
  protected shouldIgnoreNextChange: boolean;
10
10
  protected lastLoadedPersonId?: string;
11
+ protected shouldAllowAddAnonymous: boolean;
11
12
  private loadingPromise?;
12
13
  constructor(options: ViewControllerOptions & PersonSelectInputOptions);
13
14
  private handleFocusInput;
@@ -35,5 +36,6 @@ type AutocompleteInput = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Auto
35
36
  export interface PersonSelectInputOptions extends FormInputOptions {
36
37
  organizationId?: string;
37
38
  locationId?: string;
39
+ shouldAllowAddAnonymous?: boolean;
38
40
  }
39
41
  export {};
@@ -27,22 +27,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
30
- const schema_1 = require("@sprucelabs/schema");
31
30
  const InvitePersonCard_vc_1 = __importDefault(require("../inviting/InvitePersonCard.vc"));
32
31
  const searchPeopleToSuggestions_1 = __importStar(require("./searchPeopleToSuggestions"));
33
32
  class PersonSelectInputViewController extends heartwood_view_controllers_1.AbstractViewController {
34
33
  constructor(options) {
35
34
  super(options);
36
35
  this.shouldIgnoreNextChange = false;
37
- this.organizationId = options.organizationId;
38
- this.locationId = options.locationId;
36
+ const { organizationId, locationId, shouldAllowAddAnonymous } = options;
37
+ this.organizationId = organizationId;
38
+ this.locationId = locationId;
39
+ this.shouldAllowAddAnonymous = shouldAllowAddAnonymous !== null && shouldAllowAddAnonymous !== void 0 ? shouldAllowAddAnonymous : true;
39
40
  this.autoCompleteVc = this.Controller('autocompleteInput', Object.assign(Object.assign({}, options), { onChangeRenderedValue: this.handleOnChangeRenderedValue.bind(this), renderedValue: '', onFocus: this.handleFocusInput.bind(this) }));
40
41
  this.mixinControllers({
41
42
  'people.invite-person-card': InvitePersonCard_vc_1.default,
42
43
  });
43
44
  }
44
45
  async handleFocusInput() {
45
- if (this.autoCompleteVc.getRenderedValue() === '') {
46
+ if (this.autoCompleteVc.getRenderedValue() === '' &&
47
+ this.shouldAllowAddAnonymous) {
46
48
  this.autoCompleteVc.showSuggestions([this.renderAnonSuggestion()]);
47
49
  }
48
50
  }
@@ -60,19 +62,21 @@ class PersonSelectInputViewController extends heartwood_view_controllers_1.Abstr
60
62
  this.shouldIgnoreNextChange = false;
61
63
  }
62
64
  async populateSuggestions(value) {
63
- (0, schema_1.assertOptions)({ organizationId: this.organizationId }, ['organizationId'], `You gotta set an organizationId to your person select input for it to function. Try using 'this.vc.setOrganizationId(...)'!`);
64
65
  try {
65
66
  const people = await this.search(value);
66
67
  const suggestions = (0, searchPeopleToSuggestions_1.default)(people, async (person) => this.handleClickSuggestion(person));
67
- this.autoCompleteVc.showSuggestions([
68
+ const allSuggestions = [
68
69
  ...suggestions,
69
70
  {
70
71
  id: 'invite',
71
72
  label: 'Invite person',
72
73
  onClick: this.handleClickInvitePerson.bind(this),
73
74
  },
74
- this.renderAnonSuggestion(),
75
- ]);
75
+ ];
76
+ if (this.shouldAllowAddAnonymous) {
77
+ allSuggestions.push(this.renderAnonSuggestion());
78
+ }
79
+ this.autoCompleteVc.showSuggestions(allSuggestions);
76
80
  }
77
81
  catch (err) {
78
82
  console.error(err);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-people-utils",
3
3
  "description": "People Utilities",
4
- "version": "2.1.11",
4
+ "version": "2.3.0",
5
5
  "skill": {
6
6
  "namespace": "invite"
7
7
  },