feat: enhance purchase intentions with chat integration and offer tracking
- Added MongoDB chat/message integration for seller responses - Improved seller response validation and default messaging - Integrated automatic chat creation/update when responding to intentions - Added highest custom offer fields to listing queries and models - Enhanced listing data with top offer information for buyers
This commit is contained in:
1 parent
d27526e026
commit
d8e7d5d7e6
19 files changed
+806
-58
No files matched your search
@@ -16,6 +16,9 @@ interface PurchaseIntention {
|
||||
buyer_message: string | null;
|
||||
seller_response: string | null;
|
||||
created_at: string;
|
||||
custom_offer_amount: number | null;
|
||||
custom_offer_currency: string | null;
|
||||
custom_offer_created_at: string | null;
|
||||
buyer?: {
|
||||
user_id: number;
|
||||
username: string;
|
||||
@@ -82,6 +85,28 @@ function getPaymentMethodLabel(method: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
function formatCustomOffer(intention: PurchaseIntention): string | null {
|
||||
if (
|
||||
intention.custom_offer_amount === null ||
|
||||
intention.custom_offer_amount === undefined ||
|
||||
!intention.custom_offer_currency
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const amount = intention.custom_offer_amount;
|
||||
switch (intention.custom_offer_currency) {
|
||||
case "pix":
|
||||
return `R$ ${amount.toFixed(2)}`;
|
||||
case "tibia_coins":
|
||||
return `${Math.round(amount).toLocaleString("pt-BR")} TC`;
|
||||
case "gold_coins":
|
||||
return `${Math.round(amount).toLocaleString("pt-BR")} GP`;
|
||||
default:
|
||||
return amount.toLocaleString("pt-BR");
|
||||
}
|
||||
}
|
||||
|
||||
export function MyAdsIntentionList({ listingId, sellerId }: MyAdsIntentionListProps) {
|
||||
const [intentions, setIntentions] = useState<PurchaseIntention[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -196,6 +221,18 @@ export function MyAdsIntentionList({ listingId, sellerId }: MyAdsIntentionListPr
|
||||
<Clock className="h-3 w-3" />
|
||||
<span>{formatTimeAgo(new Date(intention.created_at))}</span>
|
||||
</div>
|
||||
{formatCustomOffer(intention) && (
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<Badge variant="outline" className="border-primary text-primary">
|
||||
Oferta: {formatCustomOffer(intention)}
|
||||
</Badge>
|
||||
{intention.custom_offer_created_at && (
|
||||
<span className="text-[10px] text-muted-foreground">
|
||||
{new Date(intention.custom_offer_created_at).toLocaleString("pt-BR")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{intention.buyer_message && (
|
||||
<p className="text-xs text-muted-foreground line-clamp-1">
|
||||
<MessageSquare className="h-3 w-3 inline mr-1" />
|
||||
|
||||
Reference in new issue
Block a user