fixed show phone number

This commit is contained in:
SlimusMinus
2026-10-27 22:52:10 +03:00
parent 113355c0ef
commit 4b7db41a97
13 changed files with 425 additions and 32 deletions

View File

@@ -5,6 +5,7 @@ import PhoneIcon from "../components/icons/PhoneIcon";
import TrashIcon from "../components/icons/TrashIcon";
import CheckIcon from "../components/icons/CheckIcon";
import {useContactSeller} from "../hooks/useContactSeller";
import {useRevealPhone} from "../hooks/useRevealPhone";
import {useAuthContext} from "../context/AuthContext";
import {getImageUrl} from "../config/authConstants";
import {CATEGORY_PET} from "../config/feedConstants";
@@ -31,6 +32,7 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
// isOwner тут не подходит — в общей ленте он false и для своих объявлений.
const isOwnAd = user?.id != null && ad.userId != null && String(ad.userId) === String(user.id);
const { contactSeller, error: contactError, clearError } = useContactSeller(ad);
const phoneReveal = useRevealPhone(ad.id);
useEffect(() => {
const check = () => {
@@ -108,6 +110,13 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
? t('postCard.foundStatusWithDate', {status: foundText, date: foundDate})
: foundText;
// Номер в ленту не приходит: в «Моих объявлениях» и в админке он есть в ad.phone,
// в общей ленте его открывают кнопкой (proof-of-work на бэкенде) — и автор
// своего объявления тоже, чтобы видеть то же, что покупатель.
// У закрытого объявления номер не показывается: вещь уже вернулась.
const shownPhone = ad.phone || phoneReveal.phone;
const canRevealPhone = !shownPhone && ad.phoneVisible && !isClosed;
const headAccentClass = ad.type === "found" ? " f-head-found" : " f-head-loss";
const typeBadge = (
@@ -317,15 +326,27 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
<div className="f-card-foot">
<div className="f-card-foot-left">
{ad.phone && (
<a className="f-card-phone" href={`tel:${ad.phone}`}
{shownPhone ? (
<a className="f-card-phone" href={`tel:${shownPhone}`}
onClick={e => e.stopPropagation()}>
<PhoneIcon/> {ad.phone}
<PhoneIcon/> {shownPhone}
</a>
) : canRevealPhone && (
<button type="button" className="f-card-phone f-card-phone-reveal"
disabled={phoneReveal.loading}
aria-busy={phoneReveal.loading}
onClick={e => {
e.stopPropagation();
phoneReveal.reveal();
}}>
<PhoneIcon/> {phoneReveal.loading ? t('postCard.phoneChecking') : t('postCard.showPhone')}
</button>
)}
</div>
<div className="f-card-foot-right">
{!isOwnAd && (
{isOwnAd ? (
<span className="f-card-own-label">{t('postCard.ownAd')}</span>
) : (
<button type="button" className="f-card-contact"
onClick={handleContact}>
{t('postCard.write')}
@@ -369,6 +390,14 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
</div>
)}
{phoneReveal.error && (
<Toast
message={phoneReveal.error}
type="error"
onDismiss={phoneReveal.clearError}
/>
)}
{contactError && (
<Toast
message={contactError}