@idsoftsource/initial-process 3.3.1 → 3.3.2

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.
@@ -3440,15 +3440,68 @@ class PreviewComponent {
3440
3440
  professionTypeServerIds = {};
3441
3441
  professionSavedSnapshots = {};
3442
3442
  professionSelections = {};
3443
+ normalizeProfessionTypeId(id) {
3444
+ if (id == null)
3445
+ return null;
3446
+ const normalized = String(id).trim();
3447
+ return normalized || null;
3448
+ }
3449
+ resolveProfessionTypeIdFromSavedItem(item) {
3450
+ const fromProfessionId = this.normalizeProfessionTypeId(item?.professionId);
3451
+ if (fromProfessionId && this.professionTypes.some((p) => this.normalizeProfessionTypeId(p.id) === fromProfessionId)) {
3452
+ return fromProfessionId;
3453
+ }
3454
+ const name = (item?.professionName || '').trim().toLowerCase();
3455
+ if (!name)
3456
+ return fromProfessionId;
3457
+ const match = this.professionTypes.find((p) => (p.professionName || '').trim().toLowerCase() === name);
3458
+ return this.normalizeProfessionTypeId(match?.id) ?? fromProfessionId;
3459
+ }
3460
+ isProfessionTypeSaved(id) {
3461
+ const typeId = this.normalizeProfessionTypeId(id);
3462
+ return !!typeId && this.savedProfessionTypeIds.has(typeId);
3463
+ }
3464
+ markProfessionSelectionSaved(id, serverRecordId) {
3465
+ const typeId = this.normalizeProfessionTypeId(id);
3466
+ if (!typeId)
3467
+ return;
3468
+ this.savedProfessionTypeIds.add(typeId);
3469
+ const sel = this.professionSelections[id] ?? this.professionSelections[typeId];
3470
+ if (sel) {
3471
+ this.professionSavedSnapshots[typeId] = {
3472
+ starRating: sel.starRating ?? 0,
3473
+ year: sel.year ?? null,
3474
+ profileVisibility: !!sel.profileVisibility,
3475
+ notes: sel.notes ?? '',
3476
+ };
3477
+ }
3478
+ if (serverRecordId) {
3479
+ this.professionTypeServerIds[typeId] = serverRecordId;
3480
+ }
3481
+ }
3482
+ markProfessionsCreated(newIds, res) {
3483
+ const createdRecords = Array.isArray(res)
3484
+ ? res
3485
+ : (Array.isArray(res?.data) ? res.data : (Array.isArray(res?.value) ? res.value : null));
3486
+ newIds.forEach((id, index) => {
3487
+ if (this.isManualProfessionType(id))
3488
+ return;
3489
+ const serverRecordId = this.getEntityId(createdRecords?.[index]) ?? (index === 0 ? this.getCreatedId(res) : null);
3490
+ this.markProfessionSelectionSaved(id, serverRecordId);
3491
+ });
3492
+ }
3443
3493
  applySavedProfessionsToTable() {
3444
3494
  this.professionTypeServerIds = {};
3445
3495
  this.professionSavedSnapshots = {};
3496
+ const savedTypeIds = new Set();
3446
3497
  (this.userProfessionOptions ?? []).forEach((item) => {
3447
- const typeId = item?.professionId;
3498
+ const typeId = this.resolveProfessionTypeIdFromSavedItem(item);
3448
3499
  if (!typeId)
3449
3500
  return;
3450
- this.savedProfessionTypeIds.add(typeId);
3451
- this.professionTypeServerIds[typeId] = item.id;
3501
+ savedTypeIds.add(typeId);
3502
+ const serverId = this.getEntityId(item);
3503
+ if (serverId)
3504
+ this.professionTypeServerIds[typeId] = serverId;
3452
3505
  const snapshot = {
3453
3506
  starRating: item.starRating ?? 0,
3454
3507
  year: item.year ?? null,
@@ -3458,10 +3511,14 @@ class PreviewComponent {
3458
3511
  this.professionSavedSnapshots[typeId] = snapshot;
3459
3512
  this.professionSelections[typeId] = { selected: true, ...snapshot };
3460
3513
  });
3514
+ this.savedProfessionTypeIds = savedTypeIds;
3461
3515
  }
3462
3516
  hasProfessionRowChanged(id) {
3463
- const snap = this.professionSavedSnapshots[id];
3464
- const sel = this.professionSelections[id];
3517
+ const typeId = this.normalizeProfessionTypeId(id);
3518
+ if (!typeId)
3519
+ return false;
3520
+ const snap = this.professionSavedSnapshots[typeId];
3521
+ const sel = this.professionSelections[id] ?? this.professionSelections[typeId];
3465
3522
  if (!snap || !sel)
3466
3523
  return false;
3467
3524
  return snap.starRating !== (sel.starRating ?? 0)
@@ -3507,8 +3564,8 @@ class PreviewComponent {
3507
3564
  }
3508
3565
  get professionSubmitLabel() {
3509
3566
  const selectedIds = Object.keys(this.professionSelections).filter(id => this.professionSelections[id].selected);
3510
- const hasNew = selectedIds.some(id => !this.savedProfessionTypeIds.has(id) && this.isManualRowReady(id));
3511
- const hasChanged = selectedIds.some(id => this.savedProfessionTypeIds.has(id) && this.hasProfessionRowChanged(id));
3567
+ const hasNew = selectedIds.some(id => !this.isProfessionTypeSaved(id) && this.isManualRowReady(id));
3568
+ const hasChanged = selectedIds.some(id => this.isProfessionTypeSaved(id) && this.hasProfessionRowChanged(id));
3512
3569
  if (hasNew && hasChanged)
3513
3570
  return 'Save Changes';
3514
3571
  if (hasChanged)
@@ -3516,14 +3573,14 @@ class PreviewComponent {
3516
3573
  return 'Save Profession';
3517
3574
  }
3518
3575
  isProfessionSaved(id) {
3519
- return this.savedProfessionTypeIds.has(id);
3576
+ return this.isProfessionTypeSaved(id);
3520
3577
  }
3521
3578
  get selectedProfessionCount() {
3522
3579
  return Object.keys(this.professionSelections).filter(id => {
3523
3580
  const sel = this.professionSelections[id];
3524
3581
  if (!sel.selected)
3525
3582
  return false;
3526
- if (!this.savedProfessionTypeIds.has(id))
3583
+ if (!this.isProfessionTypeSaved(id))
3527
3584
  return this.isManualRowReady(id);
3528
3585
  return this.hasProfessionRowChanged(id);
3529
3586
  }).length;
@@ -3584,7 +3641,7 @@ class PreviewComponent {
3584
3641
  buildNewProfessionCreatePayload(id) {
3585
3642
  const profType = this.professionTypes.find((p) => p.id === id) || {};
3586
3643
  const sel = this.professionSelections[id];
3587
- return {
3644
+ const payload = {
3588
3645
  forUser: ForUser.ForProducer,
3589
3646
  professionName: profType.professionName,
3590
3647
  notes: sel.notes ?? '',
@@ -3595,11 +3652,15 @@ class PreviewComponent {
3595
3652
  professionGroup: profType.professionGroup ?? '',
3596
3653
  residentialCommercial: profType.residentialCommercial ?? '',
3597
3654
  };
3655
+ if (!profType.isManual) {
3656
+ payload.professionId = id;
3657
+ }
3658
+ return payload;
3598
3659
  }
3599
3660
  async submitProfessions() {
3600
3661
  const allSelectedIds = Object.keys(this.professionSelections).filter(id => this.professionSelections[id].selected);
3601
- const newIds = allSelectedIds.filter(id => !this.savedProfessionTypeIds.has(id) && this.isManualRowReady(id));
3602
- const changedSavedIds = allSelectedIds.filter(id => this.savedProfessionTypeIds.has(id) && this.hasProfessionRowChanged(id));
3662
+ const newIds = allSelectedIds.filter(id => !this.isProfessionTypeSaved(id) && this.isManualRowReady(id));
3663
+ const changedSavedIds = allSelectedIds.filter(id => this.isProfessionTypeSaved(id) && this.hasProfessionRowChanged(id));
3603
3664
  if ((!newIds.length && !changedSavedIds.length) || this.isSavingProfessionsTable)
3604
3665
  return;
3605
3666
  this.isSavingProfessionsTable = true;
@@ -3611,9 +3672,17 @@ class PreviewComponent {
3611
3672
  console.error('Unable to create user profession(s)', res.failures);
3612
3673
  return;
3613
3674
  }
3675
+ this.markProfessionsCreated(newIds, res);
3676
+ const manualIds = newIds.filter(id => this.isManualProfessionType(id));
3677
+ if (manualIds.length) {
3678
+ const manualIdSet = new Set(manualIds);
3679
+ this.professionTypes = this.professionTypes.filter((p) => !manualIdSet.has(p.id));
3680
+ manualIds.forEach(id => delete this.professionSelections[id]);
3681
+ }
3614
3682
  }
3615
3683
  for (const id of changedSavedIds) {
3616
- const payload = { ...this.buildProfessionPayload(id), id: this.professionTypeServerIds[id] };
3684
+ const typeId = this.normalizeProfessionTypeId(id);
3685
+ const payload = { ...this.buildProfessionPayload(id), id: typeId ? this.professionTypeServerIds[typeId] : undefined };
3617
3686
  const res = await firstValueFrom(this.userProfessionService.updateUserProfession(payload));
3618
3687
  if (res?.failed) {
3619
3688
  console.error('Unable to update user profession', res.failures);