From 0342c872f4f17b262f23cca3bdc43b58feb28018 Mon Sep 17 00:00:00 2001 From: Jose Olarte III Date: Fri, 20 Jun 2025 15:50:57 +0800 Subject: [PATCH] Fix: added context for ContactGiftingView --- src/components/GiftedDialog.vue | 117 +++++++++++------------- src/views/ContactGiftingView.vue | 148 +++++++++++++++++++++++++++---- 2 files changed, 186 insertions(+), 79 deletions(-) diff --git a/src/components/GiftedDialog.vue b/src/components/GiftedDialog.vue index c8c3236a..076e1f0d 100644 --- a/src/components/GiftedDialog.vue +++ b/src/components/GiftedDialog.vue @@ -151,10 +151,28 @@ :to="{ name: 'contact-gift', query: { - recipientProjectId: toProjectId, - recipientProjectName: giver?.name, - recipientProjectImage: giver?.image, - recipientProjectHandleId: giver?.handleId, + stepType: stepType, + giverEntityType: giverEntityType, + recipientEntityType: recipientEntityType, + ...(stepType === 'giver' + ? { + recipientProjectId: toProjectId, + recipientProjectName: receiver?.name, + recipientProjectImage: receiver?.image, + recipientProjectHandleId: receiver?.handleId, + recipientDid: receiver?.did, + } + : { + giverProjectId: fromProjectId, + giverProjectName: giver?.name, + giverProjectImage: giver?.image, + giverProjectHandleId: giver?.handleId, + giverDid: giver?.did, + }), + fromProjectId: fromProjectId, + toProjectId: toProjectId, + showProjects: (showProjects || false).toString(), + isFromProjectView: (isFromProjectView || false).toString(), }, }" > @@ -185,7 +203,10 @@
- - +

- {{ - recipientEntityType === "project" - ? "Given to project:" - : "Given to:" - }} + Given to project:

