style: clean up code formatting and remove trailing whitespace
refactor: reorganize imports and fix type imports
This commit is contained in:
1 parent
d3704602fd
commit
47c04de6fe
232 files changed
+7140
-4798
No files matched your search
@@ -1,6 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
CheckCircle2,
|
||||
Clock,
|
||||
Loader2,
|
||||
MessageSquare,
|
||||
ShoppingBag,
|
||||
ShoppingCart,
|
||||
User,
|
||||
XCircle,
|
||||
} from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -8,24 +22,10 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
||||
import {
|
||||
ShoppingCart,
|
||||
Clock,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
MessageSquare,
|
||||
User,
|
||||
Loader2,
|
||||
ShoppingBag,
|
||||
} from "lucide-react";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useSession } from "@/lib/hooks/use-session";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
interface PurchaseIntention {
|
||||
intention_id: number;
|
||||
@@ -72,21 +72,30 @@ function getStatusBadge(status: string) {
|
||||
switch (status) {
|
||||
case "pending":
|
||||
return (
|
||||
<Badge variant="secondary" className="bg-yellow-500/20 text-yellow-700 dark:text-yellow-400">
|
||||
<Badge
|
||||
variant="secondary"
|
||||
className="bg-yellow-500/20 text-yellow-700 dark:text-yellow-400"
|
||||
>
|
||||
<Clock className="h-3 w-3 mr-1" />
|
||||
Pendente
|
||||
</Badge>
|
||||
);
|
||||
case "accepted":
|
||||
return (
|
||||
<Badge variant="secondary" className="bg-green-500/20 text-green-700 dark:text-green-400">
|
||||
<Badge
|
||||
variant="secondary"
|
||||
className="bg-green-500/20 text-green-700 dark:text-green-400"
|
||||
>
|
||||
<CheckCircle2 className="h-3 w-3 mr-1" />
|
||||
Aceita
|
||||
</Badge>
|
||||
);
|
||||
case "rejected":
|
||||
return (
|
||||
<Badge variant="secondary" className="bg-red-500/20 text-red-700 dark:text-red-400">
|
||||
<Badge
|
||||
variant="secondary"
|
||||
className="bg-red-500/20 text-red-700 dark:text-red-400"
|
||||
>
|
||||
<XCircle className="h-3 w-3 mr-1" />
|
||||
Rejeitada
|
||||
</Badge>
|
||||
@@ -96,7 +105,9 @@ function getStatusBadge(status: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function formatCustomOffer(intention: PurchaseIntention): { value: string; date: string | null } | null {
|
||||
function formatCustomOffer(
|
||||
intention: PurchaseIntention,
|
||||
): { value: string; date: string | null } | null {
|
||||
if (
|
||||
intention.custom_offer_amount === null ||
|
||||
intention.custom_offer_amount === undefined ||
|
||||
@@ -142,7 +153,10 @@ export function IntentionDetailModal({
|
||||
const [sellerResponse, setSellerResponse] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [listing, setListing] = useState<{ seller_id: number; listing_status: string } | null>(null);
|
||||
const [listing, setListing] = useState<{
|
||||
seller_id: number;
|
||||
listing_status: string;
|
||||
} | null>(null);
|
||||
const [showMarkSoldDialog, setShowMarkSoldDialog] = useState(false);
|
||||
const [markingSold, setMarkingSold] = useState(false);
|
||||
|
||||
@@ -161,7 +175,11 @@ export function IntentionDetailModal({
|
||||
}, [open, listingId]);
|
||||
|
||||
const isOwner = user && listing && user.userId === listing.seller_id;
|
||||
const canMarkAsSold = isOwner && listing && (listing.listing_status === "active" || listing.listing_status === "in_escrow");
|
||||
const canMarkAsSold =
|
||||
isOwner &&
|
||||
listing &&
|
||||
(listing.listing_status === "active" ||
|
||||
listing.listing_status === "in_escrow");
|
||||
const canAcceptOrReject = intention.status === "pending";
|
||||
const customOffer = formatCustomOffer(intention);
|
||||
|
||||
@@ -169,7 +187,7 @@ export function IntentionDetailModal({
|
||||
if (open) {
|
||||
setSellerResponse(intention.seller_response ?? "");
|
||||
}
|
||||
}, [open, intention.intention_id, intention.seller_response]);
|
||||
}, [open, intention.seller_response]);
|
||||
|
||||
const handleAccept = async () => {
|
||||
setLoading(true);
|
||||
@@ -185,7 +203,7 @@ export function IntentionDetailModal({
|
||||
status: "accepted",
|
||||
seller_response: sellerResponse || undefined,
|
||||
}),
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const data = await res.json();
|
||||
@@ -217,7 +235,7 @@ export function IntentionDetailModal({
|
||||
status: "rejected",
|
||||
seller_response: sellerResponse || undefined,
|
||||
}),
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const data = await res.json();
|
||||
@@ -229,7 +247,9 @@ export function IntentionDetailModal({
|
||||
if (onUpdate) onUpdate();
|
||||
onOpenChange(false);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : "Erro ao rejeitar intenção");
|
||||
setError(
|
||||
err instanceof Error ? err.message : "Erro ao rejeitar intenção",
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -241,7 +261,7 @@ export function IntentionDetailModal({
|
||||
const res = await fetch(`/api/listings/${listingId}/mark-sold`, {
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
|
||||
if (!res.ok) {
|
||||
const data = await res.json();
|
||||
throw new Error(data.error || "Erro ao marcar como vendido");
|
||||
@@ -250,13 +270,15 @@ export function IntentionDetailModal({
|
||||
// Invalidar cache para atualizar a lista
|
||||
queryClient.invalidateQueries({ queryKey: ["listings"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["my-listings"] });
|
||||
|
||||
|
||||
if (onUpdate) onUpdate();
|
||||
setShowMarkSoldDialog(false);
|
||||
onOpenChange(false);
|
||||
} catch (error) {
|
||||
console.error("Erro ao marcar como vendido:", error);
|
||||
alert(error instanceof Error ? error.message : "Erro ao marcar como vendido");
|
||||
alert(
|
||||
error instanceof Error ? error.message : "Erro ao marcar como vendido",
|
||||
);
|
||||
} finally {
|
||||
setMarkingSold(false);
|
||||
}
|
||||
@@ -271,7 +293,8 @@ export function IntentionDetailModal({
|
||||
{getStatusBadge(intention.status)}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Detalhes da intenção de compra de {intention.buyer?.username || "usuário"}
|
||||
Detalhes da intenção de compra de{" "}
|
||||
{intention.buyer?.username || "usuário"}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -304,7 +327,9 @@ export function IntentionDetailModal({
|
||||
<div className="space-y-3">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground">Método de Pagamento</Label>
|
||||
<Label className="text-xs text-muted-foreground">
|
||||
Método de Pagamento
|
||||
</Label>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<ShoppingCart className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="font-medium">
|
||||
@@ -313,7 +338,9 @@ export function IntentionDetailModal({
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground">Data de Criação</Label>
|
||||
<Label className="text-xs text-muted-foreground">
|
||||
Data de Criação
|
||||
</Label>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<Clock className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-sm">
|
||||
@@ -328,9 +355,13 @@ export function IntentionDetailModal({
|
||||
<Label className="text-xs text-primary uppercase tracking-wide">
|
||||
Oferta do Comprador
|
||||
</Label>
|
||||
<div className="text-base font-semibold text-primary">{customOffer.value}</div>
|
||||
<div className="text-base font-semibold text-primary">
|
||||
{customOffer.value}
|
||||
</div>
|
||||
{customOffer.date && (
|
||||
<p className="text-[11px] text-primary/70">Enviada em {customOffer.date}</p>
|
||||
<p className="text-[11px] text-primary/70">
|
||||
Enviada em {customOffer.date}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
@@ -398,7 +429,11 @@ export function IntentionDetailModal({
|
||||
Marcar como Vendido
|
||||
</Button>
|
||||
)}
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)} disabled={loading || markingSold}>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => onOpenChange(false)}
|
||||
disabled={loading || markingSold}
|
||||
>
|
||||
Fechar
|
||||
</Button>
|
||||
{canAcceptOrReject && (
|
||||
@@ -420,7 +455,10 @@ export function IntentionDetailModal({
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<Button onClick={handleAccept} disabled={loading || markingSold}>
|
||||
<Button
|
||||
onClick={handleAccept}
|
||||
disabled={loading || markingSold}
|
||||
>
|
||||
{loading ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||
@@ -445,14 +483,18 @@ export function IntentionDetailModal({
|
||||
<DialogHeader>
|
||||
<DialogTitle>Marcar anúncio como vendido?</DialogTitle>
|
||||
<DialogDescription>
|
||||
Ao marcar este anúncio como vendido, as seguintes ações serão executadas:
|
||||
Ao marcar este anúncio como vendido, as seguintes ações serão
|
||||
executadas:
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2 pt-2">
|
||||
<ul className="list-disc list-inside space-y-1 text-sm text-muted-foreground">
|
||||
<li>O anúncio será marcado como "Vendido"</li>
|
||||
<li>O anúncio continuará visível na lista por mais 1 hora</li>
|
||||
<li>Após 1 hora, o anúncio sairá automaticamente da lista de anúncios ativos</li>
|
||||
<li>
|
||||
Após 1 hora, o anúncio sairá automaticamente da lista de
|
||||
anúncios ativos
|
||||
</li>
|
||||
<li>Nenhuma interação (comprar, dar lance) será permitida</li>
|
||||
</ul>
|
||||
<p className="pt-2 font-medium text-foreground">
|
||||
@@ -480,4 +522,3 @@ export function IntentionDetailModal({
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user