perbaikan fixing insert issue

This commit is contained in:
AJISETIAJI
2025-06-04 23:49:45 +07:00
parent 77c50cb12c
commit 9f7556b11d
2 changed files with 51 additions and 14 deletions

View File

@@ -113,7 +113,13 @@
name: string;
};
type User = {
id: string;
full_name: string;
};
let dataVilla: Villa[] = [];
let dataUser: User[] = [];
onMount(async () => {
const { data, error } = await supabase
@@ -125,6 +131,15 @@
} else if (data) {
dataVilla = data;
}
const { data: userData, error: userError } = await supabase
.from("users")
.select("id, full_name");
if (userError) {
console.error("Error fetching users:", userError);
} else if (userData) {
dataUser = userData;
}
});
type Issue = {
@@ -350,7 +365,7 @@
} else {
const issueInsert: issueInsert = {
name: formData.get("name") as string,
villa_id: formData.get("villa_id") as string,
villa_id: formData.get("villa_name") as string,
area_of_villa: formData.get("area_of_villa") as string,
priority: formData.get("priority") as string,
issue_type: formData.get("issue_type") as string,
@@ -913,9 +928,9 @@
<option value="" disabled selected
>Select Reporter</option
>
{#each reportedBy as reporter}
<option value={reporter.value}
>{reporter.label}</option
{#each dataUser as reporter}
<option value={reporter.id}
>{reporter.full_name}</option
>
{/each}
</select>
@@ -940,9 +955,9 @@
<option value="" disabled selected
>Select Input By</option
>
{#each inputBy as input}
<option value={input.value}
>{input.label}</option
{#each dataUser as input}
<option value={input.id}
>{input.full_name}</option
>
{/each}
</select>
@@ -1033,9 +1048,9 @@
>Villa Name</label
>
<select
name="villa_id"
name="villa_name"
class="w-full border px-3 py-2 rounded {errorClass(
'villa_id',
'villa_name',
)}"
bind:value={newIssue[col.key as keyof Issue]}
>
@@ -1046,9 +1061,9 @@
<option value={villa.id}>{villa.name}</option>
{/each}
</select>
{#if $formErrors.villa_id}
{#if $formErrors.villa_name}
<p class="text-red-500 text-xs">
{$formErrors.villa_id}
{$formErrors.villa_name}
</p>
{/if}
</div>