[feet] undangan ulang tahun starter + basic
This commit is contained in:
parent
23ae9529bb
commit
1918987187
252
proyek-frontend/app/pages/form/undangan-ulang-tahun-basic.vue
Normal file
252
proyek-frontend/app/pages/form/undangan-ulang-tahun-basic.vue
Normal file
@ -0,0 +1,252 @@
|
||||
<template>
|
||||
<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">
|
||||
<h1 class="text-2xl font-bold text-center text-gray-800">
|
||||
Form Undangan Ulang Tahun Basic
|
||||
</h1>
|
||||
<p class="text-center text-gray-500 text-sm mb-8">
|
||||
Isi semua data berikut dengan lengkap dan benar.
|
||||
</p>
|
||||
|
||||
<!-- Data Pemesan -->
|
||||
<section class="mb-8">
|
||||
<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">
|
||||
<input v-model="form.nama_pemesan" type="text" placeholder="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" />
|
||||
<input v-model="form.email" type="email" placeholder="Email"
|
||||
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.no_tlpn" type="text" placeholder="No Telepon"
|
||||
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>
|
||||
</section>
|
||||
|
||||
<!-- Data Anak -->
|
||||
<section class="mb-8">
|
||||
<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>
|
||||
<div class="grid gap-2">
|
||||
<input v-model="form.form.nama_lengkap" placeholder="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" />
|
||||
<input v-model="form.form.nama_panggilan" placeholder="Nama Panggilan"
|
||||
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.nama_bapak" placeholder="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" />
|
||||
<input v-model="form.form.nama_ibu" placeholder="Nama Ibu"
|
||||
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.umur_yang_dirayakan" type="number" placeholder="Umur Yang Dirayakan"
|
||||
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>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Detail Acara -->
|
||||
<section class="mb-8">
|
||||
<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 v-model="form.form.hari_tanggal_acara" type="date" placeholder="Hari & Tanggal 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" />
|
||||
<input v-model="form.form.waktu" type="text" placeholder="Waktu"
|
||||
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" />
|
||||
<textarea v-model="form.form.alamat" rows="4" placeholder="Alamat"
|
||||
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>
|
||||
<input v-model="form.form.link_gmaps" type="text" placeholder="Link Gmaps"
|
||||
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.hitung_mundur" type="datetime-local" placeholder="Hitung Mundur 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>
|
||||
</section>
|
||||
|
||||
<!-- Pesan & Rekening -->
|
||||
<section class="mb-8">
|
||||
<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..."
|
||||
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>
|
||||
<div class="grid md:grid-cols-1 gap-4 mt-4">
|
||||
<input v-model="form.form.rekening_1" placeholder="Rekening 1"
|
||||
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.link_music" placeholder="Link Music (opsional)"
|
||||
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>
|
||||
</section>
|
||||
|
||||
<!-- Foto Upload -->
|
||||
<section class="mb-8">
|
||||
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">🖼️ Galeri Foto</h2>
|
||||
<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"
|
||||
>
|
||||
<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">
|
||||
<span class="text-4xl font-bold">+</span>
|
||||
<span class="text-sm mt-2">Pilih Foto (maks. 4, JPEG/PNG, maks. 2MB)</span>
|
||||
</label>
|
||||
<div v-else class="grid grid-cols-2 sm:grid-cols-4 gap-4">
|
||||
<div
|
||||
v-for="(src, i) in previews"
|
||||
:key="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"
|
||||
title="Hapus foto"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<label
|
||||
v-if="previews.length < 4"
|
||||
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>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Tombol -->
|
||||
<div class="text-end mt-6">
|
||||
<button @click="batal"
|
||||
class="bg-gray-600 text-white font-semibold px-6 py-2 rounded-lg transition mr-2">
|
||||
Batal
|
||||
</button>
|
||||
<button @click="konfirmasi"
|
||||
class="bg-blue-700 text-white font-semibold px-6 py-2 rounded-lg transition">
|
||||
Konfirmasi
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const form = ref({
|
||||
nama_pemesan: '',
|
||||
email: '',
|
||||
no_tlpn: '',
|
||||
form: {
|
||||
nama_lengkap: '',
|
||||
nama_panggilan: '',
|
||||
nama_bapak: '',
|
||||
nama_ibu: '',
|
||||
umur_yang_dirayakan: '',
|
||||
hari_tanggal_acara: '',
|
||||
waktu: '',
|
||||
alamat: '',
|
||||
link_gmaps: '',
|
||||
hitung_mundur: '',
|
||||
say_something: '',
|
||||
rekening_1: '',
|
||||
link_music: ''
|
||||
},
|
||||
foto: []
|
||||
})
|
||||
|
||||
const previews = ref([])
|
||||
|
||||
const handleFileChange = (e) => {
|
||||
const files = Array.from(e.target.files)
|
||||
const totalFiles = form.value.foto.length + files.length
|
||||
|
||||
if (totalFiles > 4) {
|
||||
alert('Maksimal 4 foto!')
|
||||
e.target.value = ''
|
||||
return
|
||||
}
|
||||
|
||||
files.forEach(file => {
|
||||
// Validate file size (2MB) and type
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
alert(`File ${file.name} terlalu besar! Maksimal 2MB.`)
|
||||
return
|
||||
}
|
||||
if (!['image/jpeg', 'image/png', 'image/jpg'].includes(file.type)) {
|
||||
alert(`File ${file.name} harus berupa JPEG atau PNG!`)
|
||||
return
|
||||
}
|
||||
form.value.foto.push(file)
|
||||
previews.value.push(URL.createObjectURL(file))
|
||||
})
|
||||
|
||||
e.target.value = ''
|
||||
}
|
||||
|
||||
const removeFile = (index) => {
|
||||
form.value.foto.splice(index, 1)
|
||||
previews.value.splice(index, 1)
|
||||
}
|
||||
|
||||
const konfirmasi = async () => {
|
||||
try {
|
||||
// Basic client-side validation
|
||||
if (!form.value.nama_pemesan || !form.value.email) {
|
||||
alert('Harap isi kolom wajib (Nama Pemesan, Email)!')
|
||||
return
|
||||
}
|
||||
|
||||
const data = new FormData()
|
||||
data.append('nama_pemesan', form.value.nama_pemesan)
|
||||
data.append('email', form.value.email)
|
||||
data.append('no_tlpn', form.value.no_telepon)
|
||||
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)) {
|
||||
data.append(`form[${key}]`, value)
|
||||
}
|
||||
|
||||
form.value.foto.forEach((file, index) => {
|
||||
data.append(`foto[${index}]`, file)
|
||||
})
|
||||
|
||||
console.log([...data]) // untuk debugging
|
||||
|
||||
const res = await fetch('http://localhost:8000/api/pelanggans', {
|
||||
method: 'POST',
|
||||
body: data
|
||||
})
|
||||
|
||||
const result = await res.json()
|
||||
|
||||
if (!res.ok) {
|
||||
if (res.status === 422) {
|
||||
const errors = result.errors || {}
|
||||
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')
|
||||
}
|
||||
|
||||
alert(result.message || 'Data berhasil disimpan!')
|
||||
router.push('/')
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
alert('Terjadi kesalahan: ' + err.message)
|
||||
}
|
||||
}
|
||||
|
||||
const batal = () => router.back()
|
||||
</script>
|
||||
221
proyek-frontend/app/pages/form/undangan-ulang-tahun-starter.vue
Normal file
221
proyek-frontend/app/pages/form/undangan-ulang-tahun-starter.vue
Normal file
@ -0,0 +1,221 @@
|
||||
<template>
|
||||
<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">
|
||||
<h1 class="text-2xl font-bold text-center text-gray-800">
|
||||
Form Undangan Ulang Tahun Starter
|
||||
</h1>
|
||||
<p class="text-center text-gray-500 text-sm mb-8">
|
||||
Isi semua data berikut dengan lengkap dan benar.
|
||||
</p>
|
||||
|
||||
<!-- Data Pemesan -->
|
||||
<section class="mb-8">
|
||||
<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">
|
||||
<input v-model="form.nama_pemesan" type="text" placeholder="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" />
|
||||
<input v-model="form.email" type="email" placeholder="Email"
|
||||
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.no_tlpn" type="text" placeholder="No Telepon"
|
||||
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>
|
||||
</section>
|
||||
|
||||
<!-- Data Anak -->
|
||||
<section class="mb-8">
|
||||
<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>
|
||||
<div class="grid gap-2">
|
||||
<input v-model="form.form.nama_lengkap" placeholder="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" />
|
||||
<input v-model="form.form.umur_yang_dirayakan" type="number" placeholder="Umur Yang Dirayakan"
|
||||
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>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Detail Acara -->
|
||||
<section class="mb-8">
|
||||
<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 v-model="form.form.hari_tanggal_acara" type="date" placeholder="Hari & Tanggal 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" />
|
||||
<input v-model="form.form.waktu" type="text" placeholder="Waktu"
|
||||
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" />
|
||||
<textarea v-model="form.form.alamat" rows="4" placeholder="Alamat"
|
||||
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>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Foto Upload -->
|
||||
<section class="mb-8">
|
||||
<h2 class="font-semibold text-blue-600 mb-3 border-b pb-1">🖼️ Galeri Foto</h2>
|
||||
<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"
|
||||
>
|
||||
<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">
|
||||
<span class="text-4xl font-bold">+</span>
|
||||
<span class="text-sm mt-2">Pilih Foto (maks. 2, JPEG/PNG, maks. 2MB)</span>
|
||||
</label>
|
||||
<div v-else class="grid grid-cols-2 sm:grid-cols-2 gap-4">
|
||||
<div
|
||||
v-for="(src, i) in previews"
|
||||
:key="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"
|
||||
title="Hapus foto"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<label
|
||||
v-if="previews.length < 2"
|
||||
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>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Tombol -->
|
||||
<div class="text-end mt-6">
|
||||
<button @click="batal"
|
||||
class="bg-gray-600 text-white font-semibold px-6 py-2 rounded-lg transition mr-2">
|
||||
Batal
|
||||
</button>
|
||||
<button @click="konfirmasi"
|
||||
class="bg-blue-700 text-white font-semibold px-6 py-2 rounded-lg transition">
|
||||
Konfirmasi
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const form = ref({
|
||||
nama_pemesan: '',
|
||||
email: '',
|
||||
no_tlpn: '',
|
||||
form: {
|
||||
nama_lengkap: '',
|
||||
umur_yang_dirayakan: '',
|
||||
hari_tanggal_acara: '',
|
||||
waktu: '',
|
||||
alamat: ''
|
||||
},
|
||||
foto: []
|
||||
})
|
||||
|
||||
const previews = ref([])
|
||||
|
||||
const handleFileChange = (e) => {
|
||||
const files = Array.from(e.target.files)
|
||||
const totalFiles = form.value.foto.length + files.length
|
||||
|
||||
if (totalFiles > 2) {
|
||||
alert('Maksimal 2 foto!')
|
||||
e.target.value = ''
|
||||
return
|
||||
}
|
||||
|
||||
files.forEach(file => {
|
||||
// Validate file size (2MB) and type
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
alert(`File ${file.name} terlalu besar! Maksimal 2MB.`)
|
||||
return
|
||||
}
|
||||
if (!['image/jpeg', 'image/png', 'image/jpg'].includes(file.type)) {
|
||||
alert(`File ${file.name} harus berupa JPEG atau PNG!`)
|
||||
return
|
||||
}
|
||||
form.value.foto.push(file)
|
||||
previews.value.push(URL.createObjectURL(file))
|
||||
})
|
||||
|
||||
e.target.value = ''
|
||||
}
|
||||
|
||||
const removeFile = (index) => {
|
||||
form.value.foto.splice(index, 1)
|
||||
previews.value.splice(index, 1)
|
||||
}
|
||||
|
||||
const konfirmasi = async () => {
|
||||
try {
|
||||
// Basic client-side validation
|
||||
if (!form.value.nama_pemesan || !form.value.email) {
|
||||
alert('Harap isi kolom wajib (Nama Pemesan, Email)!')
|
||||
return
|
||||
}
|
||||
|
||||
const data = new FormData()
|
||||
data.append('nama_pemesan', form.value.nama_pemesan)
|
||||
data.append('email', form.value.email)
|
||||
data.append('no_tlpn', form.value.no_telepon)
|
||||
data.append('template_slug', 'undangan-ulang-tahun-starter')
|
||||
|
||||
// Append form fields individually to ensure Laravel receives them as an array
|
||||
for (const [key, value] of Object.entries(form.value.form)) {
|
||||
data.append(`form[${key}]`, value)
|
||||
}
|
||||
|
||||
form.value.foto.forEach((file, index) => {
|
||||
data.append(`foto[${index}]`, file)
|
||||
})
|
||||
|
||||
console.log([...data]) // untuk debugging
|
||||
|
||||
const res = await fetch('http://localhost:8000/api/pelanggans', {
|
||||
method: 'POST',
|
||||
body: data
|
||||
})
|
||||
|
||||
const result = await res.json()
|
||||
|
||||
if (!res.ok) {
|
||||
if (res.status === 422) {
|
||||
const errors = result.errors || {}
|
||||
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')
|
||||
}
|
||||
|
||||
alert(result.message || 'Data berhasil disimpan!')
|
||||
router.push('/')
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
alert('Terjadi kesalahan: ' + err.message)
|
||||
}
|
||||
}
|
||||
|
||||
const batal = () => router.back()
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user