{{ receiver?.name || "Unnamed" }} @@ -491,17 +479,17 @@ export default class GiftedDialog extends Vue { @Prop({ default: false }) showProjects = false; @Prop() isFromProjectView = false; - @Watch('showProjects') + @Watch("showProjects") onShowProjectsChange() { this.updateEntityTypes(); } - @Watch('fromProjectId') + @Watch("fromProjectId") onFromProjectIdChange() { this.updateEntityTypes(); } - @Watch('toProjectId') + @Watch("toProjectId") onToProjectIdChange() { this.updateEntityTypes(); } @@ -531,8 +519,9 @@ export default class GiftedDialog extends Vue { // Computed property to help debug template logic get shouldShowProjects() { - const result = (this.stepType === 'giver' && this.giverEntityType === 'project') || - (this.stepType === 'recipient' && this.recipientEntityType === 'project'); + const result = + (this.stepType === "giver" && this.giverEntityType === "project") || + (this.stepType === "recipient" && this.recipientEntityType === "project"); return result; } @@ -544,7 +533,7 @@ export default class GiftedDialog extends Vue { // Reset and set entity types based on current context this.giverEntityType = "person"; this.recipientEntityType = "person"; - + // Determine entity types based on current context if (this.showProjects) { // HomeView "Project" button or ProjectViewView "Given by This" diff --git a/src/views/ContactGiftingView.vue b/src/views/ContactGiftingView.vue index 93a05c22..03241073 100644 --- a/src/views/ContactGiftingView.vue +++ b/src/views/ContactGiftingView.vue @@ -11,7 +11,7 @@ class="text-lg text-center px-2 py-1 absolute -left-2 -top-1" > - Given by... + {{ stepType === "giver" ? "Given by..." : "Given to..." }}

@@ -65,7 +65,13 @@ - + @@ -101,6 +107,21 @@ export default class ContactGiftingView extends Vue { recipientProjectImage = ""; recipientProjectHandleId = ""; + // New context parameters + stepType = "giver"; + giverEntityType = "person" as "person" | "project"; + recipientEntityType = "person" as "person" | "project"; + giverProjectId = ""; + giverProjectName = ""; + giverProjectImage = ""; + giverProjectHandleId = ""; + giverDid = ""; + recipientDid = ""; + fromProjectId = ""; + toProjectId = ""; + showProjects = false; + isFromProjectView = false; + async created() { try { let settings = await databaseUtil.retrieveSettingsForActiveAccount(); @@ -137,6 +158,31 @@ export default class ContactGiftingView extends Vue { (this.$route.query["recipientProjectHandleId"] as string) || ""; this.prompt = (this.$route.query["prompt"] as string) ?? this.prompt; + // Read new context parameters + this.stepType = (this.$route.query["stepType"] as string) || "giver"; + this.giverEntityType = + (this.$route.query["giverEntityType"] as "person" | "project") || + "person"; + this.recipientEntityType = + (this.$route.query["recipientEntityType"] as "person" | "project") || + "person"; + this.giverProjectId = + (this.$route.query["giverProjectId"] as string) || ""; + this.giverProjectName = + (this.$route.query["giverProjectName"] as string) || ""; + this.giverProjectImage = + (this.$route.query["giverProjectImage"] as string) || ""; + this.giverProjectHandleId = + (this.$route.query["giverProjectHandleId"] as string) || ""; + this.giverDid = (this.$route.query["giverDid"] as string) || ""; + this.recipientDid = (this.$route.query["recipientDid"] as string) || ""; + this.fromProjectId = (this.$route.query["fromProjectId"] as string) || ""; + this.toProjectId = (this.$route.query["toProjectId"] as string) || ""; + this.showProjects = + (this.$route.query["showProjects"] as string) === "true"; + this.isFromProjectView = + (this.$route.query["isFromProjectView"] as string) === "true"; + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { logger.error("Error retrieving settings & contacts:", err); @@ -154,33 +200,105 @@ export default class ContactGiftingView extends Vue { } } - openDialog(giver?: GiverReceiverInputInfo | "Unnamed") { - const recipient = this.projectId - ? { - did: this.recipientProjectHandleId, - name: this.recipientProjectName, - image: this.recipientProjectImage, - handleId: this.recipientProjectHandleId, + openDialog(contact?: GiverReceiverInputInfo | "Unnamed") { + if (contact === "Unnamed") { + // Special case: Pass undefined to trigger Step 1, but with "Unnamed" pre-selected + let recipient: GiverReceiverInputInfo; + let giver: GiverReceiverInputInfo | undefined; + + if (this.stepType === "giver") { + // We're selecting a giver, so recipient is either a project or the current user + if (this.recipientEntityType === "project") { + recipient = { + did: this.recipientProjectHandleId, + name: this.recipientProjectName, + image: this.recipientProjectImage, + handleId: this.recipientProjectHandleId, + }; + } else { + recipient = { did: this.activeDid, name: "You" }; } - : { did: this.activeDid, name: "you" }; + giver = undefined; // Will be set to "Unnamed" in GiftedDialog + } else { + // We're selecting a recipient, so recipient is "Unnamed" and giver is preserved from context + recipient = { did: "", name: "Unnamed" }; + + // Preserve the existing giver from the context + if (this.giverEntityType === "project") { + giver = { + did: this.giverProjectHandleId, + name: this.giverProjectName, + image: this.giverProjectImage, + handleId: this.giverProjectHandleId, + }; + } else if (this.giverDid) { + giver = { + did: this.giverDid, + name: this.giverProjectName || "Someone", + }; + } else { + giver = { did: this.activeDid, name: "You" }; + } + } - if (giver === "Unnamed") { - // Special case: Pass undefined to trigger Step 1, but with "Unnamed" pre-selected (this.$refs.customDialog as GiftedDialog).open( - undefined, + giver, recipient, undefined, - "Given by Unnamed", + this.stepType === "giver" ? "Given by Unnamed" : "Given to Unnamed", this.prompt, ); // Immediately select "Unnamed" and move to Step 2 (this.$refs.customDialog as GiftedDialog).selectGiver(); } else { + // Regular case: contact is a GiverReceiverInputInfo + let giver: GiverReceiverInputInfo; + let recipient: GiverReceiverInputInfo; + + if (this.stepType === "giver") { + // We're selecting a giver, so the contact becomes the giver + giver = contact as GiverReceiverInputInfo; // Safe because we know contact is not "Unnamed" or undefined + + // Recipient is either a project or the current user + if (this.recipientEntityType === "project") { + recipient = { + did: this.recipientProjectHandleId, + name: this.recipientProjectName, + image: this.recipientProjectImage, + handleId: this.recipientProjectHandleId, + }; + } else { + recipient = { did: this.activeDid, name: "You" }; + } + } else { + // We're selecting a recipient, so the contact becomes the recipient + recipient = contact as GiverReceiverInputInfo; // Safe because we know contact is not "Unnamed" or undefined + + // Preserve the existing giver from the context + if (this.giverEntityType === "project") { + giver = { + did: this.giverProjectHandleId, + name: this.giverProjectName, + image: this.giverProjectImage, + handleId: this.giverProjectHandleId, + }; + } else if (this.giverDid) { + giver = { + did: this.giverDid, + name: this.giverProjectName || "Someone", + }; + } else { + giver = { did: this.activeDid, name: "You" }; + } + } + (this.$refs.customDialog as GiftedDialog).open( giver, recipient, undefined, - "Given by " + (giver?.name || "someone not named"), + this.stepType === "giver" + ? "Given by " + (contact?.name || "someone not named") + : "Given to " + (contact?.name || "someone not named"), this.prompt, ); }