import { ArrowRight, BadgePlus, LogIn } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/router"; import toast from "react-hot-toast"; import { ContattoAnnuncio } from "~/components/annuncio-interactions/contatto_modal"; import LoadingButton from "~/components/custom_ui/loading-button"; import { Button, buttonVariants } from "~/components/ui/button"; import { cn } from "~/lib/utils"; import { useAnnuncio } from "~/providers/AnnuncioProvider"; import type { SessionContextType } from "~/providers/SessionProvider"; import type { AnnunciId } from "~/schemas/public/Annunci"; import type { UsersId } from "~/schemas/public/Users"; import { api } from "~/utils/api"; export const AnnuncioInteractions = ({ session, disabled, }: { session: SessionContextType; disabled?: boolean; }) => { const router = useRouter(); const { id, tipo } = useAnnuncio(); if (disabled) { return (
Richieste Temporaneamente disattivate
); } return (
{session.user ? ( tipo ? ( ) : ( Errore ) ) : (
Accedi se hai un account oppure
)}
); }; const ServizioInteraction = ({ userId, tipologia, annuncioId, }: { userId: UsersId; tipologia: string; annuncioId: AnnunciId; }) => { const { data: servizio, isLoading } = api.servizio.AnnuncioServizioTipologiaMatch.useQuery({ annuncioId, tipologia, userId, }); if (isLoading) return ; if ( servizio === undefined || servizio.status === "invalid" || servizio.status === "not_found" ) { return (

Non hai un servizio attivo

); } if (servizio.status === "already_saved") { return (
Annuncio già salvato!
); } return ; }; export const InteressatoButton = ({ annuncioId, }: { annuncioId: AnnunciId; }) => { const { data: hasInterest, isLoading } = api.intrests.hasUserInterest.useQuery({ annuncioId, }); const utils = api.useUtils(); const { mutate: add } = api.intrests.addIntrest.useMutation({ onSuccess: async () => { await utils.intrests.hasUserInterest.invalidate({ annuncioId, }); toast.success("Richiesta di interesse inviata con successo!"); }, }); if (isLoading || hasInterest === undefined) { return ( ); } if (hasInterest) { return ( Hai già mandato una richiesta ); } return ( ); }; export const InteressatoButtonBatchV = ({ annuncioId, hasInterest, }: { annuncioId: AnnunciId; hasInterest: boolean; }) => { const utils = api.useUtils(); const { mutate: add } = api.intrests.addIntrest.useMutation({ onSuccess: async () => { await utils.intrests.getUserInterests.invalidate(); toast.success("Richiesta di interesse inviata con successo!"); }, }); if (hasInterest) { return ( Hai già mandato una richiesta ); } return ( ); };