refactor: enhance Kanban component to support drag-and-drop positional updates with optimistic UI and rollback capabilities
This commit is contained in:
parent
ce0801ff87
commit
c0d5f5892f
9 changed files with 926 additions and 796 deletions
|
|
@ -33,7 +33,7 @@
|
|||
* loading?: boolean,
|
||||
* itemName?: string,
|
||||
* itemNamePlural?: string,
|
||||
* onItemMove: (itemId: string, newStatus: string, columnId: string) => Promise<void>,
|
||||
* onItemMove: (itemId: string, newStatus: string, columnId: string, aboveId: string | null, belowId: string | null) => Promise<void>,
|
||||
* onCardClick: (item: any) => void,
|
||||
* CardComponent: any,
|
||||
* emptyMessage?: string,
|
||||
|
|
@ -139,52 +139,72 @@
|
|||
/**
|
||||
* @param {DragEvent} e
|
||||
* @param {string} targetColumnId
|
||||
* @param {{ aboveId: string | null, belowId: string | null }} neighbors
|
||||
*/
|
||||
async function handleDrop(e, targetColumnId) {
|
||||
async function handleDrop(e, targetColumnId, neighbors) {
|
||||
e.preventDefault();
|
||||
dragOverColumn = null;
|
||||
|
||||
if (!draggedItem || dragSourceColumn === targetColumnId) {
|
||||
draggedItem = null;
|
||||
if (!draggedItem) {
|
||||
dragSourceColumn = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const item = draggedItem;
|
||||
const sourceColumnId = dragSourceColumn;
|
||||
const { aboveId, belowId } = neighbors;
|
||||
|
||||
draggedItem = null;
|
||||
dragSourceColumn = null;
|
||||
|
||||
const sourceCol = localColumns.find((c) => c.id === sourceColumnId);
|
||||
const targetCol = localColumns.find((c) => c.id === targetColumnId);
|
||||
if (!sourceCol || !targetCol) return;
|
||||
|
||||
if (sourceCol && targetCol) {
|
||||
const itemIndex = sourceCol.items.findIndex((i) => i.id === item.id);
|
||||
if (itemIndex !== -1) {
|
||||
sourceCol.items.splice(itemIndex, 1);
|
||||
sourceCol.item_count--;
|
||||
}
|
||||
targetCol.items.unshift({ ...item, status: targetColumnId });
|
||||
targetCol.item_count++;
|
||||
localColumns = [...localColumns];
|
||||
// Snapshot for rollback
|
||||
const sourceItemsBefore = [...sourceCol.items];
|
||||
const targetItemsBefore = [...targetCol.items];
|
||||
const sourceCountBefore = sourceCol.item_count;
|
||||
const targetCountBefore = targetCol.item_count;
|
||||
|
||||
// Detect no-op: same column AND the dropped position equals current position
|
||||
if (sourceColumnId === targetColumnId) {
|
||||
const currentIdx = sourceCol.items.findIndex((i) => i.id === item.id);
|
||||
const currentAbove = sourceCol.items[currentIdx - 1]?.id ?? null;
|
||||
const currentBelow = sourceCol.items[currentIdx + 1]?.id ?? null;
|
||||
if (aboveId === currentAbove && belowId === currentBelow) return;
|
||||
}
|
||||
|
||||
// Optimistic update: remove from source, insert at resolved position in target
|
||||
const srcIdx = sourceCol.items.findIndex((i) => i.id === item.id);
|
||||
if (srcIdx !== -1) {
|
||||
sourceCol.items.splice(srcIdx, 1);
|
||||
sourceCol.item_count--;
|
||||
}
|
||||
let insertIdx;
|
||||
if (belowId) {
|
||||
insertIdx = targetCol.items.findIndex((i) => i.id === belowId);
|
||||
if (insertIdx === -1) insertIdx = targetCol.items.length;
|
||||
} else if (aboveId) {
|
||||
const aboveIdx = targetCol.items.findIndex((i) => i.id === aboveId);
|
||||
insertIdx = aboveIdx === -1 ? targetCol.items.length : aboveIdx + 1;
|
||||
} else {
|
||||
insertIdx = targetCol.items.length;
|
||||
}
|
||||
targetCol.items.splice(insertIdx, 0, { ...item, status: targetColumnId });
|
||||
targetCol.item_count++;
|
||||
localColumns = [...localColumns];
|
||||
|
||||
try {
|
||||
await onItemMove(item.id, targetColumnId, targetColumnId);
|
||||
await onItemMove(item.id, targetColumnId, targetColumnId, aboveId, belowId);
|
||||
} catch (error) {
|
||||
console.error(`Failed to move ${itemName}:`, error);
|
||||
toast.error(`Failed to move ${itemName}`);
|
||||
if (sourceCol && targetCol) {
|
||||
const itemIndex = targetCol.items.findIndex((i) => i.id === item.id);
|
||||
if (itemIndex !== -1) {
|
||||
targetCol.items.splice(itemIndex, 1);
|
||||
targetCol.item_count--;
|
||||
}
|
||||
sourceCol.items.unshift(item);
|
||||
sourceCol.item_count++;
|
||||
localColumns = [...localColumns];
|
||||
}
|
||||
sourceCol.items = sourceItemsBefore;
|
||||
targetCol.items = targetItemsBefore;
|
||||
sourceCol.item_count = sourceCountBefore;
|
||||
targetCol.item_count = targetCountBefore;
|
||||
localColumns = [...localColumns];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -229,8 +249,12 @@
|
|||
<div class="mt-2 flex items-center justify-between">
|
||||
<div class="skeleton h-3 w-12 rounded"></div>
|
||||
<div class="flex -space-x-1.5">
|
||||
<div class="skeleton h-6 w-6 rounded-full ring-2 ring-white dark:ring-[#262626]"></div>
|
||||
<div class="skeleton h-6 w-6 rounded-full ring-2 ring-white dark:ring-[#262626]"></div>
|
||||
<div
|
||||
class="skeleton h-6 w-6 rounded-full ring-2 ring-white dark:ring-[#262626]"
|
||||
></div>
|
||||
<div
|
||||
class="skeleton h-6 w-6 rounded-full ring-2 ring-white dark:ring-[#262626]"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -263,7 +287,9 @@
|
|||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<TrendingUp class="h-4 w-4 text-emerald-600 dark:text-emerald-400" />
|
||||
<span class="text-[11px] font-medium uppercase tracking-wider text-gray-500 dark:text-gray-400">
|
||||
<span
|
||||
class="text-[11px] font-medium uppercase tracking-wider text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
Pipeline
|
||||
</span>
|
||||
<span class="text-sm font-semibold text-gray-800 dark:text-white">
|
||||
|
|
@ -275,7 +301,9 @@
|
|||
|
||||
<div class="flex items-center gap-2">
|
||||
<Flame class="h-4 w-4 text-rose-500 dark:text-rose-400" />
|
||||
<span class="text-[11px] font-medium uppercase tracking-wider text-gray-500 dark:text-gray-400">
|
||||
<span
|
||||
class="text-[11px] font-medium uppercase tracking-wider text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
Hot
|
||||
</span>
|
||||
<span class="text-sm font-semibold text-gray-800 dark:text-white">
|
||||
|
|
@ -287,7 +315,9 @@
|
|||
|
||||
<div class="flex items-center gap-2">
|
||||
<Users class="h-4 w-4 text-gray-500 dark:text-gray-400" />
|
||||
<span class="text-[11px] font-medium uppercase tracking-wider text-gray-500 dark:text-gray-400">
|
||||
<span
|
||||
class="text-[11px] font-medium uppercase tracking-wider text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
Total {itemNamePlural}
|
||||
</span>
|
||||
<span class="text-sm font-semibold text-gray-800 dark:text-white">
|
||||
|
|
@ -305,9 +335,10 @@
|
|||
{itemName}
|
||||
{CardComponent}
|
||||
isDragOver={dragOverColumn === column.id}
|
||||
draggedItemId={draggedItem?.id ?? null}
|
||||
onDragOver={(e) => handleDragOver(e, column.id)}
|
||||
onDragLeave={handleDragLeave}
|
||||
onDrop={(e) => handleDrop(e, column.id)}
|
||||
onDrop={(e, neighbors) => handleDrop(e, column.id, neighbors)}
|
||||
{onCardClick}
|
||||
onCardDragStart={(e, item) => handleDragStart(e, item, column.id)}
|
||||
onCardDragEnd={handleDragEnd}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,11 @@
|
|||
* column: Column,
|
||||
* itemName?: string,
|
||||
* isDragOver: boolean,
|
||||
* draggedItemId?: string | null,
|
||||
* CardComponent?: any,
|
||||
* onDragOver: (e: DragEvent) => void,
|
||||
* onDragLeave: () => void,
|
||||
* onDrop: (e: DragEvent) => void,
|
||||
* onDrop: (e: DragEvent, neighbors: { aboveId: string | null, belowId: string | null }) => void,
|
||||
* onCardClick: (item: any) => void,
|
||||
* onCardDragStart: (e: DragEvent, item: any) => void,
|
||||
* onCardDragEnd: () => void,
|
||||
|
|
@ -32,6 +33,7 @@
|
|||
column,
|
||||
itemName = 'item',
|
||||
isDragOver,
|
||||
draggedItemId = null,
|
||||
CardComponent = null,
|
||||
onDragOver,
|
||||
onDragLeave,
|
||||
|
|
@ -42,6 +44,61 @@
|
|||
onAddItem
|
||||
} = $props();
|
||||
|
||||
/** @type {HTMLDivElement | undefined} */
|
||||
let cardsEl;
|
||||
// Render-index where the dragged card would insert. null = unknown / column empty.
|
||||
let dropRenderIdx = $state(/** @type {number | null} */ (null));
|
||||
|
||||
/** @param {number} clientY */
|
||||
function computeDropRenderIdx(clientY) {
|
||||
if (!cardsEl) return 0;
|
||||
const els = /** @type {HTMLElement[]} */ (
|
||||
Array.from(cardsEl.querySelectorAll('[data-card-id]'))
|
||||
);
|
||||
if (els.length === 0) return 0;
|
||||
for (let i = 0; i < els.length; i++) {
|
||||
const rect = els[i].getBoundingClientRect();
|
||||
const mid = rect.top + rect.height / 2;
|
||||
if (clientY < mid) return i;
|
||||
}
|
||||
return els.length;
|
||||
}
|
||||
|
||||
const draggedIdxInColumn = $derived(
|
||||
draggedItemId ? column.items.findIndex((it) => it.id === draggedItemId) : -1
|
||||
);
|
||||
|
||||
/** @param {number} renderIdx */
|
||||
function showIndicatorAt(renderIdx) {
|
||||
if (!isDragOver || dropRenderIdx !== renderIdx) return false;
|
||||
if (draggedIdxInColumn !== -1) {
|
||||
// No-op slots: current position or immediately below the dragged card
|
||||
if (renderIdx === draggedIdxInColumn || renderIdx === draggedIdxInColumn + 1) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @param {number} renderIdx */
|
||||
function resolveNeighbors(renderIdx) {
|
||||
/** @type {string | null} */
|
||||
let aboveId = null;
|
||||
/** @type {string | null} */
|
||||
let belowId = null;
|
||||
for (let i = renderIdx - 1; i >= 0; i--) {
|
||||
if (column.items[i].id !== draggedItemId) {
|
||||
aboveId = column.items[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (let i = renderIdx; i < column.items.length; i++) {
|
||||
if (column.items[i].id !== draggedItemId) {
|
||||
belowId = column.items[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return { aboveId, belowId };
|
||||
}
|
||||
|
||||
// WIP limit check
|
||||
const isAtWipLimit = $derived(
|
||||
column.wip_limit !== null &&
|
||||
|
|
@ -73,8 +130,21 @@
|
|||
function handleDragOver(e) {
|
||||
e.preventDefault();
|
||||
e.dataTransfer.dropEffect = 'move';
|
||||
dropRenderIdx = computeDropRenderIdx(e.clientY);
|
||||
onDragOver(e);
|
||||
}
|
||||
|
||||
function handleColumnDragLeave() {
|
||||
dropRenderIdx = null;
|
||||
onDragLeave();
|
||||
}
|
||||
|
||||
/** @param {DragEvent} e */
|
||||
function handleColumnDrop(e) {
|
||||
const idx = computeDropRenderIdx(e.clientY);
|
||||
dropRenderIdx = null;
|
||||
onDrop(e, resolveNeighbors(idx));
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
|
@ -82,8 +152,8 @@
|
|||
class:kanban-drag-over={isDragOver}
|
||||
class:wip-exceeded={isAtWipLimit}
|
||||
ondragover={handleDragOver}
|
||||
ondragleave={onDragLeave}
|
||||
ondrop={onDrop}
|
||||
ondragleave={handleColumnDragLeave}
|
||||
ondrop={handleColumnDrop}
|
||||
role="region"
|
||||
aria-label="{column.name} column with {itemCount} {itemCount !== 1 ? 'items' : itemName}"
|
||||
>
|
||||
|
|
@ -124,32 +194,40 @@
|
|||
</div>
|
||||
|
||||
<!-- Cards -->
|
||||
<div class="kanban-cards min-h-0 flex-1 space-y-2 overflow-y-auto px-2 pb-1">
|
||||
{#each column.items as item (item.id)}
|
||||
{#if CardComponent}
|
||||
<CardComponent
|
||||
{item}
|
||||
onclick={() => onCardClick(item)}
|
||||
ondragstart={(e) => onCardDragStart(e, item)}
|
||||
ondragend={onCardDragEnd}
|
||||
/>
|
||||
{:else}
|
||||
<div
|
||||
class="cursor-pointer rounded-lg border border-black/[0.04] bg-white p-2.5 text-sm shadow-[0_1px_0_rgba(9,30,66,0.12)] hover:border-black/10 dark:border-white/[0.06] dark:bg-white/[0.05]"
|
||||
draggable="true"
|
||||
onclick={() => onCardClick(item)}
|
||||
onkeydown={(e) => (e.key === 'Enter' || e.key === ' ') && onCardClick(item)}
|
||||
ondragstart={(e) => onCardDragStart(e, item)}
|
||||
ondragend={onCardDragEnd}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<div class="font-medium text-gray-900 dark:text-gray-100">
|
||||
{item.title || item.name || 'Untitled'}
|
||||
</div>
|
||||
</div>
|
||||
<div bind:this={cardsEl} class="kanban-cards min-h-0 flex-1 space-y-2 overflow-y-auto px-2 pb-1">
|
||||
{#each column.items as item, i (item.id)}
|
||||
{#if showIndicatorAt(i)}
|
||||
<div class="drop-indicator" aria-hidden="true"></div>
|
||||
{/if}
|
||||
<div data-card-id={item.id}>
|
||||
{#if CardComponent}
|
||||
<CardComponent
|
||||
{item}
|
||||
onclick={() => onCardClick(item)}
|
||||
ondragstart={(e) => onCardDragStart(e, item)}
|
||||
ondragend={onCardDragEnd}
|
||||
/>
|
||||
{:else}
|
||||
<div
|
||||
class="cursor-pointer rounded-lg border border-black/[0.04] bg-white p-2.5 text-sm shadow-[0_1px_0_rgba(9,30,66,0.12)] hover:border-black/10 dark:border-white/[0.06] dark:bg-white/[0.05]"
|
||||
draggable="true"
|
||||
onclick={() => onCardClick(item)}
|
||||
onkeydown={(e) => (e.key === 'Enter' || e.key === ' ') && onCardClick(item)}
|
||||
ondragstart={(e) => onCardDragStart(e, item)}
|
||||
ondragend={onCardDragEnd}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<div class="font-medium text-gray-900 dark:text-gray-100">
|
||||
{item.title || item.name || 'Untitled'}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
{#if showIndicatorAt(column.items.length)}
|
||||
<div class="drop-indicator" aria-hidden="true"></div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Footer: Add a card -->
|
||||
|
|
@ -180,6 +258,13 @@
|
|||
box-shadow: inset 0 0 0 1px rgba(251, 113, 133, 0.4);
|
||||
}
|
||||
|
||||
.drop-indicator {
|
||||
height: 3px;
|
||||
border-radius: 2px;
|
||||
background: rgb(34 211 238);
|
||||
margin: 2px 0;
|
||||
}
|
||||
|
||||
.kanban-cards::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
* @type {{
|
||||
* data: KanbanData | null,
|
||||
* loading?: boolean,
|
||||
* onStatusChange: (leadId: string, newStatus: string, columnId: string) => Promise<void>,
|
||||
* onStatusChange: (leadId: string, newStatus: string, columnId: string, aboveId: string | null, belowId: string | null) => Promise<void>,
|
||||
* onCardClick: (lead: any) => void
|
||||
* }}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
* @type {{
|
||||
* data: KanbanData | null,
|
||||
* loading?: boolean,
|
||||
* onStatusChange: (taskId: string, newStatus: string, columnId: string) => Promise<void>,
|
||||
* onStatusChange: (taskId: string, newStatus: string, columnId: string, aboveId: string | null, belowId: string | null) => Promise<void>,
|
||||
* onCardClick: (task: any) => void,
|
||||
* onAddItem?: (columnId: string) => void
|
||||
* }}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
* @type {{
|
||||
* data: KanbanData | null,
|
||||
* loading?: boolean,
|
||||
* onStatusChange: (ticketId: string, newStatus: string, columnId: string) => Promise<void>,
|
||||
* onStatusChange: (ticketId: string, newStatus: string, columnId: string, aboveId: string | null, belowId: string | null) => Promise<void>,
|
||||
* onCardClick: (ticketItem: any) => void
|
||||
* }}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -656,6 +656,8 @@ export const actions = {
|
|||
const statusRaw =
|
||||
form.get('status')?.toString().trim().toLowerCase().replace(/_/g, ' ') || '';
|
||||
const status = validStatuses.includes(statusRaw) ? statusRaw : null;
|
||||
const aboveLeadId = form.get('aboveLeadId')?.toString() || null;
|
||||
const belowLeadId = form.get('belowLeadId')?.toString() || null;
|
||||
|
||||
if (!leadId) {
|
||||
return fail(400, { error: 'Lead ID is required.' });
|
||||
|
|
@ -665,11 +667,16 @@ export const actions = {
|
|||
return fail(400, { error: 'Valid status is required.' });
|
||||
}
|
||||
|
||||
/** @type {Record<string, string>} */
|
||||
const moveData = { status };
|
||||
if (aboveLeadId) moveData.above_lead_id = aboveLeadId;
|
||||
if (belowLeadId) moveData.below_lead_id = belowLeadId;
|
||||
|
||||
await apiRequest(
|
||||
`/leads/${leadId}/move/`,
|
||||
{
|
||||
method: 'PATCH',
|
||||
body: { status }
|
||||
body: moveData
|
||||
},
|
||||
{ cookies, org: locals.org }
|
||||
);
|
||||
|
|
|
|||
|
|
@ -31,19 +31,19 @@
|
|||
} from '@lucide/svelte';
|
||||
import { LinkedinIcon as Linkedin } from '$lib/components/icons';
|
||||
import { page } from '$app/stores';
|
||||
import {
|
||||
SearchInput,
|
||||
SelectFilter,
|
||||
DateRangeFilter,
|
||||
TagFilter
|
||||
} from '$lib/components/ui/filter';
|
||||
import { SearchInput, SelectFilter, DateRangeFilter, TagFilter } from '$lib/components/ui/filter';
|
||||
import { Pagination } from '$lib/components/ui/pagination';
|
||||
import { Button } from '$lib/components/ui/button/index.js';
|
||||
import { PageHeader, FilterStrip, ViewTabs, FilterPill } from '$lib/components/layout';
|
||||
import { INDUSTRIES, COUNTRIES } from '$lib/constants/lead-choices.js';
|
||||
import { CURRENCY_CODES } from '$lib/constants/filters.js';
|
||||
import * as DropdownMenu from '$lib/components/ui/dropdown-menu/index.js';
|
||||
import { formatRelativeDate, formatDate, getNameInitials, getInitials } from '$lib/utils/formatting.js';
|
||||
import {
|
||||
formatRelativeDate,
|
||||
formatDate,
|
||||
getNameInitials,
|
||||
getInitials
|
||||
} from '$lib/utils/formatting.js';
|
||||
import {
|
||||
leadStatusOptions,
|
||||
leadRatingOptions,
|
||||
|
|
@ -642,10 +642,7 @@
|
|||
const initialAction = initialUrlParams.get('action');
|
||||
const initialLead = initialViewId
|
||||
? untrack(
|
||||
() =>
|
||||
(data.leads || []).find(
|
||||
(/** @type {any} */ l) => l.id === initialViewId
|
||||
) || null
|
||||
() => (data.leads || []).find((/** @type {any} */ l) => l.id === initialViewId) || null
|
||||
)
|
||||
: null;
|
||||
|
||||
|
|
@ -974,8 +971,10 @@
|
|||
* @param {string} leadId
|
||||
* @param {string} newStatus
|
||||
* @param {string} _columnId
|
||||
* @param {string | null} aboveLeadId
|
||||
* @param {string | null} belowLeadId
|
||||
*/
|
||||
async function handleKanbanStatusChange(leadId, newStatus, _columnId) {
|
||||
async function handleKanbanStatusChange(leadId, newStatus, _columnId, aboveLeadId, belowLeadId) {
|
||||
// Convert column ID (status) to proper format
|
||||
// Column IDs are: "assigned", "in process", "recycled", "closed"
|
||||
const status = newStatus;
|
||||
|
|
@ -983,6 +982,8 @@
|
|||
// Populate form and submit
|
||||
kanbanFormState.leadId = leadId;
|
||||
kanbanFormState.status = status;
|
||||
kanbanFormState.aboveLeadId = aboveLeadId || '';
|
||||
kanbanFormState.belowLeadId = belowLeadId || '';
|
||||
|
||||
await tick();
|
||||
updateStatusForm.requestSubmit();
|
||||
|
|
@ -1255,7 +1256,9 @@
|
|||
// Kanban form state (for drag-drop status updates)
|
||||
let kanbanFormState = $state({
|
||||
leadId: '',
|
||||
status: ''
|
||||
status: '',
|
||||
aboveLeadId: '',
|
||||
belowLeadId: ''
|
||||
});
|
||||
// Form data state
|
||||
let formState = $state({
|
||||
|
|
@ -1496,286 +1499,282 @@
|
|||
class:overflow-hidden={viewMode === 'kanban'}
|
||||
>
|
||||
<PageHeader
|
||||
title="Leads"
|
||||
subtitle="{viewMode === 'kanban'
|
||||
? totalLeadCount
|
||||
: filteredLeads.length} of {totalLeadCount} leads"
|
||||
>
|
||||
{#snippet actions()}
|
||||
<div class="flex items-center gap-2">
|
||||
<!-- View Toggle -->
|
||||
<ViewToggle view={viewMode} onchange={setViewMode} />
|
||||
title="Leads"
|
||||
subtitle="{viewMode === 'kanban'
|
||||
? totalLeadCount
|
||||
: filteredLeads.length} of {totalLeadCount} leads"
|
||||
>
|
||||
{#snippet actions()}
|
||||
<div class="flex items-center gap-2">
|
||||
<!-- View Toggle -->
|
||||
<ViewToggle view={viewMode} onchange={setViewMode} />
|
||||
|
||||
<div class="mx-1 h-6 w-px bg-[var(--border-default)]"></div>
|
||||
<div class="mx-1 h-6 w-px bg-[var(--border-default)]"></div>
|
||||
|
||||
<!-- Status Filter Chips - Using design system tokens -->
|
||||
<div class="flex gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'ALL')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'ALL'
|
||||
? 'bg-[var(--text-primary)] text-[var(--surface-default)]'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
All
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'ALL'
|
||||
? 'bg-[var(--text-secondary)] text-[var(--surface-default)]'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
>
|
||||
{totalLeadCount}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'open')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'open'
|
||||
? 'bg-[var(--color-primary-default)] text-white'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
Open
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'open'
|
||||
? 'bg-[var(--color-primary-hover)] text-white/90'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
>
|
||||
{openCount}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'lost')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'lost'
|
||||
? 'bg-[var(--stage-lost)] text-white'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
Lost
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'lost'
|
||||
? 'bg-[var(--stage-lost)]/80 text-white/90'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
>
|
||||
{lostCount}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="mx-1 h-6 w-px bg-[var(--border-default)]"></div>
|
||||
|
||||
<!-- Column Visibility (only for table view) -->
|
||||
{#if viewMode === 'table'}
|
||||
<DropdownMenu.Root>
|
||||
<DropdownMenu.Trigger asChild>
|
||||
{#snippet child({ props })}
|
||||
<Button {...props} variant="outline" size="sm" class="gap-2">
|
||||
<Eye class="h-4 w-4" />
|
||||
Columns
|
||||
{#if visibleColumns.length < columns.length}
|
||||
<span
|
||||
class="rounded-full bg-[var(--color-primary-light)] px-1.5 py-0.5 text-xs font-medium text-[var(--color-primary-default)] dark:bg-[var(--color-primary-default)]/15"
|
||||
>
|
||||
{visibleColumns.length}/{columns.length}
|
||||
</span>
|
||||
{/if}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</DropdownMenu.Trigger>
|
||||
<DropdownMenu.Content align="end" class="w-48">
|
||||
<DropdownMenu.Label>Toggle columns</DropdownMenu.Label>
|
||||
<DropdownMenu.Separator />
|
||||
{#each columns as column (column.key)}
|
||||
<DropdownMenu.CheckboxItem
|
||||
class=""
|
||||
checked={visibleColumns.includes(column.key)}
|
||||
disabled={column.canHide === false}
|
||||
onCheckedChange={() => toggleColumn(column.key)}
|
||||
>
|
||||
{column.label}
|
||||
</DropdownMenu.CheckboxItem>
|
||||
{/each}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu.Root>
|
||||
{/if}
|
||||
|
||||
<Button onclick={openCreate}>
|
||||
<Plus class="mr-2 h-4 w-4" />
|
||||
New Lead
|
||||
</Button>
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet tabs()}
|
||||
<ViewTabs views={[{ id: 'all', label: 'All', count: totalLeadCount }]} active="all" />
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
<div
|
||||
class="flex flex-1 flex-col"
|
||||
class:min-h-0={viewMode === 'kanban'}
|
||||
>
|
||||
<FilterStrip>
|
||||
<SearchInput
|
||||
value={filters.search}
|
||||
placeholder="Search leads..."
|
||||
showLabel={false}
|
||||
onchange={(value) => updateFilters({ ...filters, search: value })}
|
||||
class="w-64"
|
||||
/>
|
||||
<SelectFilter
|
||||
label="Source"
|
||||
options={filterOptions.sources}
|
||||
value={filters.source || 'ALL'}
|
||||
onchange={(value) => updateFilters({ ...filters, source: value })}
|
||||
class="w-40"
|
||||
/>
|
||||
<SelectFilter
|
||||
label="Rating"
|
||||
options={filterOptions.ratings}
|
||||
value={filters.rating || 'ALL'}
|
||||
onchange={(value) => updateFilters({ ...filters, rating: value })}
|
||||
class="w-32"
|
||||
/>
|
||||
<DateRangeFilter
|
||||
label="Created"
|
||||
startDate={filters.created_at_gte}
|
||||
endDate={filters.created_at_lte}
|
||||
onchange={(start, end) =>
|
||||
updateFilters({ ...filters, created_at_gte: start, created_at_lte: end })}
|
||||
class="w-56"
|
||||
/>
|
||||
<TagFilter
|
||||
tags={data.tags || []}
|
||||
value={filters.tags}
|
||||
onchange={(ids) => updateFilters({ ...filters, tags: ids })}
|
||||
/>
|
||||
{#if activeFiltersCount > 0}
|
||||
<FilterPill label="Clear all" dashed onclick={clearFilters} />
|
||||
{/if}
|
||||
{#snippet meta()}
|
||||
<span>{filteredLeads.length} of {pagination.total} leads</span>
|
||||
{/snippet}
|
||||
</FilterStrip>
|
||||
|
||||
<!-- Content: Table or Kanban -->
|
||||
{#if viewMode === 'kanban'}
|
||||
<!-- Kanban View -->
|
||||
<div class="flex min-h-0 flex-1 flex-col">
|
||||
<LeadKanban
|
||||
data={kanbanData}
|
||||
loading={!kanbanData}
|
||||
onStatusChange={handleKanbanStatusChange}
|
||||
onCardClick={(lead) => openLead(lead, true)}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Table View -->
|
||||
{#if filteredLeads.length === 0}
|
||||
<div class="flex flex-col items-center justify-center py-16 text-center">
|
||||
<div
|
||||
class="mb-4 flex size-16 items-center justify-center rounded-[var(--radius-xl)] bg-[var(--surface-sunken)]"
|
||||
>
|
||||
<User class="size-8 text-[var(--text-tertiary)]" />
|
||||
</div>
|
||||
<h3 class="text-lg font-medium text-[var(--text-primary)]">No leads found</h3>
|
||||
<p class="mt-1 text-sm text-[var(--text-secondary)]">Create a new lead to get started</p>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Desktop Table using CrmTable -->
|
||||
<div class="hidden md:block">
|
||||
<CrmTable
|
||||
data={filteredLeads}
|
||||
{columns}
|
||||
bind:visibleColumns
|
||||
bind:activeRowId
|
||||
onRowChange={handleRowChange}
|
||||
onRowClick={(row) => openLead(row)}
|
||||
>
|
||||
{#snippet emptyState()}
|
||||
<div class="flex flex-col items-center justify-center py-16 text-center">
|
||||
<div
|
||||
class="mb-4 flex size-12 items-center justify-center rounded-[var(--radius-lg)] bg-[var(--surface-sunken)]"
|
||||
>
|
||||
<User class="size-6 text-[var(--text-tertiary)]" />
|
||||
</div>
|
||||
<h3 class="text-lg font-medium text-[var(--text-primary)]">No leads found</h3>
|
||||
</div>
|
||||
{/snippet}
|
||||
</CrmTable>
|
||||
</div>
|
||||
|
||||
<!-- Mobile Card View -->
|
||||
<div class="divide-y divide-[var(--border-default)]/50 md:hidden">
|
||||
{#each filteredLeads as lead (lead.id)}
|
||||
<!-- Status Filter Chips - Using design system tokens -->
|
||||
<div class="flex gap-1">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full items-start gap-3 px-4 py-3 text-left transition-colors hover:bg-[var(--color-primary-light)] dark:hover:bg-[var(--color-primary-default)]/5"
|
||||
onclick={() => openLead(lead)}
|
||||
onclick={() => (statusChipFilter = 'ALL')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'ALL'
|
||||
? 'bg-[var(--text-primary)] text-[var(--surface-default)]'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div>
|
||||
<p class="text-sm font-medium text-[var(--text-primary)]">
|
||||
{getFullName(lead)}
|
||||
</p>
|
||||
{#if lead.company}
|
||||
<p class="text-sm text-[var(--text-secondary)]">
|
||||
{typeof lead.company === 'object' ? lead.company.name : lead.company}
|
||||
</p>
|
||||
All
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'ALL'
|
||||
? 'bg-[var(--text-secondary)] text-[var(--surface-default)]'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
>
|
||||
{totalLeadCount}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'open')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'open'
|
||||
? 'bg-[var(--color-primary-default)] text-white'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
Open
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'open'
|
||||
? 'bg-[var(--color-primary-hover)] text-white/90'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
>
|
||||
{openCount}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'lost')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'lost'
|
||||
? 'bg-[var(--stage-lost)] text-white'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
Lost
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'lost'
|
||||
? 'bg-[var(--stage-lost)]/80 text-white/90'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
>
|
||||
{lostCount}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="mx-1 h-6 w-px bg-[var(--border-default)]"></div>
|
||||
|
||||
<!-- Column Visibility (only for table view) -->
|
||||
{#if viewMode === 'table'}
|
||||
<DropdownMenu.Root>
|
||||
<DropdownMenu.Trigger asChild>
|
||||
{#snippet child({ props })}
|
||||
<Button {...props} variant="outline" size="sm" class="gap-2">
|
||||
<Eye class="h-4 w-4" />
|
||||
Columns
|
||||
{#if visibleColumns.length < columns.length}
|
||||
<span
|
||||
class="rounded-full bg-[var(--color-primary-light)] px-1.5 py-0.5 text-xs font-medium text-[var(--color-primary-default)] dark:bg-[var(--color-primary-default)]/15"
|
||||
>
|
||||
{visibleColumns.length}/{columns.length}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
<span
|
||||
class="shrink-0 rounded-full px-2 py-0.5 text-xs font-medium {getOptionStyle(
|
||||
lead.status,
|
||||
leadStatusOptions
|
||||
)}"
|
||||
</Button>
|
||||
{/snippet}
|
||||
</DropdownMenu.Trigger>
|
||||
<DropdownMenu.Content align="end" class="w-48">
|
||||
<DropdownMenu.Label>Toggle columns</DropdownMenu.Label>
|
||||
<DropdownMenu.Separator />
|
||||
{#each columns as column (column.key)}
|
||||
<DropdownMenu.CheckboxItem
|
||||
class=""
|
||||
checked={visibleColumns.includes(column.key)}
|
||||
disabled={column.canHide === false}
|
||||
onCheckedChange={() => toggleColumn(column.key)}
|
||||
>
|
||||
{getOptionLabel(lead.status, leadStatusOptions)}
|
||||
</span>
|
||||
{column.label}
|
||||
</DropdownMenu.CheckboxItem>
|
||||
{/each}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu.Root>
|
||||
{/if}
|
||||
|
||||
<Button onclick={openCreate}>
|
||||
<Plus class="mr-2 h-4 w-4" />
|
||||
New Lead
|
||||
</Button>
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet tabs()}
|
||||
<ViewTabs views={[{ id: 'all', label: 'All', count: totalLeadCount }]} active="all" />
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
<div class="flex flex-1 flex-col" class:min-h-0={viewMode === 'kanban'}>
|
||||
<FilterStrip>
|
||||
<SearchInput
|
||||
value={filters.search}
|
||||
placeholder="Search leads..."
|
||||
showLabel={false}
|
||||
onchange={(value) => updateFilters({ ...filters, search: value })}
|
||||
class="w-64"
|
||||
/>
|
||||
<SelectFilter
|
||||
label="Source"
|
||||
options={filterOptions.sources}
|
||||
value={filters.source || 'ALL'}
|
||||
onchange={(value) => updateFilters({ ...filters, source: value })}
|
||||
class="w-40"
|
||||
/>
|
||||
<SelectFilter
|
||||
label="Rating"
|
||||
options={filterOptions.ratings}
|
||||
value={filters.rating || 'ALL'}
|
||||
onchange={(value) => updateFilters({ ...filters, rating: value })}
|
||||
class="w-32"
|
||||
/>
|
||||
<DateRangeFilter
|
||||
label="Created"
|
||||
startDate={filters.created_at_gte}
|
||||
endDate={filters.created_at_lte}
|
||||
onchange={(start, end) =>
|
||||
updateFilters({ ...filters, created_at_gte: start, created_at_lte: end })}
|
||||
class="w-56"
|
||||
/>
|
||||
<TagFilter
|
||||
tags={data.tags || []}
|
||||
value={filters.tags}
|
||||
onchange={(ids) => updateFilters({ ...filters, tags: ids })}
|
||||
/>
|
||||
{#if activeFiltersCount > 0}
|
||||
<FilterPill label="Clear all" dashed onclick={clearFilters} />
|
||||
{/if}
|
||||
{#snippet meta()}
|
||||
<span>{filteredLeads.length} of {pagination.total} leads</span>
|
||||
{/snippet}
|
||||
</FilterStrip>
|
||||
|
||||
<!-- Content: Table or Kanban -->
|
||||
{#if viewMode === 'kanban'}
|
||||
<!-- Kanban View -->
|
||||
<div class="flex min-h-0 flex-1 flex-col">
|
||||
<LeadKanban
|
||||
data={kanbanData}
|
||||
loading={!kanbanData}
|
||||
onStatusChange={handleKanbanStatusChange}
|
||||
onCardClick={(lead) => openLead(lead, true)}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Table View -->
|
||||
{#if filteredLeads.length === 0}
|
||||
<div class="flex flex-col items-center justify-center py-16 text-center">
|
||||
<div
|
||||
class="mb-4 flex size-16 items-center justify-center rounded-[var(--radius-xl)] bg-[var(--surface-sunken)]"
|
||||
>
|
||||
<User class="size-8 text-[var(--text-tertiary)]" />
|
||||
</div>
|
||||
<h3 class="text-lg font-medium text-[var(--text-primary)]">No leads found</h3>
|
||||
<p class="mt-1 text-sm text-[var(--text-secondary)]">Create a new lead to get started</p>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Desktop Table using CrmTable -->
|
||||
<div class="hidden md:block">
|
||||
<CrmTable
|
||||
data={filteredLeads}
|
||||
{columns}
|
||||
bind:visibleColumns
|
||||
bind:activeRowId
|
||||
onRowChange={handleRowChange}
|
||||
onRowClick={(row) => openLead(row)}
|
||||
>
|
||||
{#snippet emptyState()}
|
||||
<div class="flex flex-col items-center justify-center py-16 text-center">
|
||||
<div
|
||||
class="mb-4 flex size-12 items-center justify-center rounded-[var(--radius-lg)] bg-[var(--surface-sunken)]"
|
||||
>
|
||||
<User class="size-6 text-[var(--text-tertiary)]" />
|
||||
</div>
|
||||
<h3 class="text-lg font-medium text-[var(--text-primary)]">No leads found</h3>
|
||||
</div>
|
||||
<div
|
||||
class="mt-2 flex flex-wrap items-center gap-3 text-xs text-[var(--text-secondary)]"
|
||||
>
|
||||
{#if lead.rating}
|
||||
{/snippet}
|
||||
</CrmTable>
|
||||
</div>
|
||||
|
||||
<!-- Mobile Card View -->
|
||||
<div class="divide-y divide-[var(--border-default)]/50 md:hidden">
|
||||
{#each filteredLeads as lead (lead.id)}
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full items-start gap-3 px-4 py-3 text-left transition-colors hover:bg-[var(--color-primary-light)] dark:hover:bg-[var(--color-primary-default)]/5"
|
||||
onclick={() => openLead(lead)}
|
||||
>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div>
|
||||
<p class="text-sm font-medium text-[var(--text-primary)]">
|
||||
{getFullName(lead)}
|
||||
</p>
|
||||
{#if lead.company}
|
||||
<p class="text-sm text-[var(--text-secondary)]">
|
||||
{typeof lead.company === 'object' ? lead.company.name : lead.company}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
<span
|
||||
class="rounded-full px-2 py-0.5 {getOptionStyle(
|
||||
lead.rating,
|
||||
leadRatingOptions
|
||||
class="shrink-0 rounded-full px-2 py-0.5 text-xs font-medium {getOptionStyle(
|
||||
lead.status,
|
||||
leadStatusOptions
|
||||
)}"
|
||||
>
|
||||
{getOptionLabel(lead.rating, leadRatingOptions)}
|
||||
{getOptionLabel(lead.status, leadStatusOptions)}
|
||||
</span>
|
||||
{/if}
|
||||
<span>{formatRelativeDate(lead.createdAt)}</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-2 flex flex-wrap items-center gap-3 text-xs text-[var(--text-secondary)]"
|
||||
>
|
||||
{#if lead.rating}
|
||||
<span
|
||||
class="rounded-full px-2 py-0.5 {getOptionStyle(
|
||||
lead.rating,
|
||||
leadRatingOptions
|
||||
)}"
|
||||
>
|
||||
{getOptionLabel(lead.rating, leadRatingOptions)}
|
||||
</span>
|
||||
{/if}
|
||||
<span>{formatRelativeDate(lead.createdAt)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
|
||||
<!-- Mobile new row button -->
|
||||
<button
|
||||
type="button"
|
||||
onclick={openCreate}
|
||||
class="flex w-full items-center gap-2 px-4 py-3 text-sm text-[var(--text-secondary)] transition-colors hover:bg-[var(--surface-raised)] hover:text-[var(--text-primary)]"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
New
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Mobile new row button -->
|
||||
<button
|
||||
type="button"
|
||||
onclick={openCreate}
|
||||
class="flex w-full items-center gap-2 px-4 py-3 text-sm text-[var(--text-secondary)] transition-colors hover:bg-[var(--surface-raised)] hover:text-[var(--text-primary)]"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
New
|
||||
</button>
|
||||
</div>
|
||||
<!-- Pagination (only for table view) -->
|
||||
<Pagination
|
||||
page={pagination.page}
|
||||
limit={pagination.limit}
|
||||
total={pagination.total}
|
||||
onPageChange={handlePageChange}
|
||||
onLimitChange={handleLimitChange}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- Pagination (only for table view) -->
|
||||
<Pagination
|
||||
page={pagination.page}
|
||||
limit={pagination.limit}
|
||||
total={pagination.total}
|
||||
onPageChange={handlePageChange}
|
||||
onLimitChange={handleLimitChange}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Lead Drawer -->
|
||||
|
|
@ -1820,7 +1819,9 @@
|
|||
|
||||
{#snippet metaSection()}
|
||||
{#if drawerData}
|
||||
<div class="flex flex-wrap items-center gap-x-2 gap-y-1 text-[12px] text-[color:var(--text-muted)]">
|
||||
<div
|
||||
class="flex flex-wrap items-center gap-x-2 gap-y-1 text-[12px] text-[color:var(--text-muted)]"
|
||||
>
|
||||
{#if drawerData.owner}
|
||||
<div class="flex items-center gap-1.5">
|
||||
<span
|
||||
|
|
@ -2014,4 +2015,6 @@
|
|||
>
|
||||
<input type="hidden" name="leadId" bind:value={kanbanFormState.leadId} />
|
||||
<input type="hidden" name="status" bind:value={kanbanFormState.status} />
|
||||
<input type="hidden" name="aboveLeadId" bind:value={kanbanFormState.aboveLeadId} />
|
||||
<input type="hidden" name="belowLeadId" bind:value={kanbanFormState.belowLeadId} />
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import { enhance } from '$app/forms';
|
||||
import { invalidateAll, goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import { onMount, tick } from 'svelte';
|
||||
import { onMount, tick, untrack } from 'svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import {
|
||||
Plus,
|
||||
|
|
@ -38,12 +38,7 @@
|
|||
import { CommentSection } from '$lib/components/ui/comment-section';
|
||||
import CustomFieldsPanel from '$lib/components/custom-fields/CustomFieldsPanel.svelte';
|
||||
import { getCurrentUser } from '$lib/api.js';
|
||||
import {
|
||||
SearchInput,
|
||||
SelectFilter,
|
||||
DateRangeFilter,
|
||||
TagFilter
|
||||
} from '$lib/components/ui/filter';
|
||||
import { SearchInput, SelectFilter, DateRangeFilter, TagFilter } from '$lib/components/ui/filter';
|
||||
import { Pagination } from '$lib/components/ui/pagination';
|
||||
import { cn } from '$lib/utils.js';
|
||||
import { TASK_STATUSES as statuses, PRIORITIES as priorities } from '$lib/constants/filters.js';
|
||||
|
|
@ -441,8 +436,11 @@
|
|||
return filtered;
|
||||
});
|
||||
|
||||
// Local data for optimistic updates
|
||||
let localTasks = $state(/** @type {any[]} */ ([]));
|
||||
// Local data for optimistic updates. Initialize synchronously from props so SSR
|
||||
// renders the actual rows instead of flashing "No tasks" until $effect runs on hydration.
|
||||
let localTasks = $state(
|
||||
/** @type {any[]} */ (untrack(() => (data.tasks ? [...data.tasks] : [])))
|
||||
);
|
||||
|
||||
$effect(() => {
|
||||
localTasks = [...filteredTasks];
|
||||
|
|
@ -1026,13 +1024,15 @@
|
|||
* @param {string} taskId
|
||||
* @param {string} newStatus
|
||||
* @param {string} _columnId
|
||||
* @param {string | null} aboveTaskId
|
||||
* @param {string | null} belowTaskId
|
||||
*/
|
||||
async function handleKanbanStatusChange(taskId, newStatus, _columnId) {
|
||||
async function handleKanbanStatusChange(taskId, newStatus, _columnId, aboveTaskId, belowTaskId) {
|
||||
kanbanFormState.taskId = taskId;
|
||||
kanbanFormState.status = newStatus;
|
||||
kanbanFormState.stageId = '';
|
||||
kanbanFormState.aboveTaskId = '';
|
||||
kanbanFormState.belowTaskId = '';
|
||||
kanbanFormState.aboveTaskId = aboveTaskId || '';
|
||||
kanbanFormState.belowTaskId = belowTaskId || '';
|
||||
await tick();
|
||||
moveTaskForm.requestSubmit();
|
||||
}
|
||||
|
|
@ -1110,246 +1110,244 @@
|
|||
</svelte:head>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<PageHeader title="Tasks" subtitle="{filteredTasks.length} of {tasks.length} tasks">
|
||||
{#snippet actions()}
|
||||
<div class="flex items-center gap-2">
|
||||
<!-- Status Filter Chips -->
|
||||
<div class="flex gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'ALL')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'ALL'
|
||||
? 'bg-[var(--color-primary-default)] text-white'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
All
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'ALL'
|
||||
? 'bg-[var(--color-primary-dark)] text-white/90'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
<PageHeader title="Tasks" subtitle="{filteredTasks.length} of {tasks.length} tasks">
|
||||
{#snippet actions()}
|
||||
<div class="flex items-center gap-2">
|
||||
<!-- Status Filter Chips -->
|
||||
<div class="flex gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'ALL')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'ALL'
|
||||
? 'bg-[var(--color-primary-default)] text-white'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
{tasks.length}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'active')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'active'
|
||||
? 'bg-[var(--task-due-today)] text-white'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
Active
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'active'
|
||||
? 'bg-black/20 text-white/90'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
All
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'ALL'
|
||||
? 'bg-[var(--color-primary-dark)] text-white/90'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
>
|
||||
{tasks.length}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'active')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'active'
|
||||
? 'bg-[var(--task-due-today)] text-white'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
{activeTaskCount}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'completed')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'completed'
|
||||
? 'bg-[var(--task-completed)] text-white'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
Completed
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'completed'
|
||||
? 'bg-black/20 text-white/90'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
Active
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'active'
|
||||
? 'bg-black/20 text-white/90'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
>
|
||||
{activeTaskCount}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (statusChipFilter = 'completed')}
|
||||
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors {statusChipFilter ===
|
||||
'completed'
|
||||
? 'bg-[var(--task-completed)] text-white'
|
||||
: 'bg-[var(--surface-sunken)] text-[var(--text-secondary)] hover:bg-[var(--surface-raised)]'}"
|
||||
>
|
||||
{completedCount}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="bg-border mx-1 h-6 w-px"></div>
|
||||
|
||||
<!-- View Toggle -->
|
||||
<div class="border-input bg-background inline-flex rounded-lg border p-1">
|
||||
<Button
|
||||
variant={viewMode === 'list' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
onclick={() => updateViewMode('list')}
|
||||
class="h-8 px-3"
|
||||
>
|
||||
<List class="mr-1.5 h-4 w-4" />
|
||||
List
|
||||
</Button>
|
||||
<Button
|
||||
variant={viewMode === 'kanban' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
onclick={() => updateViewMode('kanban')}
|
||||
class="h-8 px-3"
|
||||
>
|
||||
<Columns class="mr-1.5 h-4 w-4" />
|
||||
Board
|
||||
</Button>
|
||||
<Button
|
||||
variant={viewMode === 'calendar' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
onclick={() => updateViewMode('calendar')}
|
||||
class="h-8 px-3"
|
||||
>
|
||||
<Calendar class="mr-1.5 h-4 w-4" />
|
||||
Calendar
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{#if viewMode === 'list'}
|
||||
<DropdownMenu.Root>
|
||||
<DropdownMenu.Trigger>
|
||||
{#snippet child({ props })}
|
||||
<Button {...props} variant="outline" size="sm" class="gap-2">
|
||||
<Eye class="h-4 w-4" />
|
||||
Columns
|
||||
{#if columnCounts.visible < columnCounts.total}
|
||||
<span
|
||||
class="rounded-full bg-[var(--color-primary-light)] px-1.5 py-0.5 text-xs font-medium text-[var(--color-primary-default)]"
|
||||
>
|
||||
{columnCounts.visible}/{columnCounts.total}
|
||||
</span>
|
||||
{/if}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</DropdownMenu.Trigger>
|
||||
<DropdownMenu.Content align="end" class="w-48">
|
||||
<DropdownMenu.Label>Toggle columns</DropdownMenu.Label>
|
||||
<DropdownMenu.Separator />
|
||||
{#each taskColumns as column (column.key)}
|
||||
<DropdownMenu.CheckboxItem
|
||||
class=""
|
||||
checked={isColumnVisible(column.key)}
|
||||
onCheckedChange={() => toggleColumn(column.key)}
|
||||
disabled={column.canHide === false}
|
||||
>
|
||||
{column.label}
|
||||
</DropdownMenu.CheckboxItem>
|
||||
{/each}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu.Root>
|
||||
{/if}
|
||||
|
||||
<Button onclick={addNewTask}>
|
||||
<Plus class="mr-2 h-4 w-4" />
|
||||
New Task
|
||||
</Button>
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet tabs()}
|
||||
<ViewTabs views={[{ id: 'all', label: 'All', count: pagination.total }]} active="all" />
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
<div class="flex-1">
|
||||
<FilterStrip>
|
||||
<SearchInput
|
||||
value={filters.search}
|
||||
onchange={(value) => updateFilters({ ...filters, search: value })}
|
||||
placeholder="Search tasks..."
|
||||
/>
|
||||
<SelectFilter
|
||||
label="Priority"
|
||||
options={priorityFilterOptions}
|
||||
value={filters.priority}
|
||||
onchange={(value) => updateFilters({ ...filters, priority: value })}
|
||||
/>
|
||||
<DateRangeFilter
|
||||
label="Due Date"
|
||||
startDate={filters.due_date_gte}
|
||||
endDate={filters.due_date_lte}
|
||||
onchange={(start, end) =>
|
||||
updateFilters({ ...filters, due_date_gte: start, due_date_lte: end })}
|
||||
/>
|
||||
<TagFilter
|
||||
tags={allTags}
|
||||
value={filters.tags}
|
||||
onchange={(ids) => updateFilters({ ...filters, tags: ids })}
|
||||
/>
|
||||
{#if activeFiltersCount > 0}
|
||||
<FilterPill label="Clear all" dashed onclick={clearFilters} />
|
||||
{/if}
|
||||
{#snippet meta()}
|
||||
<span>{filteredTasks.length} of {pagination.total} tasks</span>
|
||||
{/snippet}
|
||||
</FilterStrip>
|
||||
{#if viewMode === 'list'}
|
||||
<CrmTable
|
||||
data={localTasks}
|
||||
columns={taskColumns}
|
||||
bind:visibleColumns
|
||||
bind:activeRowId
|
||||
onRowChange={handleRowChange}
|
||||
onRowClick={handleRowClick}
|
||||
>
|
||||
{#snippet emptyState()}
|
||||
<div class="flex flex-col items-center justify-center py-16 text-center">
|
||||
<div
|
||||
class="mb-4 flex size-16 items-center justify-center rounded-[var(--radius-xl)] bg-[var(--surface-sunken)]"
|
||||
>
|
||||
<CheckSquare class="size-8 text-[var(--text-tertiary)]" />
|
||||
</div>
|
||||
<h3 class="text-lg font-medium text-[var(--text-primary)]">No tasks found</h3>
|
||||
<p class="mt-1 text-sm text-[var(--text-secondary)]">
|
||||
Try adjusting your filters or create a new task
|
||||
</p>
|
||||
Completed
|
||||
<span
|
||||
class="rounded-full px-1.5 py-0.5 text-xs {statusChipFilter === 'completed'
|
||||
? 'bg-black/20 text-white/90'
|
||||
: 'bg-[var(--border-default)] text-[var(--text-tertiary)]'}"
|
||||
>
|
||||
{completedCount}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
{/snippet}
|
||||
</CrmTable>
|
||||
{:else if viewMode === 'kanban'}
|
||||
<TaskKanban
|
||||
data={kanbanData}
|
||||
loading={!kanbanData}
|
||||
onStatusChange={handleKanbanStatusChange}
|
||||
onCardClick={handleKanbanCardClick}
|
||||
onAddItem={handleAddCardFromColumn}
|
||||
/>
|
||||
{:else}
|
||||
<!-- Calendar View -->
|
||||
<div class="grid grid-cols-1 gap-6 lg:grid-cols-3">
|
||||
<!-- Calendar Section -->
|
||||
<div class="lg:col-span-2">
|
||||
<SectionCard padded={false} class="overflow-hidden">
|
||||
<!-- Calendar Header (domain-specific colored strip) -->
|
||||
<div
|
||||
class="bg-primary flex flex-row items-center justify-between space-y-0 p-4"
|
||||
|
||||
<div class="bg-border mx-1 h-6 w-px"></div>
|
||||
|
||||
<!-- View Toggle -->
|
||||
<div class="border-input bg-background inline-flex rounded-lg border p-1">
|
||||
<Button
|
||||
variant={viewMode === 'list' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
onclick={() => updateViewMode('list')}
|
||||
class="h-8 px-3"
|
||||
>
|
||||
<div class="flex items-center gap-4">
|
||||
<List class="mr-1.5 h-4 w-4" />
|
||||
List
|
||||
</Button>
|
||||
<Button
|
||||
variant={viewMode === 'kanban' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
onclick={() => updateViewMode('kanban')}
|
||||
class="h-8 px-3"
|
||||
>
|
||||
<Columns class="mr-1.5 h-4 w-4" />
|
||||
Board
|
||||
</Button>
|
||||
<Button
|
||||
variant={viewMode === 'calendar' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
onclick={() => updateViewMode('calendar')}
|
||||
class="h-8 px-3"
|
||||
>
|
||||
<Calendar class="mr-1.5 h-4 w-4" />
|
||||
Calendar
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{#if viewMode === 'list'}
|
||||
<DropdownMenu.Root>
|
||||
<DropdownMenu.Trigger>
|
||||
{#snippet child({ props })}
|
||||
<Button {...props} variant="outline" size="sm" class="gap-2">
|
||||
<Eye class="h-4 w-4" />
|
||||
Columns
|
||||
{#if columnCounts.visible < columnCounts.total}
|
||||
<span
|
||||
class="rounded-full bg-[var(--color-primary-light)] px-1.5 py-0.5 text-xs font-medium text-[var(--color-primary-default)]"
|
||||
>
|
||||
{columnCounts.visible}/{columnCounts.total}
|
||||
</span>
|
||||
{/if}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</DropdownMenu.Trigger>
|
||||
<DropdownMenu.Content align="end" class="w-48">
|
||||
<DropdownMenu.Label>Toggle columns</DropdownMenu.Label>
|
||||
<DropdownMenu.Separator />
|
||||
{#each taskColumns as column (column.key)}
|
||||
<DropdownMenu.CheckboxItem
|
||||
class=""
|
||||
checked={isColumnVisible(column.key)}
|
||||
onCheckedChange={() => toggleColumn(column.key)}
|
||||
disabled={column.canHide === false}
|
||||
>
|
||||
{column.label}
|
||||
</DropdownMenu.CheckboxItem>
|
||||
{/each}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu.Root>
|
||||
{/if}
|
||||
|
||||
<Button onclick={addNewTask}>
|
||||
<Plus class="mr-2 h-4 w-4" />
|
||||
New Task
|
||||
</Button>
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet tabs()}
|
||||
<ViewTabs views={[{ id: 'all', label: 'All', count: pagination.total }]} active="all" />
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
<div class="flex-1">
|
||||
<FilterStrip>
|
||||
<SearchInput
|
||||
value={filters.search}
|
||||
onchange={(value) => updateFilters({ ...filters, search: value })}
|
||||
placeholder="Search tasks..."
|
||||
/>
|
||||
<SelectFilter
|
||||
label="Priority"
|
||||
options={priorityFilterOptions}
|
||||
value={filters.priority}
|
||||
onchange={(value) => updateFilters({ ...filters, priority: value })}
|
||||
/>
|
||||
<DateRangeFilter
|
||||
label="Due Date"
|
||||
startDate={filters.due_date_gte}
|
||||
endDate={filters.due_date_lte}
|
||||
onchange={(start, end) =>
|
||||
updateFilters({ ...filters, due_date_gte: start, due_date_lte: end })}
|
||||
/>
|
||||
<TagFilter
|
||||
tags={allTags}
|
||||
value={filters.tags}
|
||||
onchange={(ids) => updateFilters({ ...filters, tags: ids })}
|
||||
/>
|
||||
{#if activeFiltersCount > 0}
|
||||
<FilterPill label="Clear all" dashed onclick={clearFilters} />
|
||||
{/if}
|
||||
{#snippet meta()}
|
||||
<span>{filteredTasks.length} of {pagination.total} tasks</span>
|
||||
{/snippet}
|
||||
</FilterStrip>
|
||||
{#if viewMode === 'list'}
|
||||
<CrmTable
|
||||
data={localTasks}
|
||||
columns={taskColumns}
|
||||
bind:visibleColumns
|
||||
bind:activeRowId
|
||||
onRowChange={handleRowChange}
|
||||
onRowClick={handleRowClick}
|
||||
>
|
||||
{#snippet emptyState()}
|
||||
<div class="flex flex-col items-center justify-center py-16 text-center">
|
||||
<div
|
||||
class="mb-4 flex size-16 items-center justify-center rounded-[var(--radius-xl)] bg-[var(--surface-sunken)]"
|
||||
>
|
||||
<CheckSquare class="size-8 text-[var(--text-tertiary)]" />
|
||||
</div>
|
||||
<h3 class="text-lg font-medium text-[var(--text-primary)]">No tasks found</h3>
|
||||
<p class="mt-1 text-sm text-[var(--text-secondary)]">
|
||||
Try adjusting your filters or create a new task
|
||||
</p>
|
||||
</div>
|
||||
{/snippet}
|
||||
</CrmTable>
|
||||
{:else if viewMode === 'kanban'}
|
||||
<TaskKanban
|
||||
data={kanbanData}
|
||||
loading={!kanbanData}
|
||||
onStatusChange={handleKanbanStatusChange}
|
||||
onCardClick={handleKanbanCardClick}
|
||||
onAddItem={handleAddCardFromColumn}
|
||||
/>
|
||||
{:else}
|
||||
<!-- Calendar View -->
|
||||
<div class="grid grid-cols-1 gap-6 lg:grid-cols-3">
|
||||
<!-- Calendar Section -->
|
||||
<div class="lg:col-span-2">
|
||||
<SectionCard padded={false} class="overflow-hidden">
|
||||
<!-- Calendar Header (domain-specific colored strip) -->
|
||||
<div class="bg-primary flex flex-row items-center justify-between space-y-0 p-4">
|
||||
<div class="flex items-center gap-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onclick={previousMonth}
|
||||
class="hover:bg-primary-foreground/10 text-primary-foreground h-9 w-9"
|
||||
>
|
||||
<ChevronLeft class="h-5 w-5" />
|
||||
</Button>
|
||||
<h2 class="text-primary-foreground text-xl font-semibold">
|
||||
{monthNames[calendarMonth]}
|
||||
{calendarYear}
|
||||
</h2>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onclick={nextMonth}
|
||||
class="hover:bg-primary-foreground/10 text-primary-foreground h-9 w-9"
|
||||
>
|
||||
<ChevronRight class="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onclick={previousMonth}
|
||||
class="hover:bg-primary-foreground/10 text-primary-foreground h-9 w-9"
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onclick={goToToday}
|
||||
class="text-primary-foreground bg-primary-foreground/10 hover:bg-primary-foreground/20"
|
||||
>
|
||||
<ChevronLeft class="h-5 w-5" />
|
||||
</Button>
|
||||
<h2 class="text-primary-foreground text-xl font-semibold">
|
||||
{monthNames[calendarMonth]}
|
||||
{calendarYear}
|
||||
</h2>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onclick={nextMonth}
|
||||
class="hover:bg-primary-foreground/10 text-primary-foreground h-9 w-9"
|
||||
>
|
||||
<ChevronRight class="h-5 w-5" />
|
||||
Today
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onclick={goToToday}
|
||||
class="text-primary-foreground bg-primary-foreground/10 hover:bg-primary-foreground/20"
|
||||
>
|
||||
Today
|
||||
</Button>
|
||||
</div>
|
||||
<!-- Days of Week -->
|
||||
<div class="bg-muted/50 grid grid-cols-7 border-b">
|
||||
{#each ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] as day}
|
||||
|
|
@ -1408,26 +1406,28 @@
|
|||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</SectionCard>
|
||||
</div>
|
||||
</SectionCard>
|
||||
</div>
|
||||
|
||||
<!-- Tasks for Selected Date -->
|
||||
<div class="lg:col-span-1">
|
||||
<SectionCard class="h-fit">
|
||||
{#snippet title()}
|
||||
<div class="flex min-w-0 flex-col gap-0.5">
|
||||
<h3 class="truncate text-[16px] font-medium leading-[1.3] text-[color:var(--text-primary)]">
|
||||
Tasks for {new Date(selectedDate + 'T00:00:00').toLocaleDateString('en-US', {
|
||||
weekday: 'long',
|
||||
month: 'long',
|
||||
day: 'numeric'
|
||||
})}
|
||||
</h3>
|
||||
<p class="text-[12px] text-[color:var(--text-muted)]">
|
||||
{selectedTasks.length} task{selectedTasks.length !== 1 ? 's' : ''}
|
||||
</p>
|
||||
</div>
|
||||
{/snippet}
|
||||
<!-- Tasks for Selected Date -->
|
||||
<div class="lg:col-span-1">
|
||||
<SectionCard class="h-fit">
|
||||
{#snippet title()}
|
||||
<div class="flex min-w-0 flex-col gap-0.5">
|
||||
<h3
|
||||
class="truncate text-[16px] font-medium leading-[1.3] text-[color:var(--text-primary)]"
|
||||
>
|
||||
Tasks for {new Date(selectedDate + 'T00:00:00').toLocaleDateString('en-US', {
|
||||
weekday: 'long',
|
||||
month: 'long',
|
||||
day: 'numeric'
|
||||
})}
|
||||
</h3>
|
||||
<p class="text-[12px] text-[color:var(--text-muted)]">
|
||||
{selectedTasks.length} task{selectedTasks.length !== 1 ? 's' : ''}
|
||||
</p>
|
||||
</div>
|
||||
{/snippet}
|
||||
{#if selectedTasks.length > 0}
|
||||
<div class="space-y-3">
|
||||
{#each selectedTasks as task}
|
||||
|
|
@ -1487,34 +1487,34 @@
|
|||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</SectionCard>
|
||||
</SectionCard>
|
||||
|
||||
<!-- Monthly Stats -->
|
||||
<SectionCard title="This Month" class="mt-4">
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-muted-foreground text-sm">Total Tasks</span>
|
||||
<span class="text-foreground font-medium">{totalMonthlyTasks}</span>
|
||||
<!-- Monthly Stats -->
|
||||
<SectionCard title="This Month" class="mt-4">
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-muted-foreground text-sm">Total Tasks</span>
|
||||
<span class="text-foreground font-medium">{totalMonthlyTasks}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-muted-foreground text-sm">Days with Tasks</span>
|
||||
<span class="text-foreground font-medium">{monthlyTaskDates.length}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-muted-foreground text-sm">Days with Tasks</span>
|
||||
<span class="text-foreground font-medium">{monthlyTaskDates.length}</span>
|
||||
</div>
|
||||
</div>
|
||||
</SectionCard>
|
||||
</SectionCard>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<!-- Pagination -->
|
||||
<Pagination
|
||||
page={pagination.page}
|
||||
limit={pagination.limit}
|
||||
total={pagination.total}
|
||||
onPageChange={handlePageChange}
|
||||
onLimitChange={handleLimitChange}
|
||||
/>
|
||||
</div>
|
||||
<!-- Pagination -->
|
||||
<Pagination
|
||||
page={pagination.page}
|
||||
limit={pagination.limit}
|
||||
total={pagination.total}
|
||||
onPageChange={handlePageChange}
|
||||
onLimitChange={handleLimitChange}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Task Detail Drawer -->
|
||||
|
|
|
|||
|
|
@ -28,13 +28,12 @@
|
|||
import { CrmTable } from '$lib/components/ui/crm-table';
|
||||
import { CrmDrawer } from '$lib/components/ui/crm-drawer';
|
||||
import { BulkActionBar } from '$lib/components/ui/bulk-action-bar';
|
||||
import { TicketStatusChips, TicketListActions, TicketImportDrawer } from '$lib/components/tickets';
|
||||
import {
|
||||
SearchInput,
|
||||
SelectFilter,
|
||||
DateRangeFilter,
|
||||
TagFilter
|
||||
} from '$lib/components/ui/filter';
|
||||
TicketStatusChips,
|
||||
TicketListActions,
|
||||
TicketImportDrawer
|
||||
} from '$lib/components/tickets';
|
||||
import { SearchInput, SelectFilter, DateRangeFilter, TagFilter } from '$lib/components/ui/filter';
|
||||
import { Pagination } from '$lib/components/ui/pagination';
|
||||
import {
|
||||
ticketStatusOptions,
|
||||
|
|
@ -685,11 +684,19 @@
|
|||
* @param {string} ticketId
|
||||
* @param {string} targetColumnId
|
||||
* @param {string} _columnId
|
||||
* @param {string | null} aboveTicketId
|
||||
* @param {string | null} belowTicketId
|
||||
*/
|
||||
async function handleKanbanStatusChange(ticketId, targetColumnId, _columnId) {
|
||||
async function handleKanbanStatusChange(
|
||||
ticketId,
|
||||
targetColumnId,
|
||||
_columnId,
|
||||
aboveTicketId,
|
||||
belowTicketId
|
||||
) {
|
||||
kanbanFormState.ticketId = ticketId;
|
||||
kanbanFormState.aboveTicketId = '';
|
||||
kanbanFormState.belowTicketId = '';
|
||||
kanbanFormState.aboveTicketId = aboveTicketId || '';
|
||||
kanbanFormState.belowTicketId = belowTicketId || '';
|
||||
|
||||
// Determine mode from kanban data
|
||||
// In status-based mode, column.id is a status value (e.g., "New", "Assigned")
|
||||
|
|
@ -720,173 +727,170 @@
|
|||
</svelte:head>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<PageHeader title="Tickets" subtitle="{filteredTickets.length} of {ticketsData.length} tickets">
|
||||
{#snippet actions()}
|
||||
<div class="flex items-center gap-2">
|
||||
<TicketStatusChips
|
||||
value={statusChipFilter}
|
||||
total={ticketsData.length}
|
||||
{openCount}
|
||||
{closedCount}
|
||||
onChange={(v) => (statusChipFilter = v)}
|
||||
/>
|
||||
<Button
|
||||
variant={data.watchingOnly ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
class="gap-1.5"
|
||||
onclick={() => {
|
||||
const url = new URL($page.url);
|
||||
if (data.watchingOnly) url.searchParams.delete('watching');
|
||||
else url.searchParams.set('watching', 'true');
|
||||
url.searchParams.delete('page');
|
||||
goto(url.pathname + (url.search ? url.search : ''));
|
||||
}}
|
||||
title={data.watchingOnly
|
||||
? 'Show all tickets'
|
||||
: 'Show only tickets you are watching'}
|
||||
>
|
||||
<Eye class="h-3.5 w-3.5" />
|
||||
Watching
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="gap-1.5"
|
||||
onclick={() => goto('/tickets/analytics')}
|
||||
title="Open the analytics dashboard"
|
||||
>
|
||||
<BarChart3 class="h-3.5 w-3.5" />
|
||||
Analytics
|
||||
</Button>
|
||||
<div class="bg-border mx-1 h-6 w-px"></div>
|
||||
<TicketListActions
|
||||
{viewMode}
|
||||
filtersExpanded={false}
|
||||
{activeFiltersCount}
|
||||
{columns}
|
||||
visibleCount={columnCounts.visible}
|
||||
totalCount={columnCounts.total}
|
||||
{isColumnVisible}
|
||||
onViewMode={updateViewMode}
|
||||
onToggleFilters={() => {}}
|
||||
onToggleColumn={toggleColumn}
|
||||
onCreate={drawer.openCreate}
|
||||
onImport={() => (importOpen = true)}
|
||||
/>
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet tabs()}
|
||||
<ViewTabs views={[{ id: 'all', label: 'All', count: pagination.total }]} active="all" />
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
<div class="flex-1">
|
||||
<FilterStrip>
|
||||
<SearchInput
|
||||
value={filters.search}
|
||||
onchange={(value) => updateFilters({ ...filters, search: value })}
|
||||
placeholder="Search tickets..."
|
||||
/>
|
||||
<SelectFilter
|
||||
label="Priority"
|
||||
options={priorityFilterOptions}
|
||||
value={filters.priority}
|
||||
onchange={(value) => updateFilters({ ...filters, priority: value })}
|
||||
/>
|
||||
<SelectFilter
|
||||
label="Type"
|
||||
options={typeFilterOptions}
|
||||
value={filters.case_type}
|
||||
onchange={(value) => updateFilters({ ...filters, case_type: value })}
|
||||
/>
|
||||
<DateRangeFilter
|
||||
label="Created"
|
||||
startDate={filters.created_at_gte}
|
||||
endDate={filters.created_at_lte}
|
||||
onchange={(start, end) =>
|
||||
updateFilters({ ...filters, created_at_gte: start, created_at_lte: end })}
|
||||
/>
|
||||
<TagFilter
|
||||
tags={allTags}
|
||||
value={filters.tags}
|
||||
onchange={(ids) => updateFilters({ ...filters, tags: ids })}
|
||||
/>
|
||||
{#if activeFiltersCount > 0}
|
||||
<FilterPill label="Clear all" dashed onclick={clearFilters} />
|
||||
{/if}
|
||||
{#snippet meta()}
|
||||
<span>{filteredTickets.length} of {pagination.total} tickets</span>
|
||||
<PageHeader title="Tickets" subtitle="{filteredTickets.length} of {ticketsData.length} tickets">
|
||||
{#snippet actions()}
|
||||
<div class="flex items-center gap-2">
|
||||
<TicketStatusChips
|
||||
value={statusChipFilter}
|
||||
total={ticketsData.length}
|
||||
{openCount}
|
||||
{closedCount}
|
||||
onChange={(v) => (statusChipFilter = v)}
|
||||
/>
|
||||
<Button
|
||||
variant={data.watchingOnly ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
class="gap-1.5"
|
||||
onclick={() => {
|
||||
const url = new URL($page.url);
|
||||
if (data.watchingOnly) url.searchParams.delete('watching');
|
||||
else url.searchParams.set('watching', 'true');
|
||||
url.searchParams.delete('page');
|
||||
goto(url.pathname + (url.search ? url.search : ''));
|
||||
}}
|
||||
title={data.watchingOnly ? 'Show all tickets' : 'Show only tickets you are watching'}
|
||||
>
|
||||
<Eye class="h-3.5 w-3.5" />
|
||||
Watching
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="gap-1.5"
|
||||
onclick={() => goto('/tickets/analytics')}
|
||||
title="Open the analytics dashboard"
|
||||
>
|
||||
<BarChart3 class="h-3.5 w-3.5" />
|
||||
Analytics
|
||||
</Button>
|
||||
<div class="bg-border mx-1 h-6 w-px"></div>
|
||||
<TicketListActions
|
||||
{viewMode}
|
||||
filtersExpanded={false}
|
||||
{activeFiltersCount}
|
||||
{columns}
|
||||
visibleCount={columnCounts.visible}
|
||||
totalCount={columnCounts.total}
|
||||
{isColumnVisible}
|
||||
onViewMode={updateViewMode}
|
||||
onToggleFilters={() => {}}
|
||||
onToggleColumn={toggleColumn}
|
||||
onCreate={drawer.openCreate}
|
||||
onImport={() => (importOpen = true)}
|
||||
/>
|
||||
</div>
|
||||
{/snippet}
|
||||
</FilterStrip>
|
||||
{#snippet tabs()}
|
||||
<ViewTabs views={[{ id: 'all', label: 'All', count: pagination.total }]} active="all" />
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
{#if viewMode === 'list'}
|
||||
<CrmTable
|
||||
data={filteredTickets}
|
||||
{columns}
|
||||
bind:visibleColumns
|
||||
bind:selectedIds
|
||||
bind:activeRowId
|
||||
selectable={true}
|
||||
onRowChange={handleRowChange}
|
||||
onRowClick={(row) => goto(`/tickets/${row.id}`)}
|
||||
>
|
||||
{#snippet cellSuffix(row, column)}
|
||||
{#if column.key === 'subject' && row.escalationCount > 0}
|
||||
<span
|
||||
class="ml-2 inline-flex items-center gap-1 rounded-full bg-amber-100 px-1.5 py-0.5 align-middle text-[10px] font-medium text-amber-800 dark:bg-amber-900/30 dark:text-amber-300"
|
||||
title={row.lastEscalationFiredAt
|
||||
? `Escalated ${row.escalationCount}× — last ${new Date(row.lastEscalationFiredAt).toLocaleString()}`
|
||||
: `Escalated ${row.escalationCount}×`}
|
||||
>
|
||||
<AlertTriangle class="h-3 w-3" />
|
||||
Escalated
|
||||
</span>
|
||||
{/if}
|
||||
{#if column.key === 'subject' && (row.isProblem || row.childCount > 0)}
|
||||
<span
|
||||
class="ml-2 inline-flex items-center gap-1 rounded-full bg-purple-100 px-1.5 py-0.5 align-middle text-[10px] font-medium text-purple-800 dark:bg-purple-900/30 dark:text-purple-300"
|
||||
title={row.isProblem
|
||||
? `Problem ticket · ${row.childCount} linked child${row.childCount === 1 ? '' : 'ren'}`
|
||||
: `${row.childCount} linked child${row.childCount === 1 ? '' : 'ren'}`}
|
||||
>
|
||||
<Network class="h-3 w-3" />
|
||||
{row.isProblem ? 'Problem' : 'Tree'}
|
||||
</span>
|
||||
{/if}
|
||||
<div class="flex-1">
|
||||
<FilterStrip>
|
||||
<SearchInput
|
||||
value={filters.search}
|
||||
onchange={(value) => updateFilters({ ...filters, search: value })}
|
||||
placeholder="Search tickets..."
|
||||
/>
|
||||
<SelectFilter
|
||||
label="Priority"
|
||||
options={priorityFilterOptions}
|
||||
value={filters.priority}
|
||||
onchange={(value) => updateFilters({ ...filters, priority: value })}
|
||||
/>
|
||||
<SelectFilter
|
||||
label="Type"
|
||||
options={typeFilterOptions}
|
||||
value={filters.case_type}
|
||||
onchange={(value) => updateFilters({ ...filters, case_type: value })}
|
||||
/>
|
||||
<DateRangeFilter
|
||||
label="Created"
|
||||
startDate={filters.created_at_gte}
|
||||
endDate={filters.created_at_lte}
|
||||
onchange={(start, end) =>
|
||||
updateFilters({ ...filters, created_at_gte: start, created_at_lte: end })}
|
||||
/>
|
||||
<TagFilter
|
||||
tags={allTags}
|
||||
value={filters.tags}
|
||||
onchange={(ids) => updateFilters({ ...filters, tags: ids })}
|
||||
/>
|
||||
{#if activeFiltersCount > 0}
|
||||
<FilterPill label="Clear all" dashed onclick={clearFilters} />
|
||||
{/if}
|
||||
{#snippet meta()}
|
||||
<span>{filteredTickets.length} of {pagination.total} tickets</span>
|
||||
{/snippet}
|
||||
{#snippet emptyState()}
|
||||
<div class="flex flex-col items-center justify-center py-16 text-center">
|
||||
<div
|
||||
class="mb-4 flex size-16 items-center justify-center rounded-[var(--radius-xl)] bg-[var(--surface-sunken)]"
|
||||
>
|
||||
<Briefcase class="size-8 text-[var(--text-tertiary)]" />
|
||||
</FilterStrip>
|
||||
|
||||
{#if viewMode === 'list'}
|
||||
<CrmTable
|
||||
data={filteredTickets}
|
||||
{columns}
|
||||
bind:visibleColumns
|
||||
bind:selectedIds
|
||||
bind:activeRowId
|
||||
selectable={true}
|
||||
onRowChange={handleRowChange}
|
||||
onRowClick={(row) => goto(`/tickets/${row.id}`)}
|
||||
>
|
||||
{#snippet cellSuffix(row, column)}
|
||||
{#if column.key === 'subject' && row.escalationCount > 0}
|
||||
<span
|
||||
class="ml-2 inline-flex items-center gap-1 rounded-full bg-amber-100 px-1.5 py-0.5 align-middle text-[10px] font-medium text-amber-800 dark:bg-amber-900/30 dark:text-amber-300"
|
||||
title={row.lastEscalationFiredAt
|
||||
? `Escalated ${row.escalationCount}× — last ${new Date(row.lastEscalationFiredAt).toLocaleString()}`
|
||||
: `Escalated ${row.escalationCount}×`}
|
||||
>
|
||||
<AlertTriangle class="h-3 w-3" />
|
||||
Escalated
|
||||
</span>
|
||||
{/if}
|
||||
{#if column.key === 'subject' && (row.isProblem || row.childCount > 0)}
|
||||
<span
|
||||
class="ml-2 inline-flex items-center gap-1 rounded-full bg-purple-100 px-1.5 py-0.5 align-middle text-[10px] font-medium text-purple-800 dark:bg-purple-900/30 dark:text-purple-300"
|
||||
title={row.isProblem
|
||||
? `Problem ticket · ${row.childCount} linked child${row.childCount === 1 ? '' : 'ren'}`
|
||||
: `${row.childCount} linked child${row.childCount === 1 ? '' : 'ren'}`}
|
||||
>
|
||||
<Network class="h-3 w-3" />
|
||||
{row.isProblem ? 'Problem' : 'Tree'}
|
||||
</span>
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet emptyState()}
|
||||
<div class="flex flex-col items-center justify-center py-16 text-center">
|
||||
<div
|
||||
class="mb-4 flex size-16 items-center justify-center rounded-[var(--radius-xl)] bg-[var(--surface-sunken)]"
|
||||
>
|
||||
<Briefcase class="size-8 text-[var(--text-tertiary)]" />
|
||||
</div>
|
||||
<h3 class="text-lg font-medium text-[var(--text-primary)]">No tickets found</h3>
|
||||
<p class="mt-1 text-sm text-[var(--text-secondary)]">
|
||||
Try adjusting your filters or create a new ticket
|
||||
</p>
|
||||
</div>
|
||||
<h3 class="text-lg font-medium text-[var(--text-primary)]">No tickets found</h3>
|
||||
<p class="mt-1 text-sm text-[var(--text-secondary)]">
|
||||
Try adjusting your filters or create a new ticket
|
||||
</p>
|
||||
</div>
|
||||
{/snippet}
|
||||
</CrmTable>
|
||||
|
||||
<!-- Pagination (only for list view) -->
|
||||
<Pagination
|
||||
page={pagination.page}
|
||||
limit={pagination.limit}
|
||||
total={pagination.total}
|
||||
onPageChange={handlePageChange}
|
||||
onLimitChange={handleLimitChange}
|
||||
/>
|
||||
{:else}
|
||||
<TicketKanban
|
||||
data={kanbanData}
|
||||
loading={!kanbanData}
|
||||
onStatusChange={handleKanbanStatusChange}
|
||||
onCardClick={handleKanbanCardClick}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
</CrmTable>
|
||||
|
||||
<!-- Pagination (only for list view) -->
|
||||
<Pagination
|
||||
page={pagination.page}
|
||||
limit={pagination.limit}
|
||||
total={pagination.total}
|
||||
onPageChange={handlePageChange}
|
||||
onLimitChange={handleLimitChange}
|
||||
/>
|
||||
{:else}
|
||||
<TicketKanban
|
||||
data={kanbanData}
|
||||
loading={!kanbanData}
|
||||
onStatusChange={handleKanbanStatusChange}
|
||||
onCardClick={handleKanbanCardClick}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<BulkActionBar
|
||||
|
|
|
|||
Loading…
Reference in a new issue