ganti query tabel villas ke vb_villas

This commit is contained in:
2025-06-07 01:31:01 +08:00
parent 75e93b9d5b
commit 4644eea89f

View File

@@ -5,7 +5,7 @@
type Villa = {
id: string;
name: string;
villa_name: string;
villa_manager: string;
villa_location: string;
villa_status: string;
@@ -15,13 +15,13 @@
monthly_rental_pre_approved_status: boolean;
long_term_rental_pre_approval: boolean;
pet_allowed_pre_approval_status: boolean;
session_1_rate: number;
session_2_rate: number;
session_3_rate: number;
session_4_rate: number;
session_5_rate: number;
session_6_rate: number;
session_7_rate: number;
season_1_rate: number;
season_2_rate: number;
season_3_rate: number;
season_4_rate: number;
season_5_rate: number;
season_6_rate: number;
season_7_rate: number;
villa_email_address: string;
villa_recovery_email_adress: string;
owner_portal_username: string;
@@ -42,7 +42,7 @@
};
const columns: columns[] = [
{ key: "name", title: "Name" },
{ key: "villa_name", title: "Villa Name" },
{ key: "villa_manager", title: "Villa Manager" },
{ key: "villa_location", title: "Villa Location" },
{ key: "villa_status", title: "Villa Status" },
@@ -61,13 +61,13 @@
key: "pet_allowed_pre_approval_status",
title: "Pet Allowed Pre Approval Status",
},
{ key: "session_1_rate", title: "Session 1 Rate" },
{ key: "session_2_rate", title: "Session 2 Rate" },
{ key: "session_3_rate", title: "Session 3 Rate" },
{ key: "session_4_rate", title: "Session 4 Rate" },
{ key: "session_5_rate", title: "Session 5 Rate" },
{ key: "session_6_rate", title: "Session 6 Rate" },
{ key: "session_7_rate", title: "Session 7 Rate" },
{ key: "season_1_rate", title: "Season 1 Rate" },
{ key: "season_2_rate", title: "Season 2 Rate" },
{ key: "season_3_rate", title: "Season 3 Rate" },
{ key: "season_4_rate", title: "Season 4 Rate" },
{ key: "season_5_rate", title: "Season 5 Rate" },
{ key: "season_6_rate", title: "Season 6 Rate" },
{ key: "season_7_rate", title: "Season 7 Rate" },
{ key: "villa_email_address", title: "Villa Email Address" },
{
key: "villa_recovery_email_adress",
@@ -87,10 +87,10 @@
limit: number | null = null,
offset: number | null = null,
) {
let query = supabase.from("villas").select("*");
let query = supabase.from("vb_villas").select("*");
if (filter) {
query = query.ilike("name", `%${filter}%`);
query = query.ilike("villa_name", `%${filter}%`);
}
if (sort) {
@@ -121,9 +121,9 @@
// count the total number of rows
const { count, error: countError } = await supabase
.from("villas")
.from("vb_villas")
.select("*", { count: "exact" })
.ilike("name", filter ? `%${filter}%` : "%");
.ilike("villa_name", filter ? `%${filter}%` : "%");
if (countError) {
console.error("Error counting villas:", countError);
@@ -172,28 +172,28 @@
// Basic validation: check if required fields are filled
const errors: { [key: string]: string } = {};
const requiredFields = [
"name",
"villa_manager",
"villa_location",
"villa_name",
// "villa_manager",
// "villa_location",
"villa_status",
"no_of_bedrooms",
"villa_condition",
"session_1_rate",
"session_2_rate",
"session_3_rate",
"session_4_rate",
"session_5_rate",
"session_6_rate",
"session_7_rate",
"villa_email_address",
"owner_portal_username",
"owner_portal_password",
"closeable_living_room",
"monthly_rental_pre_approved_status",
"long_term_rental_pre_approval",
"pet_allowed_pre_approval_status",
"villa_recovery_email_adress",
"villa_email_address",
// "villa_condition",
// "season_1_rate",
// "season_2_rate",
// "season_3_rate",
// "season_4_rate",
// "season_5_rate",
// "season_6_rate",
// "season_7_rate",
// "villa_email_address",
// "owner_portal_username",
// "owner_portal_password",
// "closeable_living_room",
// "monthly_rental_pre_approved_status",
// "long_term_rental_pre_approval",
// "pet_allowed_pre_approval_status",
// "villa_recovery_email_adress",
// "villa_email_address",
];
requiredFields.forEach((field) => {
if (!formData.get(field) || formData.get(field) === "") {
@@ -221,7 +221,7 @@
if (isEditing && currentEditingId) {
const { error } = await supabase
.from("villas")
.from("vb_villas")
.update(newVilla)
.eq("id", currentEditingId);
if (error) {
@@ -229,7 +229,7 @@
return;
}
} else {
const { error } = await supabase.from("villas").insert([newVilla]);
const { error } = await supabase.from("vb_villas").insert([newVilla]);
if (error) {
alert("Error adding villa: " + error.message);
return;
@@ -243,7 +243,7 @@
async function deleteVilla(id: string) {
if (confirm("Are you sure you want to delete this villa?")) {
const { error } = await supabase
.from("villas")
.from("vb_villas")
.delete()
.eq("id", id);
if (error) {
@@ -262,7 +262,7 @@
// update villa status
async function updateVillaStatus(villaId: string, status: string) {
const { error } = await supabase
.from("villas")
.from("vb_villas")
.update({ villa_status: status })
.eq("id", villaId);
if (error) {
@@ -275,7 +275,7 @@
// update villa condition
async function updateVillaCondition(villaId: string, condition: string) {
const { error } = await supabase
.from("villas")
.from("vb_villas")
.update({ villa_condition: condition })
.eq("id", villaId);
if (error) {
@@ -317,19 +317,19 @@
}}
>
<option value="created_at">Sort by Created At</option>
<option value="name">Sort by Name</option>
<option value="villa_name">Sort by Villa Name</option>
<option value="villa_manager">Sort by Villa Manager</option>
<option value="villa_location">Sort by Villa Location</option>
<option value="villa_status">Sort by Villa Status</option>
<option value="no_of_bedrooms">Sort by No Of Bedrooms</option>
<option value="villa_condition">Sort by Villa Condition</option>
<option value="session_1_rate">Sort by Session 1 Rate</option>
<option value="session_2_rate">Sort by Session 2 Rate</option>
<option value="session_3_rate">Sort by Session 3 Rate</option>
<option value="session_4_rate">Sort by Session 4 Rate</option>
<option value="session_5_rate">Sort by Session 5 Rate</option>
<option value="session_6_rate">Sort by Session 6 Rate</option>
<option value="session_7_rate">Sort by Session 7 Rate</option>
<option value="season_1_rate">Sort by Season 1 Rate</option>
<option value="season_2_rate">Sort by Season 2 Rate</option>
<option value="season_3_rate">Sort by Season 3 Rate</option>
<option value="season_4_rate">Sort by Season 4 Rate</option>
<option value="season_5_rate">Sort by Season 5 Rate</option>
<option value="season_6_rate">Sort by Season 6 Rate</option>
<option value="season_7_rate">Sort by Season 7 Rate</option>
</select>
<button
class="bg-gray-200 text-gray-700 px-4 py-2 rounded-xl hover:bg-gray-300 text-sm transition"
@@ -352,7 +352,7 @@
<thead class="bg-gray-100">
<tr>
{#each columns as col}
{#if col.key === "name"}
{#if col.key === "villa_name"}
<th
class="sticky left-0 px-4 py-3 text-left font-semibold text-gray-700 uppercase tracking-wider whitespace-nowrap"
style="background-color: #f0f8ff; z-index: 10;"
@@ -373,7 +373,7 @@
{#each allRows as row}
<tr class="hover:bg-gray-50 transition">
{#each columns as col}
{#if col.key === "name"}
{#if col.key === "villa_name"}
<td
class="sticky left-0 px-4 py-2 font-medium text-blue-600"
style="background-color: #f0f8ff; cursor: pointer;"
@@ -410,9 +410,9 @@
<option value="" disabled
>SELECT STATUS</option
>
<option value="available">ACTIVE</option
<option value="Active">ACTIVE</option
>
<option value="rented">INACTIVE</option>
<option value="Inactive">INACTIVE</option>
</select>
</td>
{:else if col.key === "villa_condition"}
@@ -433,11 +433,10 @@
<option value="" disabled
>SELECT CONDITION</option
>
<option value="new">New</option>
<option value="good">Good</option>
<option value="needs_maintenance"
>Needs Maintenance</option
>
<option value="Occupied">Occupied</option>
<option value="Vacant clean">Vacant clean</option>
<option value="Vacant dirty">Vacant Dirty</option>
<option value="Ready for Inspection">Ready for Inspection</option>
</select>
</td>
{:else if col.key === "villa_manager"}
@@ -484,31 +483,31 @@
<td class="px-4 py-2">
{row[col.key] ? "✔️ Yes" : "❌ No"}
</td>
{:else if col.key === "session_1_rate"}
{:else if col.key === "season_1_rate"}
<td class="px-4 py-2">
{row[col.key] || "N/A"}
</td>
{:else if col.key === "session_2_rate"}
{:else if col.key === "season_2_rate"}
<td class="px-4 py-2">
{row[col.key] || "N/A"}
</td>
{:else if col.key === "session_3_rate"}
{:else if col.key === "season_3_rate"}
<td class="px-4 py-2">
{row[col.key] || "N/A"}
</td>
{:else if col.key === "session_4_rate"}
{:else if col.key === "season_4_rate"}
<td class="px-4 py-2">
{row[col.key] || "N/A"}
</td>
{:else if col.key === "session_5_rate"}
{:else if col.key === "season_5_rate"}
<td class="px-4 py-2">
{row[col.key] || "N/A"}
</td>
{:else if col.key === "session_6_rate"}
{:else if col.key === "season_6_rate"}
<td class="px-4 py-2">
{row[col.key] || "N/A"}
</td>
{:else if col.key === "session_7_rate"}
{:else if col.key === "season_7_rate"}
<td class="px-4 py-2">
{row[col.key] || "N/A"}
</td>
@@ -591,8 +590,7 @@
{#if col.key === "villa_status"}
<div class="space-y-1">
<label class="block text-sm font-medium text-gray-700"
>{col.title}</label
>
>{col.title}
<select
name={col.key}
class="w-full border px-3 py-2 rounded {errorClass(
@@ -606,6 +604,7 @@
<option value="available">ACTIVE</option>
<option value="rented">INACTIVE</option>
</select>
</label>
</div>
{#if $formErrors.villa_status}
<p class="text-red-500 text-xs">