perbaikan data issue updated by
This commit is contained in:
@@ -110,7 +110,7 @@
|
||||
|
||||
type Villa = {
|
||||
id: string;
|
||||
name: string;
|
||||
villa_name: string;
|
||||
};
|
||||
|
||||
type User = {
|
||||
@@ -123,8 +123,8 @@
|
||||
|
||||
onMount(async () => {
|
||||
const { data, error } = await supabase
|
||||
.from("villas")
|
||||
.select("id, name");
|
||||
.from("vb_villas")
|
||||
.select("id, villa_name");
|
||||
|
||||
if (error) {
|
||||
console.error("Error fetching villas:", error);
|
||||
@@ -164,7 +164,8 @@
|
||||
follow_up: boolean;
|
||||
need_approval: boolean;
|
||||
created_at: string;
|
||||
// Optional field to hold the name of the villa
|
||||
updated_by?: string;
|
||||
updated_at?: string;
|
||||
};
|
||||
|
||||
type issueInsert = {
|
||||
@@ -200,6 +201,10 @@
|
||||
const columns: columns[] = [
|
||||
{ key: "name", title: "Name" },
|
||||
{ key: "villa_name", title: "Villa Name" },
|
||||
{ key: "villa_id", title: "Villa ID" },
|
||||
{ key: "input_by", title: "Input By" },
|
||||
{ key: "reported_by", title: "Reported By" },
|
||||
{ key: "reported_date", title: "Reported Date" },
|
||||
{ key: "area_of_villa", title: "Area Of Villa" },
|
||||
{ key: "priority", title: "Priority" },
|
||||
{ key: "issue_type", title: "Issue Type" },
|
||||
@@ -209,8 +214,8 @@
|
||||
{ key: "reported_date", title: "Reported Date" },
|
||||
{ key: "issue_related_image", title: "Issue Related Image" },
|
||||
{ key: "issue_source", title: "Issue Source" },
|
||||
{ key: "reported_by", title: "Reported By" },
|
||||
{ key: "input_by", title: "Input By" },
|
||||
{ key: "reported_name", title: "Reported By" },
|
||||
{ key: "inputed_name", title: "Input By" },
|
||||
{ key: "guest_communication", title: "Guest Communication" },
|
||||
{ key: "resolution", title: "Resolution" },
|
||||
{
|
||||
@@ -220,6 +225,8 @@
|
||||
{ key: "follow_up", title: "Follow Up" },
|
||||
{ key: "need_approval", title: "Need Approval" },
|
||||
{ key: "created_at", title: "Created At" },
|
||||
{ key: "updated_name", title: "Updated By" },
|
||||
{ key: "updated_at", title: "Updated At" },
|
||||
{ key: "actions", title: "Actions" },
|
||||
];
|
||||
|
||||
@@ -232,7 +239,7 @@
|
||||
limit: number = 10,
|
||||
) {
|
||||
let query = supabase
|
||||
.from("vb_issues")
|
||||
.from("vb_issues_data")
|
||||
.select("*", { count: "exact" })
|
||||
.order(sort || "created_at", { ascending: order === "asc" })
|
||||
.range(offset, offset + limit - 1);
|
||||
@@ -260,25 +267,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Ambil semua villa_id unik dari issues
|
||||
const villaIds = [...new Set(issues.map((i: Issue) => i.villa_id))];
|
||||
|
||||
const { data: villas, error: villaError } = await supabase
|
||||
.from("vb_villas")
|
||||
.select("*")
|
||||
.in("id", villaIds);
|
||||
|
||||
if (villaError) {
|
||||
console.error("Error fetching villas:", villaError);
|
||||
return;
|
||||
}
|
||||
|
||||
// Gabungkan data villa ke dalam setiap issue
|
||||
allRows = issues.map((issue: Issue) => ({
|
||||
...issue,
|
||||
villa_name:
|
||||
villas.find((v) => v.id === issue.villa_id).name || null,
|
||||
}));
|
||||
allRows = issues;
|
||||
}
|
||||
|
||||
let currentPage = offset + 1;
|
||||
@@ -303,11 +293,28 @@
|
||||
"move_issue",
|
||||
"issue_number",
|
||||
"actions",
|
||||
"villa_name",
|
||||
"reported_name",
|
||||
"inputed_name",
|
||||
"updated_name",
|
||||
"updated_at",
|
||||
"updated_by",
|
||||
];
|
||||
|
||||
const excludedKeysDisplay = [
|
||||
"villa_id",
|
||||
"reported_by",
|
||||
"input_by",
|
||||
"updated_by",
|
||||
];
|
||||
const formColumns = columns.filter(
|
||||
(col) => !excludedKeys.includes(col.key),
|
||||
);
|
||||
|
||||
const formColumnsDisplay = columns.filter(
|
||||
(col) => !excludedKeysDisplay.includes(col.key),
|
||||
);
|
||||
|
||||
function openModal(issue?: Record<string, any>) {
|
||||
if (issue) {
|
||||
isEditing = true;
|
||||
@@ -352,6 +359,16 @@
|
||||
}
|
||||
|
||||
if (isEditing && currentEditingId) {
|
||||
newIssue = formColumns.reduce(
|
||||
(acc, col) => {
|
||||
if (col.key in newIssue) {
|
||||
acc[col.key] = newIssue[col.key];
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, any>,
|
||||
);
|
||||
|
||||
const { error } = await supabase
|
||||
.from("vb_issues")
|
||||
.update(newIssue)
|
||||
@@ -365,7 +382,7 @@
|
||||
} else {
|
||||
const issueInsert: issueInsert = {
|
||||
name: formData.get("name") as string,
|
||||
villa_id: formData.get("villa_name") as string,
|
||||
villa_id: formData.get("villa_id") 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,
|
||||
@@ -467,10 +484,23 @@
|
||||
|
||||
// insert id issue to project
|
||||
async function moveIssueToProject(issueId: string) {
|
||||
// get user id from session
|
||||
const session = await supabase.auth.getSession();
|
||||
if (!session) {
|
||||
console.error("User not authenticated");
|
||||
return;
|
||||
}
|
||||
|
||||
const userId = session.data.session?.user.id;
|
||||
|
||||
// update move_issue field in the issue
|
||||
const { error: updateError } = await supabase
|
||||
.from("vb_issues")
|
||||
.update({ move_issue: "PROJECT" })
|
||||
.update({
|
||||
move_issue: "PROJECT",
|
||||
updated_by: userId,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq("id", issueId);
|
||||
|
||||
if (updateError) {
|
||||
@@ -570,7 +600,7 @@
|
||||
<table class="min-w-[1000px] divide-y divide-gray-200 text-sm w-max">
|
||||
<thead class="bg-gray-100">
|
||||
<tr>
|
||||
{#each columns as col}
|
||||
{#each formColumnsDisplay as col}
|
||||
{#if col.key === "name"}
|
||||
<th
|
||||
class="sticky left-0 px-4 py-3 text-left font-semibold text-gray-700 uppercase tracking-wider whitespace-nowrap"
|
||||
@@ -591,7 +621,7 @@
|
||||
<tbody class="divide-y divide-gray-200 bg-white">
|
||||
{#each allRows as row}
|
||||
<tr class="hover:bg-gray-50 transition">
|
||||
{#each columns as col}
|
||||
{#each formColumnsDisplay as col}
|
||||
{#if col.key === "name"}
|
||||
<td
|
||||
class="sticky left-0 px-4 py-2 font-medium text-blue-600"
|
||||
@@ -1048,9 +1078,9 @@
|
||||
>Villa Name</label
|
||||
>
|
||||
<select
|
||||
name="villa_name"
|
||||
name="villa_id"
|
||||
class="w-full border px-3 py-2 rounded {errorClass(
|
||||
'villa_name',
|
||||
'villa_id',
|
||||
)}"
|
||||
bind:value={newIssue[col.key as keyof Issue]}
|
||||
>
|
||||
@@ -1058,12 +1088,14 @@
|
||||
>Select Villa</option
|
||||
>
|
||||
{#each dataVilla as villa}
|
||||
<option value={villa.id}>{villa.name}</option>
|
||||
<option value={villa.id}
|
||||
>{villa.villa_name}</option
|
||||
>
|
||||
{/each}
|
||||
</select>
|
||||
{#if $formErrors.villa_name}
|
||||
{#if $formErrors.villa_id}
|
||||
<p class="text-red-500 text-xs">
|
||||
{$formErrors.villa_name}
|
||||
{$formErrors.villa_id}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user