Prefill post phone from user profile

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-26 23:01:47 +03:00
parent a8a0292535
commit bb8f3263f8
2 changed files with 63 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ import MapModal from "./MapModal";
import ClearableField from "../components/ClearableField";
import AddressAutocomplete from "../components/AddressAutocomplete";
import { useIsDesktop } from "../hooks/useIsDesktop";
import { useAuthContext } from "../context/AuthContext";
// Ограничения полей бэкенда (PostFieldLimits): длиннее — 400
const TITLE_MAX_LENGTH = 255;
@@ -30,8 +31,12 @@ export default function CreateUpdatePost({ onClose, onSuccess, initialData, admi
const isEdit = !!initialData;
const { t } = useTranslation();
const isDesktop = useIsDesktop();
const { user } = useAuthContext();
// Телефон из профиля подставляем, чтобы не вводить его в каждом объявлении.
// В админ-режиме правится чужое объявление — телефон админа туда не нужен.
const profilePhone = !adminMode && user?.phone ? formatPhone(user.phone) : "";
const [form, setForm] = useState(
const [form, setForm] = useState(() => (
isEdit
? {
type: (initialData.type || "loss").toLowerCase(),
@@ -39,15 +44,15 @@ export default function CreateUpdatePost({ onClose, onSuccess, initialData, admi
description: initialData.description || "",
category: initialData.category || "",
date: initialData.date || "",
phone: initialData.phone || "",
phone: initialData.phone || profilePhone,
address: initialData.address || initialData.city || "",
rulesAccepted: true,
reward: initialData.reward ?? false,
rewardText: initialData.rewardText
|| (initialData.reward ? t('post.rewardDefault') : "")
}
: EMPTY_FORM
);
: { ...EMPTY_FORM, phone: profilePhone }
));
const [rulesModalOpen, setRulesModalOpen] = useState(false);
const [mapModalOpen, setMapModalOpen] = useState(false);