perbaikan fixing insert issue
This commit is contained in:
@@ -113,7 +113,13 @@
|
|||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type User = {
|
||||||
|
id: string;
|
||||||
|
full_name: string;
|
||||||
|
};
|
||||||
|
|
||||||
let dataVilla: Villa[] = [];
|
let dataVilla: Villa[] = [];
|
||||||
|
let dataUser: User[] = [];
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
@@ -125,6 +131,15 @@
|
|||||||
} else if (data) {
|
} else if (data) {
|
||||||
dataVilla = 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 = {
|
type Issue = {
|
||||||
@@ -350,7 +365,7 @@
|
|||||||
} else {
|
} else {
|
||||||
const issueInsert: issueInsert = {
|
const issueInsert: issueInsert = {
|
||||||
name: formData.get("name") as string,
|
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,
|
area_of_villa: formData.get("area_of_villa") as string,
|
||||||
priority: formData.get("priority") as string,
|
priority: formData.get("priority") as string,
|
||||||
issue_type: formData.get("issue_type") as string,
|
issue_type: formData.get("issue_type") as string,
|
||||||
@@ -913,9 +928,9 @@
|
|||||||
<option value="" disabled selected
|
<option value="" disabled selected
|
||||||
>Select Reporter</option
|
>Select Reporter</option
|
||||||
>
|
>
|
||||||
{#each reportedBy as reporter}
|
{#each dataUser as reporter}
|
||||||
<option value={reporter.value}
|
<option value={reporter.id}
|
||||||
>{reporter.label}</option
|
>{reporter.full_name}</option
|
||||||
>
|
>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
@@ -940,9 +955,9 @@
|
|||||||
<option value="" disabled selected
|
<option value="" disabled selected
|
||||||
>Select Input By</option
|
>Select Input By</option
|
||||||
>
|
>
|
||||||
{#each inputBy as input}
|
{#each dataUser as input}
|
||||||
<option value={input.value}
|
<option value={input.id}
|
||||||
>{input.label}</option
|
>{input.full_name}</option
|
||||||
>
|
>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
@@ -1033,9 +1048,9 @@
|
|||||||
>Villa Name</label
|
>Villa Name</label
|
||||||
>
|
>
|
||||||
<select
|
<select
|
||||||
name="villa_id"
|
name="villa_name"
|
||||||
class="w-full border px-3 py-2 rounded {errorClass(
|
class="w-full border px-3 py-2 rounded {errorClass(
|
||||||
'villa_id',
|
'villa_name',
|
||||||
)}"
|
)}"
|
||||||
bind:value={newIssue[col.key as keyof Issue]}
|
bind:value={newIssue[col.key as keyof Issue]}
|
||||||
>
|
>
|
||||||
@@ -1046,9 +1061,9 @@
|
|||||||
<option value={villa.id}>{villa.name}</option>
|
<option value={villa.id}>{villa.name}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
{#if $formErrors.villa_id}
|
{#if $formErrors.villa_name}
|
||||||
<p class="text-red-500 text-xs">
|
<p class="text-red-500 text-xs">
|
||||||
{$formErrors.villa_id}
|
{$formErrors.villa_name}
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -183,6 +183,28 @@
|
|||||||
created_at: string;
|
created_at: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type issueInsert = {
|
||||||
|
name: string;
|
||||||
|
villa_id: string;
|
||||||
|
area_of_villa: string;
|
||||||
|
priority: string;
|
||||||
|
issue_type: string;
|
||||||
|
issue_number: string;
|
||||||
|
move_issue: boolean;
|
||||||
|
description_of_the_issue: string;
|
||||||
|
reported_date: string;
|
||||||
|
issue_related_image: string;
|
||||||
|
issue_source: string;
|
||||||
|
reported_by: string;
|
||||||
|
input_by: string;
|
||||||
|
guest_communication: string;
|
||||||
|
resolution: string;
|
||||||
|
guest_has_aggreed_issue_has_been_resolved: boolean;
|
||||||
|
follow_up: boolean;
|
||||||
|
need_approval: boolean;
|
||||||
|
created_at: string;
|
||||||
|
};
|
||||||
|
|
||||||
async function handleSubmit(event: Event): Promise<void> {
|
async function handleSubmit(event: Event): Promise<void> {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
@@ -198,7 +220,7 @@
|
|||||||
if (issueImageFile) {
|
if (issueImageFile) {
|
||||||
const { data, error } = await supabase.storage
|
const { data, error } = await supabase.storage
|
||||||
.from("villabugis")
|
.from("villabugis")
|
||||||
.upload(`issue/${issueImageFile.name}`, issueImageFile);
|
.upload(`issues/${issueImageFile.name}`, issueImageFile);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("Error uploading image:", error);
|
console.error("Error uploading image:", error);
|
||||||
@@ -208,9 +230,9 @@
|
|||||||
issueImageUrl = data.path; // Assuming data.Key contains the URL or path to the uploaded image
|
issueImageUrl = data.path; // Assuming data.Key contains the URL or path to the uploaded image
|
||||||
}
|
}
|
||||||
|
|
||||||
const issue: Issue = {
|
const issue: issueInsert = {
|
||||||
name: formData.get("name") as string,
|
name: formData.get("name") as string,
|
||||||
villa_name: formData.get("villa_name") as string,
|
villa_id: formData.get("villa_name") as string,
|
||||||
area_of_villa: formData.get("area_of_villa") as string,
|
area_of_villa: formData.get("area_of_villa") as string,
|
||||||
priority: formData.get("priority") as string,
|
priority: formData.get("priority") as string,
|
||||||
issue_type: formData.get("issue_type") as string,
|
issue_type: formData.get("issue_type") as string,
|
||||||
|
|||||||
Reference in New Issue
Block a user