From 68317da74861d1fedfa2439178cc6bd2b912eded Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sun, 28 Jun 2026 18:01:13 -0500 Subject: [PATCH] fix: pre-fill phone_number_id on new company from existing shared value All companies use the same WhatsApp phone number ID. When creating a new company, auto-fill the field with the value already in use so the admin doesn't have to look it up and type it manually. Co-Authored-By: Claude Sonnet 4.6 --- admin/DashboardController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/admin/DashboardController.php b/admin/DashboardController.php index 684eddc..cd64f6e 100644 --- a/admin/DashboardController.php +++ b/admin/DashboardController.php @@ -989,10 +989,17 @@ HTML; $isEdit = $id > 0; $company = $isEdit ? CompanyRepository::findById($id) : null; + // For new companies, default phone_number_id to the shared value already in use + $defaultPhoneNumberId = ''; + if (!$isEdit) { + $r = db()->query("SELECT phone_number_id FROM companies WHERE phone_number_id != '' LIMIT 1")->fetch(); + $defaultPhoneNumberId = $r ? (string)$r['phone_number_id'] : env('WHATSAPP_DEFAULT_PHONE_NUMBER_ID', ''); + } + $cv = fn(string $k, string $d = '') => self::h($company[$k] ?? $d); $name = $cv('name'); $display_name = $cv('display_name'); - $phone_number_id = $cv('phone_number_id'); + $phone_number_id = $isEdit ? $cv('phone_number_id') : self::h($defaultPhoneNumberId); $display_phone = $cv('display_phone'); $api_base_url = $cv('api_base_url'); $api_key = $cv('api_key');