fix: SearchableSelect matches value across string/number types

Insurance option values are strings (String(insurance_id)) while the patient
profile prefill is a number, so strict === matching left بیمه پایه/تکمیلی
showing the placeholder on load — the saved insurance was invisible and looked
unsaved even though PATCH persisted it. Match with String(o.value) ===
String(value) so numeric prefills bind to string-valued options (and vice
versa); null/'' still selects nothing. Verified live: selects now display the
saved insurance after reload.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-16 11:16:22 +03:30
co-authored by Claude Opus 4.8
parent 2e2b63f72d
commit f5b0ddc69e
2 changed files with 38 additions and 1 deletions
@@ -34,8 +34,12 @@ export default function SearchableSelect({
}: Props) {
const darkMode = useUiStore((s) => s.darkMode);
// مقایسهٔ نرم (string↔number): مقدار پیش‌فرض ممکن است number باشد ولی value گزینه String
// (مثلاً id بیمه). تطبیق سخت‌گیرانه در این حالت گزینه را خالی نشان می‌داد.
const selected = useMemo(
() => options.find((o) => o.value === value) ?? null,
() => (value == null || value === ''
? null
: options.find((o) => String(o.value) === String(value)) ?? null),
[options, value],
);