11"use client" ;
22
33import { useState } from "react" ;
4+ import Link from "next/link" ;
45import { DollarSign } from "lucide-react" ;
5- import { useMutation , useQuery , useQueryClient } from "@tanstack/react-query" ;
6+ import { useQuery , useQueryClient } from "@tanstack/react-query" ;
67import { MakeOfferModal } from "@/components/listings/offer/MakeOfferModal" ;
78import { PhoneInputModal } from "@/components/listings/offer/PhoneInputModal" ;
89import { VerificationCodeModal } from "@/components/listings/offer/VerificationCodeModal" ;
9- import { EditListing } from "@/components/listings/detail/EditListing" ;
1010import { DeleteListing } from "@/components/listings/detail/DeleteListing" ;
1111import { Button } from "@/components/ui/button" ;
12- import {
13- Dialog ,
14- DialogContent ,
15- DialogDescription ,
16- DialogFooter ,
17- DialogHeader ,
18- DialogTitle ,
19- } from "@/components/ui/dialog" ;
2012import { getPhoneStatus } from "@/lib/actions" ;
21- import type { Item , Offer , Sublet } from "@/lib/types" ;
22- import { getMyOfferForListing } from "@/lib/actions" ;
23- import { MyOfferCard } from "@/components/listings/offer/MyOfferCard" ;
24- import { EditMyOfferModal } from "@/components/listings/offer/EditMyOfferModal" ;
25- import { deleteMyOfferForListing } from "@/lib/actions" ;
13+ import type { Item , Sublet } from "@/lib/types" ;
2614
2715interface Props {
2816 listing : Item | Sublet ;
2917 listingPrice : number ;
3018 listingOwnerLabel : string ;
3119 priceLabel ?: string ;
3220 isOwner ?: boolean ;
33- initialMyOffer ?: Offer | null ;
3421}
3522
3623type ModalState = "none" | "phone-input" | "verification" | "offer" ;
@@ -41,12 +28,10 @@ export const ListingActions = ({
4128 priceLabel,
4229 listingOwnerLabel,
4330 isOwner = false ,
44- initialMyOffer = null ,
4531} : Props ) => {
4632 const [ modalState , setModalState ] = useState < ModalState > ( "none" ) ;
4733 const [ pendingPhoneNumber , setPendingPhoneNumber ] = useState < string > ( "" ) ;
4834 const [ isChangingPhone , setIsChangingPhone ] = useState < boolean > ( false ) ;
49- const [ isEditing , setIsEditing ] = useState ( false ) ;
5035 const [ isDeleteOpen , setIsDeleteOpen ] = useState ( false ) ;
5136
5237 const queryClient = useQueryClient ( ) ;
@@ -57,35 +42,16 @@ export const ListingActions = ({
5742 enabled : ! isOwner ,
5843 } ) ;
5944
60- const myOfferQuery = useQuery ( {
61- queryKey : [ "myOffer" , listing . id ] ,
62- queryFn : ( ) => getMyOfferForListing ( listing . id ) ,
63- initialData : initialMyOffer ,
64- enabled : ! isOwner ,
65- staleTime : Infinity ,
66- } ) ;
67-
68- const myOffer = myOfferQuery . data ?? null ;
69-
70- const [ isEditOfferOpen , setIsEditOfferOpen ] = useState ( false ) ;
71- const [ isDeleteOfferOpen , setIsDeleteOfferOpen ] = useState ( false ) ;
72-
73- const deleteMyOfferMutation = useMutation ( {
74- mutationFn : ( ) => deleteMyOfferForListing ( listing . id ) ,
75- onSuccess : ( ) => {
76- setIsDeleteOfferOpen ( false ) ;
77- queryClient . invalidateQueries ( { queryKey : [ "myOffer" , listing . id ] } ) ;
78- } ,
79- } ) ;
80-
8145 if ( isOwner ) {
8246 const typeLabel = listing . listing_type === "sublet" ? "Sublet" : "Item" ;
47+ const editHref =
48+ listing . listing_type === "sublet" ? `/sublets/${ listing . id } /edit` : `/items/${ listing . id } /edit` ;
8349
8450 return (
8551 < >
8652 < div className = "flex items-center justify-end gap-2" >
87- < Button className = "cursor-pointer" variant = "outline" onClick = { ( ) => setIsEditing ( true ) } >
88- Edit Listing
53+ < Button className = "cursor-pointer" variant = "outline" asChild >
54+ < Link href = { editHref } > Edit Listing</ Link >
8955 </ Button >
9056 < Button
9157 className = "cursor-pointer bg-red-500 text-white hover:bg-red-600"
@@ -94,12 +60,6 @@ export const ListingActions = ({
9460 Delete { typeLabel }
9561 </ Button >
9662 </ div >
97-
98- < EditListing
99- listing = { listing }
100- open = { isEditing }
101- onOpenChange = { setIsEditing }
102- />
10363 < DeleteListing
10464 listing = { listing }
10565 open = { isDeleteOpen }
@@ -140,55 +100,6 @@ export const ListingActions = ({
140100 setModalState ( "phone-input" ) ;
141101 } ;
142102
143- if ( myOffer ) {
144- return (
145- < >
146- < MyOfferCard
147- offer = { myOffer }
148- onEdit = { ( ) => setIsEditOfferOpen ( true ) }
149- onDelete = { ( ) => setIsDeleteOfferOpen ( true ) }
150- />
151-
152- < EditMyOfferModal
153- isOpen = { isEditOfferOpen }
154- onClose = { ( ) => setIsEditOfferOpen ( false ) }
155- offer = { myOffer }
156- onSaved = { ( ) => {
157- queryClient . invalidateQueries ( { queryKey : [ "myOffer" , listing . id ] } ) ;
158- setIsEditOfferOpen ( false ) ;
159- } }
160- />
161-
162- < Dialog open = { isDeleteOfferOpen } onOpenChange = { setIsDeleteOfferOpen } >
163- < DialogContent >
164- < DialogHeader >
165- < DialogTitle > Delete Offer</ DialogTitle >
166- < DialogDescription >
167- Are you sure you want to withdraw your offer?
168- </ DialogDescription >
169- </ DialogHeader >
170- < DialogFooter >
171- < Button
172- className = "cursor-pointer"
173- variant = "outline"
174- onClick = { ( ) => setIsDeleteOfferOpen ( false ) }
175- >
176- Cancel
177- </ Button >
178- < Button
179- className = "cursor-pointer bg-red-500 text-white hover:bg-red-600"
180- onClick = { ( ) => deleteMyOfferMutation . mutate ( ) }
181- disabled = { deleteMyOfferMutation . isPending }
182- >
183- { deleteMyOfferMutation . isPending ? "Withdrawing..." : "Withdraw" }
184- </ Button >
185- </ DialogFooter >
186- </ DialogContent >
187- </ Dialog >
188- </ >
189- ) ;
190- }
191-
192103 return (
193104 < >
194105 < Button
0 commit comments