fix: unify two reservation forms into one — wire booking to API
CI/CD / CI · dotnet build (push) Successful in 41s
CI/CD / Deploy · drsousan (push) Successful in 29s

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 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-02 16:51:58 +03:30
parent 772df0698c
commit 81838f75ce
+39 -64
View File
@@ -650,24 +650,6 @@
</div> </div>
</div> </div>
<!-- Health Request Form -->
<div class="health-form-wrap fade-in hidden" id="healthFormWrap">
<div class="health-form-card">
<h3 id="healthFormTitle">درخواست مشاوره</h3>
<p style="color:var(--mid);font-size:.88rem;margin-bottom:1.5rem">فرم زیر را تکمیل کنید. تیم ما در اسرع وقت با شما تماس می‌گیرد.</p>
<input type="hidden" id="hf-category"/>
<div class="form-row">
<div class="form-group"><label>نام و نام خانوادگی *</label><input id="hf-name" placeholder="نام شما" required/></div>
<div class="form-group"><label>شماره موبایل *</label><input id="hf-phone" type="tel" placeholder="09xx-xxx-xxxx" required/></div>
</div>
<div class="form-group"><label>ایمیل (اختیاری)</label><input id="hf-email" type="email" placeholder="email@example.com"/></div>
<div class="form-group"><label>شرح درخواست یا مشکل</label><textarea id="hf-message" rows="4" placeholder="لطفاً مشکل یا درخواست خود را بنویسید ..."></textarea></div>
<div style="display:flex;gap:.8rem;flex-wrap:wrap">
<button class="form-submit" id="hf-submit" onclick="submitHealthForm()" style="flex:1">ارسال درخواست</button>
<button onclick="document.getElementById('healthFormWrap').classList.add('hidden')" style="background:transparent;border:1.5px solid var(--border);border-radius:12px;padding:.8rem 1.5rem;cursor:pointer;font-family:inherit;font-size:.9rem">انصراف</button>
</div>
</div>
</div>
</div> </div>
</section> </section>
@@ -775,37 +757,39 @@
<div class="contact-form fade-in"> <div class="contact-form fade-in">
<div class="form-title">رزرو نوبت آنلاین</div> <div class="form-title">رزرو نوبت آنلاین</div>
<p class="form-sub">فرم زیر را پر کنید، در اسرع وقت با شما تماس می‌گیریم.</p> <p class="form-sub">فرم زیر را پر کنید، در اسرع وقت با شما تماس می‌گیریم.</p>
<form onsubmit="handleSubmit(event)"> <form id="bookingForm" onsubmit="handleSubmit(event)">
<input type="hidden" id="booking-category" value="beauty"/>
<div class="form-row"> <div class="form-row">
<div class="form-group"> <div class="form-group">
<label>نام</label> <label>نام</label>
<input type="text" placeholder="نام شما" required /> <input id="booking-firstname" type="text" placeholder="نام شما" required />
</div> </div>
<div class="form-group"> <div class="form-group">
<label>نام خانوادگی</label> <label>نام خانوادگی</label>
<input type="text" placeholder="نام خانوادگی" required /> <input id="booking-lastname" type="text" placeholder="نام خانوادگی" required />
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>شماره موبایل</label> <label>شماره موبایل</label>
<input type="tel" placeholder="09XX-XXX-XXXX" required /> <input id="booking-phone" type="tel" placeholder="09XX-XXX-XXXX" required />
</div> </div>
<div class="form-group"> <div class="form-group">
<label>نوع خدمت مورد نظر</label> <label>نوع خدمت مورد نظر</label>
<select> <select id="booking-service" onchange="document.getElementById('booking-category').value=this.value==='سلامت عمومی'?'health':'beauty'">
<option value="" disabled selected>انتخاب خدمت</option> <option value="" disabled selected>انتخاب خدمت</option>
@foreach (var svc in Model.Services) @foreach (var svc in Model.Services)
{ {
<option>@svc.Title</option> <option>@svc.Title</option>
} }
<option value="سلامت عمومی">سلامت عمومی</option>
<option>سایر</option> <option>سایر</option>
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>توضیحات (اختیاری)</label> <label>توضیحات (اختیاری)</label>
<textarea placeholder="مشکل پوستی یا سوالات خود را اینجا بنویسید..."></textarea> <textarea id="booking-message" placeholder="مشکل پوستی، سوال یا درخواست خود را بنویسید..."></textarea>
</div> </div>
<button type="submit" class="form-submit">ارسال و رزرو نوبت</button> <button type="submit" class="form-submit" id="booking-submit">ارسال و رزرو نوبت</button>
</form> </form>
</div> </div>
</div> </div>
@@ -835,65 +819,56 @@
}); });
}); });
// Form submission // Main booking form submits to /api/health-request
function handleSubmit(e) { async function handleSubmit(e) {
e.preventDefault(); e.preventDefault();
const btn = e.target.querySelector('.form-submit'); const btn = document.getElementById('booking-submit');
btn.textContent = '✓ درخواست شما ثبت شد'; const firstName = document.getElementById('booking-firstname').value.trim();
btn.style.background = '#2D7A4F'; const lastName = document.getElementById('booking-lastname').value.trim();
setTimeout(() => { const phone = document.getElementById('booking-phone').value.trim();
btn.textContent = 'ارسال و رزرو نوبت'; const service = document.getElementById('booking-service').value;
btn.style.background = ''; const message = document.getElementById('booking-message').value.trim();
e.target.reset(); const category = document.getElementById('booking-category').value || 'beauty';
}, 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');
btn.textContent = '...در حال ارسال'; btn.textContent = '...در حال ارسال';
btn.disabled = true; btn.disabled = true;
try { 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', { const res = await fetch('/api/health-request', {
method: 'POST', method: 'POST',
headers: {'Content-Type':'application/json'}, 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(); if (!res.ok) throw new Error();
btn.textContent = '✓ درخواست شما ثبت شد'; btn.textContent = '✓ درخواست شما ثبت شد';
btn.style.background = '#2D7A4F'; btn.style.background = '#2D7A4F';
['hf-name','hf-phone','hf-email','hf-message'].forEach(id => document.getElementById(id).value='');
setTimeout(() => { setTimeout(() => {
document.getElementById('healthFormWrap').classList.add('hidden'); btn.textContent = 'ارسال و رزرو نوبت';
btn.textContent = 'ارسال درخواست';
btn.style.background = ''; btn.style.background = '';
btn.disabled = false; btn.disabled = false;
}, 3000); e.target.reset();
document.getElementById('booking-category').value = 'beauty';
}, 3500);
} catch { } catch {
btn.textContent = 'خطا — دوباره تلاش کنید'; btn.textContent = 'خطا — دوباره تلاش کنید';
btn.style.background = '#c62828'; 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 // Active nav link on scroll
const sections = document.querySelectorAll('section[id]'); const sections = document.querySelectorAll('section[id]');
window.addEventListener('scroll', () => { window.addEventListener('scroll', () => {