form khitan starter

This commit is contained in:
Farhaan4 2025-10-28 14:30:25 +07:00
parent cc2e340e17
commit 1987f882dd

View File

@ -2,130 +2,197 @@
<div class="min-h-screen bg-gray-50 py-10 px-6"> <div class="min-h-screen bg-gray-50 py-10 px-6">
<div class="max-w-5xl mx-auto bg-white rounded-2xl shadow-lg p-8"> <div class="max-w-5xl mx-auto bg-white rounded-2xl shadow-lg p-8">
<h1 class="text-2xl font-bold text-center text-gray-800"> <h1 class="text-2xl font-bold text-center text-gray-800">
Form Undangan Khitan Starter Form Undangan Khitan Basic
</h1> </h1>
<p class="text-center text-gray-500 text-sm mb-8"> <p class="text-center text-gray-500 text-sm mb-8">
Isi semua data berikut dengan lengkap dan benar. Isi semua data dengan lengkap dan benar.
</p> </p>
<!-- Data Pemesan --> <!-- Data Pemesan -->
<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 <!-- Nama Pemesan -->
v-model="form.nama_pemesan" <div class="relative">
type="text" <input v-model="form.nama_pemesan" type="text" placeholder=" " required
placeholder="Nama Pemesan" 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" />
required <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
<input peer-valid:top-0 peer-valid:left-1 peer-valid:text-[10px] peer-valid:text-gray-500">
v-model="form.email" Nama Pemesan
type="email" </label>
placeholder="Email" </div>
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" <!-- Email -->
/> <div class="relative">
<input <input v-model="form.email" type="email" placeholder=" " required
v-model="form.no_tlpn" 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" />
type="text" <label class="absolute left-1 top-0 text-gray-400 text-xs transition-all
placeholder="No Telepon" peer-placeholder-shown:top-4 peer-placeholder-shown:left-2 peer-placeholder-shown:text-gray-400 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" 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>
<!-- Data Anak --> <!-- Data Anak -->
<section class="mb-8"> <section class="mb-8">
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">👦 Data Anak yang Dikhitan</h2> <h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">Data Anak yang Dikhitan</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<input <template v-for="(field, i) in [
v-model="form.form.nama_lengkap" { model: 'nama_lengkap', label: 'Nama Lengkap' },
type="text" { model: 'nama_panggilan', label: 'Nama Panggilan' },
placeholder="Nama Lengkap Anak" { model: '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" { model: 'nama_ibu', label: 'Nama Ibu' }
/> ]" :key="i">
<input <div class="relative">
v-model="form.form.nama_bapak" <input v-model="form.form[field.model]" placeholder=" " required class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-4 pb-1.5 text-sm
type="text" focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
placeholder="Nama Bapak" <label class="absolute left-2 text-gray-400 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:text-sm
/> peer-focus:top-0 peer-focus:text-[10px] peer-focus:text-blue-500
<input peer-valid:top-0 peer-valid:text-[10px] peer-valid:text-gray-500">
v-model="form.form.nama_ibu" {{ field.label }}
type="text" </label>
placeholder="Nama Ibu" </div>
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" </template>
/>
</div> </div>
</section> </section>
<!-- Detail Acara --> <!-- Detail Acara -->
<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">
<input <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
v-model="form.form.hari_tanggal_acara" <!-- Hari & Tanggal -->
type="date" <div class="flex flex-col">
placeholder="Hari & Tanggal Acara" <label class="text-gray-600 text-sm font-medium mb-1">Hari & Tanggal 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" <input v-model="form.form.hari_tanggal_acara" type="date" required class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm
/> focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
<input
v-model="form.form.waktu"
type="text"
placeholder="Waktu Acara"
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>
<textarea
v-model="form.form.alamat" <!-- Waktu -->
rows="3" <div class="flex flex-col">
placeholder="Alamat Acara" <label class="text-gray-600 text-sm font-medium mb-1">Waktu Acara</label>
class="w-full border border-gray-300 rounded-lg px-3 py-2 mt-3 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition resize-none" <input v-model="form.form.waktu" type="time" required class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm
></textarea> focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" />
</div>
</div>
<!-- Alamat -->
<div class="mt-6 relative">
<textarea v-model="form.form.alamat" rows="3" placeholder=" " required class="peer w-full border border-gray-300 rounded-lg px-2.5 pt-5 pb-1.5 text-sm resize-none
focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition"></textarea>
<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">
Alamat Acara
</label>
</div>
<!-- Link Google Maps -->
<div class="mt-4 relative">
<input v-model="form.form.link_gmaps" type="url" 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 Google Maps
</label>
</div>
</section>
<!-- Hitung Mundur -->
<section class="mb-8">
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">Hitung Mundur</h2>
<div class="relative">
<input v-model="form.form.hitung_mundur" type="datetime-local" 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 Hitung Mundur
</label>
</div>
</section>
<!-- Rekening -->
<section class="mb-8">
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">Rekening</h2>
<div class="relative">
<input v-model="form.form.rekening_1" 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-2 text-gray-400 transition-all duration-200
peer-placeholder-shown:top-3.5 peer-placeholder-shown:text-sm
peer-focus:top-[-2px] peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-[-2px] peer-valid:text-[10px] peer-valid:text-gray-500">
Rekening 1
</label>
</div>
</section>
<!-- Musik -->
<section class="mb-8">
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">Musik</h2>
<div class="relative">
<input v-model="form.form.link_music" 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-2 text-gray-400 transition-all duration-200
peer-placeholder-shown:top-3.5 peer-placeholder-shown:text-sm
peer-focus:top-[-2px] peer-focus:text-[10px] peer-focus:text-blue-500
peer-valid:top-[-2px] peer-valid:text-[10px] peer-valid:text-gray-500">
Link Musik (opsional)
</label>
</div>
</section>
<!-- Say Something -->
<section class="mb-8">
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">Say Something</h2>
<textarea v-model="form.form.say_something" rows="4" placeholder="Kata-kata atau ucapan terima kasih..."
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> </section>
<!-- Galeri Foto --> <!-- Galeri Foto -->
<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
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" 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. 2, 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 gap-4"> <div v-else class="grid grid-cols-2 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="absolute -top-2 -right-2 bg-red-500 text-white rounded-full w-5 h-5
class="relative group" flex items-center justify-center text-xs opacity-0 group-hover:opacity-100 transition"
> title="Hapus foto">
<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"
title="Hapus foto"
>
</button> </button>
</div> </div>
<label <label v-if="previews.length < 4" for="gallery" class="cursor-pointer flex flex-col items-center justify-center w-24 h-24
v-if="previews.length < 2" border-2 border-dashed border-gray-300 rounded-lg text-gray-400
for="gallery" hover:border-blue-400 hover:text-blue-500 transition">
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>
@ -134,16 +201,10 @@
<!-- Tombol --> <!-- Tombol -->
<div class="text-end mt-6"> <div class="text-end mt-6">
<button <button @click="batal" class="bg-gray-600 text-white font-semibold px-6 py-2 rounded-lg transition mr-2">
@click="batal"
class="bg-gray-600 text-white font-semibold px-6 py-2 rounded-lg transition mr-2"
>
Batal Batal
</button> </button>
<button <button @click="konfirmasi" class="bg-blue-700 text-white font-semibold px-6 py-2 rounded-lg transition">
@click="konfirmasi"
class="bg-blue-700 text-white font-semibold px-6 py-2 rounded-lg transition"
>
Konfirmasi Konfirmasi
</button> </button>
</div> </div>
@ -154,6 +215,7 @@
<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()
@ -163,11 +225,17 @@ const form = ref({
no_tlpn: '', no_tlpn: '',
form: { form: {
nama_lengkap: '', nama_lengkap: '',
nama_panggilan: '',
nama_bapak: '', nama_bapak: '',
nama_ibu: '', nama_ibu: '',
hari_tanggal_acara: '', hari_tanggal_acara: '',
waktu: '', waktu: '',
alamat: '' alamat: '',
link_gmaps: '',
say_something: '',
hitung_mundur: '',
rekening_1: '',
link_music: ''
}, },
foto: [] foto: []
}) })
@ -176,27 +244,25 @@ const previews = ref([])
const handleFileChange = (e) => { const handleFileChange = (e) => {
const files = Array.from(e.target.files) const files = Array.from(e.target.files)
const totalFiles = form.value.foto.length + files.length const total = form.value.foto.length + files.length
if (total > 4) {
if (totalFiles > 2) { Swal.fire('Maksimal 4 foto!', '', 'warning')
alert('Maksimal 2 foto!')
e.target.value = '' e.target.value = ''
return return
} }
files.forEach(file => { files.forEach(file => {
if (file.size > 2 * 1024 * 1024) { if (file.size > 2 * 1024 * 1024) {
alert(`File ${file.name} terlalu besar! Maksimal 2MB.`) Swal.fire(`${file.name} terlalu besar! Maks 2MB.`, '', 'error')
return return
} }
if (!['image/jpeg', 'image/png', 'image/jpg'].includes(file.type)) { if (!['image/jpeg', 'image/png', 'image/jpg'].includes(file.type)) {
alert(`File ${file.name} harus berupa JPEG atau PNG!`) Swal.fire(`${file.name} harus JPEG/PNG.`, '', 'error')
return return
} }
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 = ''
} }
@ -206,17 +272,17 @@ const removeFile = (index) => {
} }
const konfirmasi = async () => { const konfirmasi = async () => {
try {
if (!form.value.nama_pemesan || !form.value.email) { if (!form.value.nama_pemesan || !form.value.email) {
alert('Harap isi semua kolom wajib (Nama Pemesan, Email)!') Swal.fire('Harap isi Nama Pemesan dan Email!', '', 'warning')
return return
} }
try {
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_tlpn) data.append('no_tlpn', form.value.no_tlpn)
data.append('template_slug', 'undangan-khitan-starter') data.append('template_slug', 'undangan-khitan-basic')
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)
@ -235,23 +301,77 @@ const konfirmasi = async () => {
if (!res.ok) { if (!res.ok) {
if (res.status === 422) { if (res.status === 422) {
const errors = result.errors || {} throw new Error(Object.values(result.errors || {}).flat().join('\n'))
const errorMessages = Object.values(errors).flat().join('\n')
throw new Error(errorMessages || result.message || 'Validasi gagal')
}
if (res.status === 404) {
throw new Error(result.message || 'Template tidak ditemukan')
} }
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 berhasil disimpan.',
icon: 'success',
confirmButtonText: 'Lanjut ke WhatsApp',
confirmButtonColor: '#2563eb',
background: '#f9fafb',
color: '#111827',
})
// Kirim ke WhatsApp Admin
const adminNumber = '62895333053398'
const pesan = `
Halo Admin
Ada pesanan baru untuk *Undangan Khitan Basic*
*Data Pemesan*
- Nama: ${form.value.nama_pemesan}
- Email: ${form.value.email}
- No. Telepon: ${form.value.no_tlpn}
*Data Anak*
- Nama Lengkap: ${form.value.form.nama_lengkap || '-'}
- Nama Panggilan: ${form.value.form.nama_panggilan || '-'}
- Bapak: ${form.value.form.nama_bapak || '-'}
- Ibu: ${form.value.form.nama_ibu || '-'}
*Detail Acara*
- Tanggal: ${form.value.form.hari_tanggal_acara || '-'}
- Waktu: ${form.value.form.waktu || '-'}
- Alamat: ${form.value.form.alamat || '-'}
- Gmaps: ${form.value.form.link_gmaps || '-'}
*Hitung Mundur*: ${form.value.form.hitung_mundur || '-'}
*Say Something*:
${form.value.form.say_something || '-'}
*Rekening 1*: ${form.value.form.rekening_1 || '-'}
*Musik*: ${form.value.form.link_music || '-'}
Terima kasih
`
const waUrl = `https://wa.me/${adminNumber}?text=${encodeURIComponent(pesan)}`
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 || 'Terjadi kesalahan saat menyimpan.', 'error')
} }
} }
const batal = () => router.back() const batal = () => {
Swal.fire({
title: 'Batalkan?',
text: 'Perubahan yang belum disimpan akan hilang.',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonColor: '#6b7280',
confirmButtonText: 'Ya, Batalkan'
}).then(result => {
if (result.isConfirmed) router.back()
})
}
</script> </script>