forked from jsnbuchanan/crowd-funder-for-time-pwa
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
This commit is contained in:
@@ -261,12 +261,13 @@ export default class EntitySelectionStep extends Vue {
|
|||||||
giverProjectName: this.giver?.name || "",
|
giverProjectName: this.giver?.name || "",
|
||||||
giverProjectImage: this.giver?.image || "",
|
giverProjectImage: this.giver?.image || "",
|
||||||
giverProjectHandleId: this.giver?.handleId || "",
|
giverProjectHandleId: this.giver?.handleId || "",
|
||||||
giverDid: this.giver?.did || "",
|
giverDid: this.giverEntityType === "person" ? this.giver?.did || "" : "",
|
||||||
recipientProjectId: this.toProjectId || "",
|
recipientProjectId: this.toProjectId || "",
|
||||||
recipientProjectName: this.receiver?.name || "",
|
recipientProjectName: this.receiver?.name || "",
|
||||||
recipientProjectImage: this.receiver?.image || "",
|
recipientProjectImage: this.receiver?.image || "",
|
||||||
recipientProjectHandleId: this.receiver?.handleId || "",
|
recipientProjectHandleId: this.receiver?.handleId || "",
|
||||||
recipientDid: this.receiver?.did || "",
|
recipientDid:
|
||||||
|
this.recipientEntityType === "person" ? this.receiver?.did || "" : "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -315,16 +315,15 @@ export default class GiftDetailsStep extends Vue {
|
|||||||
giverName: this.giver?.name,
|
giverName: this.giver?.name,
|
||||||
offerId: this.offerId,
|
offerId: this.offerId,
|
||||||
fulfillsProjectId:
|
fulfillsProjectId:
|
||||||
this.giverEntityType === "person" &&
|
this.recipientEntityType === "project" ? this.toProjectId : undefined,
|
||||||
this.recipientEntityType === "project"
|
|
||||||
? this.toProjectId
|
|
||||||
: undefined,
|
|
||||||
providerProjectId:
|
providerProjectId:
|
||||||
this.giverEntityType === "project" &&
|
this.giverEntityType === "project"
|
||||||
this.recipientEntityType === "person"
|
|
||||||
? this.giver?.handleId
|
? this.giver?.handleId
|
||||||
: this.fromProjectId,
|
: this.fromProjectId,
|
||||||
recipientDid: this.receiver?.did,
|
recipientDid:
|
||||||
|
this.recipientEntityType === "person"
|
||||||
|
? this.receiver?.did
|
||||||
|
: undefined,
|
||||||
recipientName: this.receiver?.name,
|
recipientName: this.receiver?.name,
|
||||||
unitCode: this.localUnitCode,
|
unitCode: this.localUnitCode,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -458,11 +458,14 @@ export default class GiftedDialog extends Vue {
|
|||||||
name: contact.name || contact.did,
|
name: contact.name || contact.did,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
// Only set to "Unnamed" if no giver is currently set
|
||||||
|
if (!this.giver || !this.giver.did) {
|
||||||
this.giver = {
|
this.giver = {
|
||||||
did: "",
|
did: "",
|
||||||
name: "Unnamed",
|
name: "Unnamed",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.firstStep = false;
|
this.firstStep = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,6 +474,10 @@ export default class GiftedDialog extends Vue {
|
|||||||
this.firstStep = true;
|
this.firstStep = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moveToStep2() {
|
||||||
|
this.firstStep = false;
|
||||||
|
}
|
||||||
|
|
||||||
async loadProjects() {
|
async loadProjects() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(this.apiServer + "/api/v2/report/plans", {
|
const response = await fetch(this.apiServer + "/api/v2/report/plans", {
|
||||||
@@ -513,11 +520,14 @@ export default class GiftedDialog extends Vue {
|
|||||||
name: contact.name || contact.did,
|
name: contact.name || contact.did,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
// Only set to "Unnamed" if no receiver is currently set
|
||||||
|
if (!this.receiver || !this.receiver.did) {
|
||||||
this.receiver = {
|
this.receiver = {
|
||||||
did: "",
|
did: "",
|
||||||
name: "Unnamed",
|
name: "Unnamed",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.firstStep = false;
|
this.firstStep = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,16 +550,13 @@ export default class GiftedDialog extends Vue {
|
|||||||
giverName: this.giver?.name,
|
giverName: this.giver?.name,
|
||||||
offerId: this.offerId,
|
offerId: this.offerId,
|
||||||
fulfillsProjectId:
|
fulfillsProjectId:
|
||||||
this.giverEntityType === "person" &&
|
this.recipientEntityType === "project" ? this.toProjectId : undefined,
|
||||||
this.recipientEntityType === "project"
|
|
||||||
? this.toProjectId
|
|
||||||
: undefined,
|
|
||||||
providerProjectId:
|
providerProjectId:
|
||||||
this.giverEntityType === "project" &&
|
this.giverEntityType === "project"
|
||||||
this.recipientEntityType === "person"
|
|
||||||
? this.giver?.handleId
|
? this.giver?.handleId
|
||||||
: this.fromProjectId,
|
: this.fromProjectId,
|
||||||
recipientDid: this.receiver?.did,
|
recipientDid:
|
||||||
|
this.recipientEntityType === "person" ? this.receiver?.did : undefined,
|
||||||
recipientName: this.receiver?.name,
|
recipientName: this.receiver?.name,
|
||||||
unitCode: this.unitCode,
|
unitCode: this.unitCode,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ export default class ContactGiftingView extends Vue {
|
|||||||
let giver: GiverReceiverInputInfo | undefined;
|
let giver: GiverReceiverInputInfo | undefined;
|
||||||
|
|
||||||
if (this.stepType === "giver") {
|
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") {
|
if (this.recipientEntityType === "project") {
|
||||||
recipient = {
|
recipient = {
|
||||||
did: this.recipientProjectHandleId,
|
did: this.recipientProjectHandleId,
|
||||||
@@ -204,7 +204,20 @@ export default class ContactGiftingView extends Vue {
|
|||||||
handleId: this.recipientProjectHandleId,
|
handleId: this.recipientProjectHandleId,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
// Preserve the existing recipient from context
|
||||||
|
if (this.recipientDid === this.activeDid) {
|
||||||
|
// Recipient was "You"
|
||||||
recipient = { did: this.activeDid, name: "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
|
giver = undefined; // Will be set to "Unnamed" in GiftedDialog
|
||||||
} else {
|
} else {
|
||||||
@@ -239,12 +252,8 @@ export default class ContactGiftingView extends Vue {
|
|||||||
this.unitCode,
|
this.unitCode,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Immediately select "Unnamed" and move to Step 2 based on stepType
|
// Move to Step 2 - entities are already set by the open() call
|
||||||
if (this.stepType === "giver") {
|
(this.$refs.giftedDialog as GiftedDialog).moveToStep2();
|
||||||
(this.$refs.giftedDialog as GiftedDialog).selectGiver();
|
|
||||||
} else {
|
|
||||||
(this.$refs.giftedDialog as GiftedDialog).selectRecipient();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Regular case: contact is a GiverReceiverInputInfo
|
// Regular case: contact is a GiverReceiverInputInfo
|
||||||
let giver: GiverReceiverInputInfo;
|
let giver: GiverReceiverInputInfo;
|
||||||
@@ -317,6 +326,9 @@ export default class ContactGiftingView extends Vue {
|
|||||||
this.amountInput,
|
this.amountInput,
|
||||||
this.unitCode,
|
this.unitCode,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Move to Step 2 - entities are already set by the open() call
|
||||||
|
(this.$refs.giftedDialog as GiftedDialog).moveToStep2();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user