From bf08e57ce75be1c70f5972f6a0168df4c258ca60 Mon Sep 17 00:00:00 2001 From: Jose Olarte III Date: Thu, 7 Aug 2025 18:29:58 +0800 Subject: [PATCH] Fix: re-organize entity type conditional logic in gifting flow - Add conditional checks for person vs project entity types when setting DID fields - Simplify project ID assignment logic by removing redundant entity type checks - Preserve existing recipient context when selecting givers in ContactGiftingView, especially when dealing with "Unnamed" entity --- src/components/EntitySelectionStep.vue | 5 ++-- src/components/GiftDetailsStep.vue | 13 +++++---- src/components/GiftedDialog.vue | 37 +++++++++++++++----------- src/views/ContactGiftingView.vue | 28 +++++++++++++------ 4 files changed, 51 insertions(+), 32 deletions(-) diff --git a/src/components/EntitySelectionStep.vue b/src/components/EntitySelectionStep.vue index ee144c75..56426462 100644 --- a/src/components/EntitySelectionStep.vue +++ b/src/components/EntitySelectionStep.vue @@ -261,12 +261,13 @@ export default class EntitySelectionStep extends Vue { giverProjectName: this.giver?.name || "", giverProjectImage: this.giver?.image || "", giverProjectHandleId: this.giver?.handleId || "", - giverDid: this.giver?.did || "", + giverDid: this.giverEntityType === "person" ? this.giver?.did || "" : "", recipientProjectId: this.toProjectId || "", recipientProjectName: this.receiver?.name || "", recipientProjectImage: this.receiver?.image || "", recipientProjectHandleId: this.receiver?.handleId || "", - recipientDid: this.receiver?.did || "", + recipientDid: + this.recipientEntityType === "person" ? this.receiver?.did || "" : "", }; } diff --git a/src/components/GiftDetailsStep.vue b/src/components/GiftDetailsStep.vue index 1841b4bb..f31ed095 100644 --- a/src/components/GiftDetailsStep.vue +++ b/src/components/GiftDetailsStep.vue @@ -315,16 +315,15 @@ export default class GiftDetailsStep extends Vue { giverName: this.giver?.name, offerId: this.offerId, fulfillsProjectId: - this.giverEntityType === "person" && - this.recipientEntityType === "project" - ? this.toProjectId - : undefined, + this.recipientEntityType === "project" ? this.toProjectId : undefined, providerProjectId: - this.giverEntityType === "project" && - this.recipientEntityType === "person" + this.giverEntityType === "project" ? this.giver?.handleId : this.fromProjectId, - recipientDid: this.receiver?.did, + recipientDid: + this.recipientEntityType === "person" + ? this.receiver?.did + : undefined, recipientName: this.receiver?.name, unitCode: this.localUnitCode, }, diff --git a/src/components/GiftedDialog.vue b/src/components/GiftedDialog.vue index df7e8523..7fcc1747 100644 --- a/src/components/GiftedDialog.vue +++ b/src/components/GiftedDialog.vue @@ -458,10 +458,13 @@ export default class GiftedDialog extends Vue { name: contact.name || contact.did, }; } else { - this.giver = { - did: "", - name: "Unnamed", - }; + // Only set to "Unnamed" if no giver is currently set + if (!this.giver || !this.giver.did) { + this.giver = { + did: "", + name: "Unnamed", + }; + } } this.firstStep = false; } @@ -471,6 +474,10 @@ export default class GiftedDialog extends Vue { this.firstStep = true; } + moveToStep2() { + this.firstStep = false; + } + async loadProjects() { try { const response = await fetch(this.apiServer + "/api/v2/report/plans", { @@ -513,10 +520,13 @@ export default class GiftedDialog extends Vue { name: contact.name || contact.did, }; } else { - this.receiver = { - did: "", - name: "Unnamed", - }; + // Only set to "Unnamed" if no receiver is currently set + if (!this.receiver || !this.receiver.did) { + this.receiver = { + did: "", + name: "Unnamed", + }; + } } this.firstStep = false; } @@ -540,16 +550,13 @@ export default class GiftedDialog extends Vue { giverName: this.giver?.name, offerId: this.offerId, fulfillsProjectId: - this.giverEntityType === "person" && - this.recipientEntityType === "project" - ? this.toProjectId - : undefined, + this.recipientEntityType === "project" ? this.toProjectId : undefined, providerProjectId: - this.giverEntityType === "project" && - this.recipientEntityType === "person" + this.giverEntityType === "project" ? this.giver?.handleId : this.fromProjectId, - recipientDid: this.receiver?.did, + recipientDid: + this.recipientEntityType === "person" ? this.receiver?.did : undefined, recipientName: this.receiver?.name, unitCode: this.unitCode, }; diff --git a/src/views/ContactGiftingView.vue b/src/views/ContactGiftingView.vue index 75e8eea2..91d10c9c 100644 --- a/src/views/ContactGiftingView.vue +++ b/src/views/ContactGiftingView.vue @@ -195,7 +195,7 @@ export default class ContactGiftingView extends Vue { let giver: GiverReceiverInputInfo | undefined; if (this.stepType === "giver") { - // We're selecting a giver, so recipient is either a project or the current user + // We're selecting a giver, so preserve the existing recipient from context if (this.recipientEntityType === "project") { recipient = { did: this.recipientProjectHandleId, @@ -204,7 +204,20 @@ export default class ContactGiftingView extends Vue { handleId: this.recipientProjectHandleId, }; } else { - recipient = { did: this.activeDid, name: "You" }; + // Preserve the existing recipient from context + if (this.recipientDid === this.activeDid) { + // Recipient was "You" + recipient = { did: this.activeDid, name: "You" }; + } else if (this.recipientDid) { + // Recipient was a regular contact + recipient = { + did: this.recipientDid, + name: this.recipientProjectName || "Someone", + }; + } else { + // Fallback to "You" if no recipient was previously selected + recipient = { did: this.activeDid, name: "You" }; + } } giver = undefined; // Will be set to "Unnamed" in GiftedDialog } else { @@ -239,12 +252,8 @@ export default class ContactGiftingView extends Vue { this.unitCode, ); - // Immediately select "Unnamed" and move to Step 2 based on stepType - if (this.stepType === "giver") { - (this.$refs.giftedDialog as GiftedDialog).selectGiver(); - } else { - (this.$refs.giftedDialog as GiftedDialog).selectRecipient(); - } + // Move to Step 2 - entities are already set by the open() call + (this.$refs.giftedDialog as GiftedDialog).moveToStep2(); } else { // Regular case: contact is a GiverReceiverInputInfo let giver: GiverReceiverInputInfo; @@ -317,6 +326,9 @@ export default class ContactGiftingView extends Vue { this.amountInput, this.unitCode, ); + + // Move to Step 2 - entities are already set by the open() call + (this.$refs.giftedDialog as GiftedDialog).moveToStep2(); } } }