From 81838f75ced81d676faacace8137667f52e1927f Mon Sep 17 00:00:00 2001 From: "soroush.asadi" Date: Tue, 2 Jun 2026 16:51:58 +0330 Subject: [PATCH] =?UTF-8?q?fix:=20unify=20two=20reservation=20forms=20into?= =?UTF-8?q?=20one=20=E2=80=94=20wire=20booking=20to=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: two parallel booking systems: 1. 'رزرو نوبت آنلاین' contact form — never saved data (fake submit) 2. Health section inline form — saved to /api/health-request Fix: - Contact form now POSTs to /api/health-request (real save) - Added ids to all form inputs so JS can read them - Category auto-detected from service dropdown (سلامت عمومی → health) - Health section 'درخواست...' buttons now scroll to contact form and pre-select the right category — no duplicate inline form - Removed the duplicate healthFormWrap + submitHealthForm() - All reservations visible in admin under 'درخواست‌ها' Co-Authored-By: Claude Sonnet 4.5 --- DrSousan.Api/Pages/Index.cshtml | 103 ++++++++++++-------------------- 1 file changed, 39 insertions(+), 64 deletions(-) diff --git a/DrSousan.Api/Pages/Index.cshtml b/DrSousan.Api/Pages/Index.cshtml index 9671b55..c2256e8 100644 --- a/DrSousan.Api/Pages/Index.cshtml +++ b/DrSousan.Api/Pages/Index.cshtml @@ -650,24 +650,6 @@ - - @@ -775,37 +757,39 @@
رزرو نوبت آنلاین

فرم زیر را پر کنید، در اسرع وقت با شما تماس می‌گیریم.

-
+ +
- +
- +
- +
- @foreach (var svc in Model.Services) { } +
- +
- +
@@ -835,65 +819,56 @@ }); }); - // Form submission - function handleSubmit(e) { + // Main booking form — submits to /api/health-request + async function handleSubmit(e) { e.preventDefault(); - const btn = e.target.querySelector('.form-submit'); - btn.textContent = '✓ درخواست شما ثبت شد'; - btn.style.background = '#2D7A4F'; - setTimeout(() => { - btn.textContent = 'ارسال و رزرو نوبت'; - btn.style.background = ''; - e.target.reset(); - }, 3000); - } - - // Health care request form - function openHealthForm(category) { - document.getElementById('hf-category').value = category; - document.getElementById('healthFormTitle').textContent = - category === 'health' ? 'درخواست مراقبت سلامت عمومی' : 'درخواست مشاوره زیبایی پوست'; - const wrap = document.getElementById('healthFormWrap'); - wrap.classList.remove('hidden'); - setTimeout(() => wrap.scrollIntoView({behavior:'smooth', block:'center'}), 100); - } - async function submitHealthForm() { - const name = document.getElementById('hf-name').value.trim(); - const phone = document.getElementById('hf-phone').value.trim(); - if (!name || !phone) { alert('نام و شماره تلفن الزامی است'); return; } - const btn = document.getElementById('hf-submit'); + const btn = document.getElementById('booking-submit'); + const firstName = document.getElementById('booking-firstname').value.trim(); + const lastName = document.getElementById('booking-lastname').value.trim(); + const phone = document.getElementById('booking-phone').value.trim(); + const service = document.getElementById('booking-service').value; + const message = document.getElementById('booking-message').value.trim(); + const category = document.getElementById('booking-category').value || 'beauty'; btn.textContent = '...در حال ارسال'; btn.disabled = true; try { - const body = { - fullName: name, - phoneNumber: phone, - email: document.getElementById('hf-email').value, - message: document.getElementById('hf-message').value, - category: document.getElementById('hf-category').value - }; const res = await fetch('/api/health-request', { method: 'POST', headers: {'Content-Type':'application/json'}, - body: JSON.stringify(body) + body: JSON.stringify({ + fullName: firstName + ' ' + lastName, + phoneNumber: phone, + email: '', + message: (service ? 'خدمت: ' + service + '\n' : '') + message, + category: category + }) }); if (!res.ok) throw new Error(); btn.textContent = '✓ درخواست شما ثبت شد'; btn.style.background = '#2D7A4F'; - ['hf-name','hf-phone','hf-email','hf-message'].forEach(id => document.getElementById(id).value=''); setTimeout(() => { - document.getElementById('healthFormWrap').classList.add('hidden'); - btn.textContent = 'ارسال درخواست'; + btn.textContent = 'ارسال و رزرو نوبت'; btn.style.background = ''; btn.disabled = false; - }, 3000); + e.target.reset(); + document.getElementById('booking-category').value = 'beauty'; + }, 3500); } catch { btn.textContent = 'خطا — دوباره تلاش کنید'; btn.style.background = '#c62828'; - setTimeout(() => { btn.textContent='ارسال درخواست'; btn.style.background=''; btn.disabled=false; }, 2500); + setTimeout(() => { btn.textContent='ارسال و رزرو نوبت'; btn.style.background=''; btn.disabled=false; }, 2500); } } + // Health section buttons scroll to contact form and pre-select category + function openHealthForm(category) { + document.getElementById('booking-category').value = category; + // Pre-select matching service if health + const sel = document.getElementById('booking-service'); + if (category === 'health') sel.value = 'سلامت عمومی'; + document.getElementById('contact').scrollIntoView({behavior:'smooth', block:'start'}); + } + // Active nav link on scroll const sections = document.querySelectorAll('section[id]'); window.addEventListener('scroll', () => {