@sprucelabs/spruce-people-utils 2.2.0 → 2.3.1

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,7 @@ 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;
15
+ clearOrganizationId(): void;
14
16
  }
@@ -26,9 +26,15 @@ 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;
32
35
  }
36
+ clearOrganizationId() {
37
+ this.organizationId = undefined;
38
+ }
33
39
  }
34
40
  exports.default = SpyPersonSelectInput;
@@ -10,5 +10,7 @@ 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;
15
+ clearOrganizationId(): void;
14
16
  }
@@ -35,8 +35,14 @@ 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;
41
44
  }
45
+ clearOrganizationId() {
46
+ this.organizationId = undefined;
47
+ }
42
48
  }
@@ -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 {};
@@ -14,8 +14,10 @@ export default class PersonSelectInputViewController extends AbstractViewControl
14
14
  constructor(options) {
15
15
  super(options);
16
16
  this.shouldIgnoreNextChange = false;
17
- this.organizationId = options.organizationId;
18
- 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;
19
21
  this.autoCompleteVc = this.Controller('autocompleteInput', Object.assign(Object.assign({}, options), { onChangeRenderedValue: this.handleOnChangeRenderedValue.bind(this), renderedValue: '', onFocus: this.handleFocusInput.bind(this) }));
20
22
  this.mixinControllers({
21
23
  'people.invite-person-card': InvitePersonCardViewController,
@@ -23,7 +25,8 @@ export default class PersonSelectInputViewController extends AbstractViewControl
23
25
  }
24
26
  handleFocusInput() {
25
27
  return __awaiter(this, void 0, void 0, function* () {
26
- if (this.autoCompleteVc.getRenderedValue() === '') {
28
+ if (this.autoCompleteVc.getRenderedValue() === '' &&
29
+ this.shouldAllowAddAnonymous) {
27
30
  this.autoCompleteVc.showSuggestions([this.renderAnonSuggestion()]);
28
31
  }
29
32
  });
@@ -48,15 +51,18 @@ export default class PersonSelectInputViewController extends AbstractViewControl
48
51
  try {
49
52
  const people = yield this.search(value);
50
53
  const suggestions = searchPeopleToSuggestions(people, (person) => __awaiter(this, void 0, void 0, function* () { return this.handleClickSuggestion(person); }));
51
- this.autoCompleteVc.showSuggestions([
52
- ...suggestions,
53
- {
54
+ const allSuggestions = [...suggestions];
55
+ if (this.organizationId) {
56
+ allSuggestions.push({
54
57
  id: 'invite',
55
58
  label: 'Invite person',
56
59
  onClick: this.handleClickInvitePerson.bind(this),
57
- },
58
- this.renderAnonSuggestion(),
59
- ]);
60
+ });
61
+ }
62
+ if (this.shouldAllowAddAnonymous) {
63
+ allSuggestions.push(this.renderAnonSuggestion());
64
+ }
65
+ this.autoCompleteVc.showSuggestions(allSuggestions);
60
66
  }
61
67
  catch (err) {
62
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 {};
@@ -33,15 +33,18 @@ class PersonSelectInputViewController extends heartwood_view_controllers_1.Abstr
33
33
  constructor(options) {
34
34
  super(options);
35
35
  this.shouldIgnoreNextChange = false;
36
- this.organizationId = options.organizationId;
37
- 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;
38
40
  this.autoCompleteVc = this.Controller('autocompleteInput', Object.assign(Object.assign({}, options), { onChangeRenderedValue: this.handleOnChangeRenderedValue.bind(this), renderedValue: '', onFocus: this.handleFocusInput.bind(this) }));
39
41
  this.mixinControllers({
40
42
  'people.invite-person-card': InvitePersonCard_vc_1.default,
41
43
  });
42
44
  }
43
45
  async handleFocusInput() {
44
- if (this.autoCompleteVc.getRenderedValue() === '') {
46
+ if (this.autoCompleteVc.getRenderedValue() === '' &&
47
+ this.shouldAllowAddAnonymous) {
45
48
  this.autoCompleteVc.showSuggestions([this.renderAnonSuggestion()]);
46
49
  }
47
50
  }
@@ -62,15 +65,18 @@ class PersonSelectInputViewController extends heartwood_view_controllers_1.Abstr
62
65
  try {
63
66
  const people = await this.search(value);
64
67
  const suggestions = (0, searchPeopleToSuggestions_1.default)(people, async (person) => this.handleClickSuggestion(person));
65
- this.autoCompleteVc.showSuggestions([
66
- ...suggestions,
67
- {
68
+ const allSuggestions = [...suggestions];
69
+ if (this.organizationId) {
70
+ allSuggestions.push({
68
71
  id: 'invite',
69
72
  label: 'Invite person',
70
73
  onClick: this.handleClickInvitePerson.bind(this),
71
- },
72
- this.renderAnonSuggestion(),
73
- ]);
74
+ });
75
+ }
76
+ if (this.shouldAllowAddAnonymous) {
77
+ allSuggestions.push(this.renderAnonSuggestion());
78
+ }
79
+ this.autoCompleteVc.showSuggestions(allSuggestions);
74
80
  }
75
81
  catch (err) {
76
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.2.0",
4
+ "version": "2.3.1",
5
5
  "skill": {
6
6
  "namespace": "invite"
7
7
  },