Prefill post phone from user profile
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user