fix form ultah basic

This commit is contained in:
Farhaan4 2025-10-28 10:49:05 +07:00
parent 024c9b243f
commit 6eaa82f652

View File

@ -12,12 +12,41 @@
<section class="mb-8"> <section class="mb-8">
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">📋 Data Pemesan</h2> <h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">📋 Data Pemesan</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4"> <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<input v-model="form.nama_pemesan" type="text" placeholder="Nama Pemesan" <!-- Nama Pemesan -->
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> <div class="relative">
<input v-model="form.email" type="email" placeholder="Email" <input v-model="form.nama_pemesan" type="text" placeholder=" " required
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
<input v-model="form.no_tlpn" type="text" placeholder="No Telepon" <label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:left-1 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
Nama Pemesan
</label>
</div>
<!-- Email -->
<div class="relative">
<input v-model="form.email" type="email" placeholder=" " required
class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
<label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:left-1 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
Email
</label>
</div>
<!-- No Telepon -->
<div class="relative">
<input v-model="form.no_tlpn" type="text" placeholder=" " required
class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
<label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:left-1 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
No Telepon
</label>
</div>
</div> </div>
</section> </section>
@ -25,19 +54,25 @@
<section class="mb-8"> <section class="mb-8">
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">🎉 Data Anak</h2> <h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">🎉 Data Anak</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6"> <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div> <div class="grid gap-4">
<div class="grid gap-2"> <template v-for="(field, i) in [
<input v-model="form.form.nama_lengkap" placeholder="Nama Lengkap" { key: 'nama_lengkap', label: 'Nama Lengkap' },
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> { key: 'nama_panggilan', label: 'Nama Panggilan' },
<input v-model="form.form.nama_panggilan" placeholder="Nama Panggilan" { key: 'nama_bapak', label: 'Nama Bapak' },
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> { key: 'nama_ibu', label: 'Nama Ibu' },
<input v-model="form.form.nama_bapak" placeholder="Nama Bapak" { key: 'umur_yang_dirayakan', label: 'Umur Yang Dirayakan', type: 'number' }
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> ]" :key="i">
<input v-model="form.form.nama_ibu" placeholder="Nama Ibu" <div class="relative">
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> <input v-model="form.form[field.key]" :type="field.type || 'text'" required placeholder=" "
<input v-model="form.form.umur_yang_dirayakan" type="number" placeholder="Umur Yang Dirayakan" class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> <label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:left-1 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
{{ field.label }}
</label>
</div> </div>
</template>
</div> </div>
</div> </div>
</section> </section>
@ -46,29 +81,108 @@
<section class="mb-8"> <section class="mb-8">
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">📅 Detail Acara</h2> <h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">📅 Detail Acara</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<input v-model="form.form.hari_tanggal_acara" type="date" placeholder="Hari & Tanggal Acara" <div class="relative">
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> <input v-model="form.form.hari_tanggal_acara" type="date" required placeholder=" " class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm
<input v-model="form.form.waktu" type="text" placeholder="Waktu" focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> <label class="absolute left-2 text-gray-400 transition-all
<textarea v-model="form.form.alamat" rows="4" placeholder="Alamat" peer-placeholder-shown:top-4 peer-placeholder-shown:text-sm
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition resize-none"></textarea> peer-focus:top-0 peer-focus:text-[10px] peer-focus:text-blue-500
<input v-model="form.form.link_gmaps" type="text" placeholder="Link Gmaps" peer-valid:top-0 peer-valid:text-[10px] peer-valid:text-gray-500">
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> Hari & Tanggal Acara
<input v-model="form.form.hitung_mundur" type="datetime-local" placeholder="Hitung Mundur Waktu Acara" </label>
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> </div>
<div class="relative">
<input v-model="form.form.waktu" type="time" required placeholder=" " class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm
focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
<label class="absolute left-2 text-gray-400 transition-all
peer-placeholder-shown:top-4 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:text-[10px] peer-valid:text-gray-500">
Waktu Acara
</label>
</div>
<div class="relative md:col-span-2">
<textarea v-model="form.form.alamat" rows="4" required placeholder=" "
class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
<label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:left-1 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
Alamat
</label>
</div>
<div class="relative md:col-span-2">
<input v-model="form.form.link_gmaps" type="text" required placeholder=" "
class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
<label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:left-1 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
Link Gmaps
</label>
</div>
<div class="relative">
<input v-model="form.form.hitung_mundur_mulai" type="datetime-local" required placeholder=" " class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm
focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
<label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:left-1 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
Hitung Mundur Mulai
</label>
</div>
<div class="relative">
<input v-model="form.form.hitung_mundur_selesai" type="datetime-local" required placeholder=" " class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm
focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
<label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:left-1 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
Hitung Mundur Selesai
</label>
</div>
</div> </div>
</section> </section>
<!-- Pesan & Rekening --> <!-- Pesan & Rekening -->
<section class="mb-8"> <section class="mb-8">
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">💌 Pesan & Rekening</h2> <h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">💌 Pesan & Rekening</h2>
<textarea v-model="form.form.say_something" rows="4" placeholder="Say Something..."
<!-- Say Something -->
<section class="mb-8">
<textarea v-model="form.form.say_something" rows="4" placeholder="Kata-kata spesial atau pesan untuk tamu..."
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition resize-none"></textarea> class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition resize-none"></textarea>
</section>
<div class="grid md:grid-cols-1 gap-4 mt-4"> <div class="grid md:grid-cols-1 gap-4 mt-4">
<input v-model="form.form.rekening_1" placeholder="Rekening 1" <div class="relative">
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> <input v-model="form.form.rekening_1" placeholder=" " required
<input v-model="form.form.link_music" placeholder="Link Music (opsional)" class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> <label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:left-1 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
Rekening 1
</label>
</div>
<div class="grid md:grid-cols-1 gap-4 mt-4">
<div class="relative">
<input v-model="form.form.link_music" placeholder=" " required
class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
<label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 peer-placeholder-shown:text-sm
peer-focus:top-0 peer-focus:left-1 peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
Link Music (opsional)
</label>
</div>
</div>
</div> </div>
</section> </section>
@ -76,43 +190,23 @@
<section class="mb-8"> <section class="mb-8">
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">🖼 Galeri Foto</h2> <h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">🖼 Galeri Foto</h2>
<div <div
class="border-2 border-dashed border-gray-300 rounded-xl p-8 flex flex-col justify-center items-center text-gray-400 hover:border-blue-400 hover:text-blue-500 transition" class="border-2 border-dashed border-gray-300 rounded-xl p-8 flex flex-col justify-center items-center text-gray-400 hover:border-blue-400 hover:text-blue-500 transition">
> <input id="gallery" type="file" multiple accept="image/*" class="hidden" @change="handleFileChange" />
<input
id="gallery"
type="file"
multiple
accept="image/*"
class="hidden"
@change="handleFileChange"
/>
<label v-if="!previews.length" for="gallery" class="cursor-pointer flex flex-col items-center"> <label v-if="!previews.length" for="gallery" class="cursor-pointer flex flex-col items-center">
<span class="text-4xl font-bold">+</span> <span class="text-4xl font-bold">+</span>
<span class="text-sm mt-2">Pilih Foto (maks. 4, JPEG/PNG, maks. 2MB)</span> <span class="text-sm mt-2">Pilih Foto (maks. 4, JPEG/PNG, maks. 2MB)</span>
</label> </label>
<div v-else class="grid grid-cols-2 sm:grid-cols-4 gap-4"> <div v-else class="grid grid-cols-3 sm:grid-cols-4 gap-4">
<div <div v-for="(src, i) in previews" :key="i" class="relative group">
v-for="(src, i) in previews" <img :src="src" class="w-24 h-24 object-cover rounded-lg border shadow" />
:key="i" <button @click="removeFile(i)"
class="relative group"
>
<img
:src="src"
class="w-24 h-24 object-cover rounded-lg border shadow"
/>
<button
@click="removeFile(i)"
class="absolute -top-2 -right-2 bg-red-500 text-white rounded-full w-5 h-5 flex items-center justify-center text-xs opacity-0 group-hover:opacity-100 transition" class="absolute -top-2 -right-2 bg-red-500 text-white rounded-full w-5 h-5 flex items-center justify-center text-xs opacity-0 group-hover:opacity-100 transition"
title="Hapus foto" title="Hapus foto">
>
</button> </button>
</div> </div>
<label <label v-if="previews.length < 4" for="gallery"
v-if="previews.length < 4" class="cursor-pointer flex flex-col items-center justify-center w-24 h-24 border-2 border-dashed border-gray-300 rounded-lg text-gray-400 hover:border-blue-400 hover:text-blue-500 transition">
for="gallery"
class="cursor-pointer flex flex-col items-center justify-center w-24 h-24 border-2 border-dashed border-gray-300 rounded-lg text-gray-400 hover:border-blue-400 hover:text-blue-500 transition"
>
<span class="text-3xl font-bold">+</span> <span class="text-3xl font-bold">+</span>
</label> </label>
</div> </div>
@ -121,12 +215,10 @@
<!-- Tombol --> <!-- Tombol -->
<div class="text-end mt-6"> <div class="text-end mt-6">
<button @click="batal" <button @click="batal" class="bg-gray-600 text-white font-semibold px-6 py-2 rounded-lg transition mr-2">
class="bg-gray-600 text-white font-semibold px-6 py-2 rounded-lg transition mr-2">
Batal Batal
</button> </button>
<button @click="konfirmasi" <button @click="konfirmasi" class="bg-blue-700 text-white font-semibold px-6 py-2 rounded-lg transition">
class="bg-blue-700 text-white font-semibold px-6 py-2 rounded-lg transition">
Konfirmasi Konfirmasi
</button> </button>
</div> </div>
@ -137,8 +229,10 @@
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import Swal from 'sweetalert2'
const router = useRouter() const router = useRouter()
const ADMIN_WA = '62895333053398'
const form = ref({ const form = ref({
nama_pemesan: '', nama_pemesan: '',
@ -154,7 +248,8 @@ const form = ref({
waktu: '', waktu: '',
alamat: '', alamat: '',
link_gmaps: '', link_gmaps: '',
hitung_mundur: '', hitung_mundur_mulai: '',
hitung_mundur_selesai: '',
say_something: '', say_something: '',
rekening_1: '', rekening_1: '',
link_music: '' link_music: ''
@ -175,7 +270,6 @@ const handleFileChange = (e) => {
} }
files.forEach(file => { files.forEach(file => {
// Validate file size (2MB) and type
if (file.size > 2 * 1024 * 1024) { if (file.size > 2 * 1024 * 1024) {
alert(`File ${file.name} terlalu besar! Maksimal 2MB.`) alert(`File ${file.name} terlalu besar! Maksimal 2MB.`)
return return
@ -187,7 +281,6 @@ const handleFileChange = (e) => {
form.value.foto.push(file) form.value.foto.push(file)
previews.value.push(URL.createObjectURL(file)) previews.value.push(URL.createObjectURL(file))
}) })
e.target.value = '' e.target.value = ''
} }
@ -198,7 +291,6 @@ const removeFile = (index) => {
const konfirmasi = async () => { const konfirmasi = async () => {
try { try {
// Basic client-side validation
if (!form.value.nama_pemesan || !form.value.email) { if (!form.value.nama_pemesan || !form.value.email) {
alert('Harap isi kolom wajib (Nama Pemesan, Email)!') alert('Harap isi kolom wajib (Nama Pemesan, Email)!')
return return
@ -207,10 +299,9 @@ const konfirmasi = async () => {
const data = new FormData() const data = new FormData()
data.append('nama_pemesan', form.value.nama_pemesan) data.append('nama_pemesan', form.value.nama_pemesan)
data.append('email', form.value.email) data.append('email', form.value.email)
data.append('no_tlpn', form.value.no_telepon) data.append('no_tlpn', form.value.no_tlpn)
data.append('template_slug', 'undangan-ulang-tahun-basic') data.append('template_slug', 'undangan-ulang-tahun-basic')
// Append form fields individually to ensure Laravel receives them as an array
for (const [key, value] of Object.entries(form.value.form)) { for (const [key, value] of Object.entries(form.value.form)) {
data.append(`form[${key}]`, value) data.append(`form[${key}]`, value)
} }
@ -240,11 +331,70 @@ const konfirmasi = async () => {
throw new Error(result.message || 'Gagal mengirim data') throw new Error(result.message || 'Gagal mengirim data')
} }
alert(result.message || 'Data berhasil disimpan!') await Swal.fire({
title: '🎉 Berhasil!',
text: result.message || 'Data undangan kamu berhasil disimpan.',
icon: 'success',
confirmButtonText: 'Lanjut ke WhatsApp',
confirmButtonColor: '#2563eb',
background: '#f9fafb',
color: '#111827',
showClass: {
popup: 'animate__animated animate__fadeInDown'
},
hideClass: {
popup: 'animate__animated animate__fadeOutUp'
}
})
const f = form.value
const child = f.form
const message = `
Halo Admin 👋,
Saya ingin membuat *Undangan Ulang Tahun Basic* 🎂
📋 *Data Pemesan*
- Nama: ${f.nama_pemesan}
- Email: ${f.email}
- No. Telepon: ${f.no_tlpn}
🎉 *Data Anak*
- Nama Lengkap: ${child.nama_lengkap}
- Nama Panggilan: ${child.nama_panggilan}
- Umur: ${child.umur_yang_dirayakan} tahun
- Bapak: ${child.nama_bapak}
- Ibu: ${child.nama_ibu}
📅 *Detail Acara*
- Tanggal: ${child.hari_tanggal_acara}
- Waktu: ${child.waktu}
- Alamat: ${child.alamat}
- Link Gmaps: ${child.link_gmaps || '-'}
💌 *Pesan Tambahan*
${child.say_something || '-'}
Terima kasih 🙏
`
const encodedMsg = encodeURIComponent(message)
const waUrl = `https://wa.me/${ADMIN_WA}?text=${encodedMsg}`
Swal.fire({
title: 'Membuka WhatsApp...',
text: 'Mohon tunggu sebentar ⏳',
timer: 1500,
timerProgressBar: true,
showConfirmButton: false,
willClose: () => {
window.open(waUrl, '_blank')
router.push('/') router.push('/')
}
})
} catch (err) { } catch (err) {
console.error(err) console.error(err)
alert('Terjadi kesalahan: ' + err.message) Swal.fire('❌ Gagal', err.message, 'error')
} }
} }