hide "write" button on own ads, log chat creation errors
The feed card showed the contact button on the user's own ads (isOwner is false in the main feed), and the backend rejects a chat with yourself with 400. The button is now hidden when ad.userId is the current user, and createOrGetChat logs the backend error message. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -25,7 +25,10 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
|
||||
const rewardAnchorRef = useRef(null);
|
||||
const descRef = useRef(null);
|
||||
const imgTouchStartRef = useRef(null);
|
||||
const { isAuthenticated } = useAuthContext();
|
||||
const { isAuthenticated, user } = useAuthContext();
|
||||
// Своё объявление: писать самому себе нельзя (бэкенд отвечает 400), кнопку не показываем.
|
||||
// isOwner тут не подходит — в общей ленте он false и для своих объявлений.
|
||||
const isOwnAd = user?.id != null && ad.userId != null && String(ad.userId) === String(user.id);
|
||||
const { contactSeller, error: contactError, clearError } = useContactSeller(ad);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -301,10 +304,12 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
|
||||
)}
|
||||
</div>
|
||||
<div className="f-card-foot-right">
|
||||
<button type="button" className="f-card-contact"
|
||||
onClick={handleContact}>
|
||||
{t('postCard.write')}
|
||||
</button>
|
||||
{!isOwnAd && (
|
||||
<button type="button" className="f-card-contact"
|
||||
onClick={handleContact}>
|
||||
{t('postCard.write')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{onMarkFound && isOwner && !isClosed && (
|
||||
|
||||
Reference in New Issue
Block a user