From 813225ff6db5de7d770f83154e9e85d725eec8f6 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Sat, 11 Jul 2026 15:16:27 +0330 Subject: [PATCH] fix(doctor claim): mobile field is the account number, read-only Mobile is prefilled from the logged-in user's cookie (userInfo.mobile_number) and rendered read-only; removed it from editable form state/validation and send that number in the claim body. Backend already enforces it must match the account, so the field can't diverge. Co-Authored-By: Claude Opus 4.8 (1M context) --- components/doctor/claim/index.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/components/doctor/claim/index.js b/components/doctor/claim/index.js index f1badbe..a098d9b 100644 --- a/components/doctor/claim/index.js +++ b/components/doctor/claim/index.js @@ -7,11 +7,20 @@ import { Box, Button, Modal, TextField } from "@mui/material"; import { styleDefault } from "@/mui"; import JalaliDatePicker from "@/components/common/JalaliDatePicker"; import CloseModalD from "@/components/icons/CloseModalD"; +import Cookies from "js-cookie"; import { convertToJalali, isUserLoggedIn } from "@/helper"; import { request } from "@/services/response"; import Altcha from "@/components/Altcha"; -const initialForm = { national_code: "", birth_date: "", first_name: "", last_name: "", mobile: "" }; +const initialForm = { national_code: "", birth_date: "", first_name: "", last_name: "" }; + +function currentUserMobile() { + try { + return JSON.parse(Cookies.get("userInfo") || "{}")?.mobile_number || ""; + } catch { + return ""; + } +} /** * احراز مالکیت پروفایل پزشک ایمپورت‌شده (unclaimed). @@ -37,6 +46,7 @@ function ClaimProfileSection({ doctor }) { } const loggedIn = isUserLoggedIn(); + const userMobile = currentUserMobile(); const setField = (key, value) => { setForm((f) => ({ ...f, [key]: value })); @@ -50,8 +60,6 @@ function ClaimProfileSection({ doctor }) { if (!form.birth_date) errs.birth_date = "تاریخ تولد را انتخاب کنید"; if (!form.first_name.trim()) errs.first_name = "نام الزامی است"; if (!form.last_name.trim()) errs.last_name = "نام خانوادگی الزامی است"; - const mob = form.mobile.replace(/[۰-۹]/g, (d) => "۰۱۲۳۴۵۶۷۸۹".indexOf(d)); - if (!/^09\d{9}$/.test(mob)) errs.mobile = "شماره موبایل نامعتبر است"; setFieldErrors(errs); return Object.keys(errs).length === 0; }; @@ -61,7 +69,7 @@ function ClaimProfileSection({ doctor }) { setLoading(true); setError(""); try { - await request.postDoctorClaim(doctor.uuid, { ...form, altcha }); + await request.postDoctorClaim(doctor.uuid, { ...form, mobile: userMobile, altcha }); setLoading(false); setSuccess(true); } catch (err) { @@ -219,11 +227,10 @@ function ClaimProfileSection({ doctor }) { /> setField("mobile", e.target.value)} - inputProps={{ maxLength: 11, dir: "ltr" }} + value={userMobile} + helperText="شمارهٔ حساب کاربری شما (غیرقابل ویرایش)" + InputProps={{ readOnly: true }} + inputProps={{ dir: "ltr" }} fullWidth />