Repository Public
1// Courtier et agence : qui publie l'inscription, comment le joindre, où elle2// est aussi publiée, et ce qu'Immo-Ka observe (suivi, identifiants, sources).34import { Link } from "react-router";5import { useQuery } from "@tanstack/react-query";6import { ArrowUpRight, Phone } from "lucide-react";7import {8 agencyPath, bannerPath, contactPath, daysOnline, fetchBannieres, fmtPhone, matchBanniere, sourceLabel, telHref, type Property,9} from "@/lib/api.propriete";10import { fmtAgo } from "@/lib/format";11import { useInView } from "@/lib/hooks";12import { buttonClass } from "@/ui/primitives";13import { Disclosure, fmtDay, KV, Section } from "./kit";1415const same = (a?: string | null, b?: string | null) => !!a && !!b && a.trim().toLowerCase() === b.trim().toLowerCase();16const firm = (s: string) =>17 s18 .toLowerCase()19 .normalize("NFD")20 .replace(/[\u0300-\u036f]/g, "")21 .replace(/\b(inc|ltee|enr)\b\.?/g, "")22 .replace(/[^a-z0-9]+/g, "");23/** « VENDIRECT INC. » → « Vendirect Inc. » ; les sigles à barre oblique (RE/MAX) restent tels quels. */24const titleCase = (s: string) => (s === s.toUpperCase() ? s.replace(/\S+/g, (w) => (w.includes("/") || w.length <= 3 ? w : w[0] + w.slice(1).toLowerCase())) : s);25const initials = (name: string) =>26 name27 .replace(/\(.*?\)/g, "")28 .split(/[\s-]+/)29 .filter((w) => /^[A-Za-zÀ-ÿ]/.test(w))30 .slice(0, 2)31 .map((w) => w[0]!.toUpperCase())32 .join("");3334export function Broker({ p, names }: { p: Property; names?: Record<string, string> }) {35 const [ref, inView] = useInView<HTMLDivElement>("400px");36 const bq = useQuery({ queryKey: ["bannieres"], queryFn: fetchBannieres, enabled: inView, staleTime: Infinity, retry: 0 });37 const source = sourceLabel(p.source, names);38 const d = p.details ?? {};3940 // certaines sources mettent le nom de l'agence à la place du courtier41 const inscripteur = typeof d["Courtier inscripteur"] === "string" ? (d["Courtier inscripteur"] as string).split("—")[0]!.trim() : "";42 const person = p.broker_name && !same(p.broker_name, p.agency) && !same(p.broker_name, source) ? p.broker_name.trim() : inscripteur;43 const role = typeof d["Titre du courtier"] === "string" ? (d["Titre du courtier"] as string) : person ? "Courtier inscripteur" : null;44 const agency = (p.agency || "").trim() || (person ? "" : (p.broker_name || "").trim());45 const phone = p.broker_phone || (typeof d["Courtier inscripteur"] === "string" ? ((d["Courtier inscripteur"] as string).split("—")[1] ?? "").trim() : "");46 const tel = telHref(phone);47 const banner = matchBanniere(p, bq.data?.bannieres);48 const sameFirm = !!banner && !!agency && firm(banner.name) === firm(agency);49 const dups = p.duplicates ?? [];50 const days = daysOnline(p);51 const origin = typeof d.listing_origin_url === "string" ? d.listing_origin_url : typeof d["Annonce originale"] === "string" ? (d["Annonce originale"] as string) : null;52 const headline = person || agency || source;53 const privateSeller = /particulier|owner|propri[ée]taire/i.test(`${d["À vendre par"] ?? ""} ${d["Type vendeur/locateur"] ?? ""} ${p.broker_name ?? ""}`) || /duproprio|kijiji|lespac|fb_marketplace/.test(p.source);5455 return (56 <Section id="courtier" title={privateSeller && !person ? "Vendeur et source" : "Courtier et agence"}>57 <div ref={ref} className="rounded-xl border border-line bg-surface p-5 sm:p-6">58 <div className="flex flex-wrap items-center gap-x-5 gap-y-4">59 <span aria-hidden className="grid size-14 shrink-0 place-items-center rounded-full bg-surface-2 font-display text-[1.15rem] text-ink-2">60 {initials(headline) || "·"}61 </span>62 <div className="min-w-0 flex-1 basis-56">63 <h3 className="break-words text-[1.25rem] leading-snug">{headline}</h3>64 <p className="mt-0.5 text-[0.9rem] text-ink-3">65 {[person ? role : privateSeller ? "Vente par le propriétaire" : null, person && agency ? agency : null].filter(Boolean).join(" · ") || `Inscription publiée par ${source}`}66 </p>67 </div>68 <div className="flex w-full flex-wrap gap-2 sm:w-auto">69 {tel && (70 <a href={tel} className={buttonClass("outline", "md", "num flex-1 sm:flex-none")}>71 <Phone className="size-4" /> {fmtPhone(phone)}72 </a>73 )}74 <a href={p.url} target="_blank" rel="noopener noreferrer nofollow" className={buttonClass("primary", "md", "flex-1 sm:flex-none")}>75 Voir l'inscription <ArrowUpRight className="size-4" />76 </a>77 </div>78 </div>7980 <div className="mt-5 border-t border-line pt-1">81 {agency && (82 <KV83 k="Agence"84 v={85 <Link to={banner && sameFirm ? bannerPath(banner.id) : agencyPath(agency)} className="text-brand hover:underline">86 {agency}87 </Link>88 }89 />90 )}91 {banner && !sameFirm && (92 <KV93 k="Bannière"94 v={95 <Link to={bannerPath(banner.id)} className="text-brand hover:underline">96 {titleCase(banner.name)}97 </Link>98 }99 />100 )}101 <KV k="Source de l'inscription" v={source} />102 {p.mls && <KV k="Nº Centris / MLS" v={<span className="num">{p.mls}</span>} />}103 </div>104 <p className="mt-4 text-[0.8rem] leading-relaxed text-ink-3">105 Immo-Ka regroupe des inscriptions publiées ailleurs : la relation se fait avec le courtier ou le vendeur de l'inscription originale. Le registre de l'OACIQ permet de vérifier le permis d'un courtier.106 </p>107 </div>108109 <div className="mt-5 border-y border-line">110 {dups.length > 0 && (111 <Disclosure title="Aussi publiée sur" meta={`${dups.length} autre${dups.length > 1 ? "s" : ""} site${dups.length > 1 ? "s" : ""}`}>112 <ul>113 {dups.map((x) => (114 <li key={x.uid} className="flex items-center justify-between gap-3 border-t border-line py-2.5 first:border-0">115 <span className="min-w-0">116 <span className="block truncate font-medium text-ink">{sourceLabel(x.source, names)}</span>117 <span className="block truncate text-xs text-ink-3">{[x.broker_name, !same(x.agency, x.broker_name) ? x.agency : null, x.price_label].filter(Boolean).join(" · ")}</span>118 </span>119 <a href={x.url} target="_blank" rel="noopener noreferrer nofollow" className="inline-flex min-h-11 shrink-0 items-center gap-1 font-medium text-brand hover:underline">120 Ouvrir <ArrowUpRight className="size-3.5" />121 </a>122 </li>123 ))}124 </ul>125 <p className="mt-2 text-[0.8rem] text-ink-3">La même propriété, repérée sur d'autres sites. Immo-Ka affiche la version la plus complète.</p>126 </Disclosure>127 )}128 <Disclosure title="Suivi et identifiants" meta={days != null ? (days === 0 ? "en ligne depuis aujourd'hui" : `${days} j en ligne`) : undefined}>129 {p.first_seen ? <KV k="Première observation" v={fmtDay(p.first_seen)} /> : null}130 {days != null && <KV k="En ligne sur Immo-Ka" v={days === 0 ? "depuis aujourd'hui" : `depuis ${days} jour${days > 1 ? "s" : ""}`} />}131 {typeof d.listed_at === "string" && <KV k="Date d'inscription selon la source" v={d.listed_at} />}132 {p.updated_at ? <KV k="Dernière synchronisation" v={fmtAgo(p.updated_at)} /> : null}133 {p.price_label && <KV k="Prix affiché par la source" v={<span className="num">{p.price_label}</span>} />}134 <KV k="Identifiant de la source" v={<span className="num break-all">{p.external_id}</span>} />135 <KV k="Identifiant Immo-Ka" v={<span className="num break-all">{p.uid}</span>} />136 {origin && origin !== p.url && (137 <KV138 k="Fiche d'origine"139 v={140 <a href={origin} target="_blank" rel="noopener noreferrer nofollow" className="text-brand hover:underline">141 Ouvrir142 </a>143 }144 />145 )}146 <p className="mt-2 text-[0.8rem] text-ink-3">Dates mesurées par les synchronisations d'Immo-Ka ; elles ne remplacent pas la date d'inscription officielle.</p>147 </Disclosure>148 <Disclosure title="Sources des données de cette fiche">149 <ul className="space-y-1.5">150 <li>{source} : inscription, prix, photos, caractéristiques, courtier.</li>151 <li>Rôle d'évaluation foncière et modèle d'estimation : valeur estimée, évaluation municipale.</li>152 <li>Statistique Canada (Recensement 2021, mesures de proximité) et INSPQ : portrait du secteur, îlots de chaleur.</li>153 <li>Gouvernement du Québec : zones inondables ; réseau de surveillance de la qualité de l'air.</li>154 <li>OpenStreetMap et Mapbox : lieux à proximité, transport, fond de carte ; gazquebec.ca : prix de l'essence.</li>155 <li>Institutions financières : taux hypothécaires publiés ; Hydro-Québec : estimation du coût d'électricité.</li>156 </ul>157 <Link to={contactPath(p.uid)} className="mt-2 inline-flex min-h-11 items-center font-medium text-brand hover:underline">158 Signaler une erreur sur cette fiche159 </Link>160 </Disclosure>161 </div>162 </Section>163 );164}165