|
|
@ -17,20 +17,40 @@ |
|
|
|
|
|
|
|
<!-- Results List --> |
|
|
|
<ul class="border-t border-slate-300"> |
|
|
|
<!-- "You" entity --> |
|
|
|
<li v-if="shouldShowYouEntity" class="border-b border-slate-300 py-3"> |
|
|
|
<h2 class="text-base flex gap-4 items-center"> |
|
|
|
<span class="grow flex gap-2 items-center font-medium"> |
|
|
|
<font-awesome icon="hand" class="text-blue-500 text-4xl shrink-0" /> |
|
|
|
<span class="text-ellipsis overflow-hidden text-blue-500">You</span> |
|
|
|
</span> |
|
|
|
<span class="text-right"> |
|
|
|
<button |
|
|
|
type="button" |
|
|
|
class="block w-full text-center text-sm uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md" |
|
|
|
@click="openDialog({ did: activeDid, name: 'You' })" |
|
|
|
> |
|
|
|
<font-awesome icon="gift" class="fa-fw"></font-awesome> |
|
|
|
</button> |
|
|
|
</span> |
|
|
|
</h2> |
|
|
|
</li> |
|
|
|
<li class="border-b border-slate-300 py-3"> |
|
|
|
<h2 class="text-base flex gap-4 items-center"> |
|
|
|
<span class="grow flex gap-2 items-center font-medium"> |
|
|
|
<font-awesome |
|
|
|
icon="circle-question" |
|
|
|
class="text-slate-400 text-4xl" |
|
|
|
class="text-slate-400 text-4xl shrink-0" |
|
|
|
/> |
|
|
|
<span class="italic text-slate-400">(Not Named)</span> |
|
|
|
<span class="text-ellipsis overflow-hidden italic text-slate-500">{{ |
|
|
|
unnamedEntityName |
|
|
|
}}</span> |
|
|
|
</span> |
|
|
|
<span class="text-right"> |
|
|
|
<button |
|
|
|
type="button" |
|
|
|
class="block w-full text-center text-sm uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md" |
|
|
|
@click="openDialog('Unnamed')" |
|
|
|
@click="openDialog({ did: '', name: unnamedEntityName })" |
|
|
|
> |
|
|
|
<font-awesome icon="gift" class="fa-fw"></font-awesome> |
|
|
|
</button> |
|
|
@ -43,14 +63,22 @@ |
|
|
|
class="border-b border-slate-300 py-3" |
|
|
|
> |
|
|
|
<h2 class="text-base flex gap-4 items-center"> |
|
|
|
<span class="grow flex gap-2 items-center font-medium"> |
|
|
|
<span |
|
|
|
class="grow flex gap-2 items-center font-medium overflow-hidden" |
|
|
|
> |
|
|
|
<EntityIcon |
|
|
|
:contact="contact" |
|
|
|
:icon-size="34" |
|
|
|
class="inline-block align-middle border border-slate-300 rounded-full overflow-hidden" |
|
|
|
class="inline-block align-middle border border-slate-300 rounded-full overflow-hidden shrink-0" |
|
|
|
/> |
|
|
|
<span v-if="contact.name">{{ contact.name }}</span> |
|
|
|
<span v-else class="italic text-slate-400">(No name)</span> |
|
|
|
<span v-if="contact.name" class="text-ellipsis overflow-hidden">{{ |
|
|
|
contact.name |
|
|
|
}}</span> |
|
|
|
<span |
|
|
|
v-else |
|
|
|
class="text-ellipsis overflow-hidden italic text-slate-500" |
|
|
|
>{{ contact.did }}</span |
|
|
|
> |
|
|
|
</span> |
|
|
|
<span class="text-right"> |
|
|
|
<button |
|
|
@ -72,6 +100,7 @@ |
|
|
|
:from-project-id="fromProjectId" |
|
|
|
:to-project-id="toProjectId" |
|
|
|
:is-from-project-view="isFromProjectView" |
|
|
|
:hide-show-all="true" |
|
|
|
/> |
|
|
|
</section> |
|
|
|
</template> |
|
|
@ -89,6 +118,7 @@ import { GiverReceiverInputInfo } from "../libs/util"; |
|
|
|
import { logger } from "../utils/logger"; |
|
|
|
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin"; |
|
|
|
import { createNotifyHelpers, TIMEOUTS } from "@/utils/notify"; |
|
|
|
import { UNNAMED_ENTITY_NAME } from "@/constants/entities"; |
|
|
|
@Component({ |
|
|
|
components: { GiftedDialog, QuickNav, EntityIcon }, |
|
|
|
mixins: [PlatformServiceMixin], |
|
|
@ -188,147 +218,151 @@ export default class ContactGiftingView extends Vue { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
openDialog(contact?: GiverReceiverInputInfo | "Unnamed") { |
|
|
|
if (contact === "Unnamed") { |
|
|
|
// Special case: Handle "Unnamed" contacts for both givers and recipients |
|
|
|
let recipient: GiverReceiverInputInfo; |
|
|
|
let giver: GiverReceiverInputInfo | undefined; |
|
|
|
openDialog(contact?: GiverReceiverInputInfo) { |
|
|
|
// Determine the selected entity based on contact type |
|
|
|
const selectedEntity = this.createEntityFromContact(contact); |
|
|
|
|
|
|
|
if (this.stepType === "giver") { |
|
|
|
// We're selecting a giver, so preserve the existing recipient from context |
|
|
|
if (this.recipientEntityType === "project") { |
|
|
|
recipient = { |
|
|
|
did: this.recipientProjectHandleId, |
|
|
|
name: this.recipientProjectName, |
|
|
|
image: this.recipientProjectImage, |
|
|
|
handleId: this.recipientProjectHandleId, |
|
|
|
}; |
|
|
|
} else { |
|
|
|
// 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 { |
|
|
|
// We're selecting a recipient, so recipient is "Unnamed" and giver is preserved from context |
|
|
|
recipient = { did: "", name: "Unnamed" }; |
|
|
|
// Create giver and recipient based on step type and selected entity |
|
|
|
const { giver, recipient } = this.createGiverAndRecipient(selectedEntity); |
|
|
|
|
|
|
|
// 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" }; |
|
|
|
} |
|
|
|
} |
|
|
|
// Open the dialog |
|
|
|
(this.$refs.giftedDialog as GiftedDialog).open( |
|
|
|
giver, |
|
|
|
recipient, |
|
|
|
this.offerId, |
|
|
|
this.prompt, |
|
|
|
this.description, |
|
|
|
this.amountInput, |
|
|
|
this.unitCode, |
|
|
|
); |
|
|
|
|
|
|
|
(this.$refs.giftedDialog as GiftedDialog).open( |
|
|
|
giver, |
|
|
|
recipient, |
|
|
|
this.offerId, |
|
|
|
this.prompt, |
|
|
|
this.description, |
|
|
|
this.amountInput, |
|
|
|
this.unitCode, |
|
|
|
); |
|
|
|
// Move to Step 2 - entities are already set by the open() call |
|
|
|
(this.$refs.giftedDialog as GiftedDialog).moveToStep2(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Creates an entity object from the contact parameter |
|
|
|
* Uses DID-based logic to determine "You" and "Unnamed" entities |
|
|
|
*/ |
|
|
|
private createEntityFromContact( |
|
|
|
contact?: GiverReceiverInputInfo, |
|
|
|
): GiverReceiverInputInfo | undefined { |
|
|
|
if (!contact) { |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
|
|
|
|
// Move to Step 2 - entities are already set by the open() call |
|
|
|
(this.$refs.giftedDialog as GiftedDialog).moveToStep2(); |
|
|
|
// Handle GiverReceiverInputInfo object |
|
|
|
if (contact.did === this.activeDid) { |
|
|
|
// If DID matches active DID, create "You" entity |
|
|
|
return { did: this.activeDid, name: "You" }; |
|
|
|
} else if (!contact.did || contact.did === "") { |
|
|
|
// If DID is empty/null, create "Unnamed" entity |
|
|
|
return { did: "", name: UNNAMED_ENTITY_NAME }; |
|
|
|
} else { |
|
|
|
// Regular case: contact is a GiverReceiverInputInfo |
|
|
|
let giver: GiverReceiverInputInfo; |
|
|
|
let recipient: GiverReceiverInputInfo; |
|
|
|
// Create a copy of the contact to avoid modifying the original |
|
|
|
return { ...contact }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
/** |
|
|
|
* Creates giver and recipient objects based on step type and selected entity |
|
|
|
*/ |
|
|
|
private createGiverAndRecipient(selectedEntity?: GiverReceiverInputInfo): { |
|
|
|
giver: GiverReceiverInputInfo | undefined; |
|
|
|
recipient: GiverReceiverInputInfo; |
|
|
|
} { |
|
|
|
if (this.stepType === "giver") { |
|
|
|
// We're selecting a giver, so the selected entity becomes the giver |
|
|
|
const giver = selectedEntity; |
|
|
|
const recipient = this.createRecipientFromContext(); |
|
|
|
return { giver, recipient }; |
|
|
|
} else { |
|
|
|
// We're selecting a recipient, so the selected entity becomes the recipient |
|
|
|
const recipient = selectedEntity || { |
|
|
|
did: "", |
|
|
|
name: UNNAMED_ENTITY_NAME, |
|
|
|
}; |
|
|
|
const giver = this.createGiverFromContext(); |
|
|
|
return { giver, recipient }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Preserve the existing recipient from the context |
|
|
|
if (this.recipientEntityType === "project") { |
|
|
|
recipient = { |
|
|
|
did: this.recipientProjectHandleId, |
|
|
|
name: this.recipientProjectName, |
|
|
|
image: this.recipientProjectImage, |
|
|
|
handleId: this.recipientProjectHandleId, |
|
|
|
}; |
|
|
|
} else { |
|
|
|
// Check if the preserved recipient was "You" or a regular contact |
|
|
|
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 "Unnamed" |
|
|
|
recipient = { did: "", name: "Unnamed" }; |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* Creates recipient object from context (preserves existing recipient) |
|
|
|
*/ |
|
|
|
private createRecipientFromContext(): GiverReceiverInputInfo { |
|
|
|
if (this.recipientEntityType === "project") { |
|
|
|
return { |
|
|
|
name: this.recipientProjectName, |
|
|
|
image: this.recipientProjectImage, |
|
|
|
handleId: this.recipientProjectHandleId, |
|
|
|
}; |
|
|
|
} else { |
|
|
|
if (this.recipientDid === this.activeDid) { |
|
|
|
return { did: this.activeDid, name: "You" }; |
|
|
|
} else if (this.recipientDid) { |
|
|
|
return { |
|
|
|
did: this.recipientDid, |
|
|
|
name: this.recipientProjectName, |
|
|
|
}; |
|
|
|
} 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 |
|
|
|
return { did: "", name: UNNAMED_ENTITY_NAME }; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 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 { |
|
|
|
// Check if the preserved giver was "You" or a regular contact |
|
|
|
if (this.giverDid === this.activeDid) { |
|
|
|
// Giver was "You" |
|
|
|
giver = { did: this.activeDid, name: "You" }; |
|
|
|
} else if (this.giverDid) { |
|
|
|
// Giver was a regular contact |
|
|
|
giver = { |
|
|
|
did: this.giverDid, |
|
|
|
name: this.giverProjectName || "Someone", |
|
|
|
}; |
|
|
|
} else { |
|
|
|
// Fallback to "Unnamed" |
|
|
|
giver = { did: "", name: "Unnamed" }; |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* Creates giver object from context (preserves existing giver) |
|
|
|
*/ |
|
|
|
private createGiverFromContext(): GiverReceiverInputInfo { |
|
|
|
if (this.giverEntityType === "project") { |
|
|
|
return { |
|
|
|
name: this.giverProjectName, |
|
|
|
image: this.giverProjectImage, |
|
|
|
handleId: this.giverProjectHandleId, |
|
|
|
}; |
|
|
|
} else { |
|
|
|
if (this.giverDid === this.activeDid) { |
|
|
|
return { did: this.activeDid, name: "You" }; |
|
|
|
} else if (this.giverDid) { |
|
|
|
return { |
|
|
|
did: this.giverDid, |
|
|
|
name: this.giverProjectName, |
|
|
|
}; |
|
|
|
} else { |
|
|
|
return { did: "", name: UNNAMED_ENTITY_NAME }; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
(this.$refs.giftedDialog as GiftedDialog).open( |
|
|
|
giver, |
|
|
|
recipient, |
|
|
|
this.offerId, |
|
|
|
this.prompt, |
|
|
|
this.description, |
|
|
|
this.amountInput, |
|
|
|
this.unitCode, |
|
|
|
); |
|
|
|
/** |
|
|
|
* Get the unnamed entity name constant |
|
|
|
*/ |
|
|
|
get unnamedEntityName(): string { |
|
|
|
return UNNAMED_ENTITY_NAME; |
|
|
|
} |
|
|
|
|
|
|
|
// Move to Step 2 - entities are already set by the open() call |
|
|
|
(this.$refs.giftedDialog as GiftedDialog).moveToStep2(); |
|
|
|
get shouldShowYouEntity(): boolean { |
|
|
|
if (this.stepType === "giver") { |
|
|
|
// When selecting a giver, show "You" if the current recipient is not "You" |
|
|
|
// This prevents selecting yourself as both giver and recipient |
|
|
|
if (this.recipientEntityType === "project") { |
|
|
|
// If recipient is a project, we can select "You" as giver |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
// If recipient is a person, check if it's not "You" |
|
|
|
return this.recipientDid !== this.activeDid; |
|
|
|
} |
|
|
|
} else { |
|
|
|
// When selecting a recipient, show "You" if the current giver is not "You" |
|
|
|
// This prevents selecting yourself as both giver and recipient |
|
|
|
if (this.giverEntityType === "project") { |
|
|
|
// If giver is a project, we can select "You" as recipient |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
// If giver is a person, check if it's not "You" |
|
|
|
return this.giverDid !== this.activeDid; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|