Require a stage-move reason and record it on the lead timeline.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-18 18:18:52 +03:30
co-authored by Cursor
parent cd51439353
commit c185348c2d
7 changed files with 278 additions and 23 deletions
+96 -6
View File
@@ -17,6 +17,7 @@ import {
Space as ASpace,
Spin as ASpin,
Tag as ATag,
Textarea as ATextarea,
Typography,
theme,
} from 'ant-design-vue';
@@ -61,6 +62,17 @@ const addLost = ref(false);
const addUnqualified = ref(false);
const deleteTarget = ref<LeadStageDto | null>(null);
const moveConfirm = ref<{ stageIds: string[]; message: string } | null>(null);
const pendingLeadMove = ref<{
leadId: string;
stageId: string;
position: number;
fromStageName: string;
toStageName: string;
prev: LeadBoardColumnDto[];
nextColumns: LeadBoardColumnDto[];
} | null>(null);
const stageMoveReason = ref('');
const stageMoveError = ref('');
const draggingId = ref<string | null>(null);
const insertAt = ref<number | null>(null);
const bodyEls = new Map<string, HTMLElement>();
@@ -520,7 +532,7 @@ async function onDrop(stageId: string, event: DragEvent, index?: number) {
draggingId.value = null;
dropStageId.value = null;
clearDragUi();
if (!leadId || moving.value) return;
if (!leadId || moving.value || pendingLeadMove.value) return;
const fromCol = columns.value.find((c) =>
c.leads.some((l) => l.id === leadId),
@@ -546,7 +558,7 @@ async function onDrop(stageId: string, event: DragEvent, index?: number) {
leads: [...c.leads],
}));
columns.value = columns.value.map((c) => {
const nextColumns = columns.value.map((c) => {
if (same && c.stage.id === stageId) return { ...c, leads: nextLeads };
if (c.stage.id === fromCol.stage.id) {
return {
@@ -561,13 +573,66 @@ async function onDrop(stageId: string, event: DragEvent, index?: number) {
return c;
});
// جابه‌جایی داخل همان ستون: بدون دلیل
if (same) {
columns.value = nextColumns;
moving.value = true;
error.value = '';
try {
await api.patch(`/leads/${leadId}/move`, { stageId, position: insertIndex });
} catch {
columns.value = prev;
error.value = 'جابه‌جایی لید ناموفق بود.';
} finally {
moving.value = false;
}
return;
}
// تغییر ستون: اول دلیل، بعد اعمال
stageMoveReason.value = '';
stageMoveError.value = '';
pendingLeadMove.value = {
leadId,
stageId,
position: insertIndex,
fromStageName: fromCol.stage.name,
toStageName: target.stage.name,
prev,
nextColumns,
};
}
function cancelPendingLeadMove() {
pendingLeadMove.value = null;
stageMoveReason.value = '';
stageMoveError.value = '';
}
async function confirmPendingLeadMove() {
const pending = pendingLeadMove.value;
if (!pending || moving.value) return Promise.reject();
const reason = stageMoveReason.value.trim();
if (!reason) {
stageMoveError.value = 'دلیل تغییر ستون را بنویسید.';
return Promise.reject();
}
columns.value = pending.nextColumns;
moving.value = true;
error.value = '';
stageMoveError.value = '';
try {
await api.patch(`/leads/${leadId}/move`, { stageId, position: insertIndex });
} catch {
columns.value = prev;
error.value = 'جابه‌جایی لید ناموفق بود.';
await api.patch(`/leads/${pending.leadId}/move`, {
stageId: pending.stageId,
position: pending.position,
reason,
});
cancelPendingLeadMove();
} catch (e) {
columns.value = pending.prev;
stageMoveError.value = apiMessage(e, 'جابه‌جایی لید ناموفق بود.');
error.value = stageMoveError.value;
return Promise.reject(e);
} finally {
moving.value = false;
}
@@ -969,6 +1034,31 @@ onMounted(load);
>
<a-alert v-if="moveConfirm" type="warning" show-icon :message="moveConfirm.message" />
</a-modal>
<a-modal
:open="!!pendingLeadMove"
title="دلیل تغییر ستون"
ok-text="ثبت و انتقال"
cancel-text="انصراف"
:confirm-loading="moving"
:ok-button-props="{ disabled: !stageMoveReason.trim() }"
@ok="confirmPendingLeadMove"
@cancel="cancelPendingLeadMove"
>
<a-flex vertical :gap="12">
<a-typography-text v-if="pendingLeadMove" type="secondary">
انتقال از «{{ pendingLeadMove.fromStageName }}» به «{{ pendingLeadMove.toStageName }}»
</a-typography-text>
<a-textarea
v-model:value="stageMoveReason"
:rows="4"
:maxlength="1000"
show-count
placeholder="دلیل تغییر ستون را بنویسید…"
/>
<a-alert v-if="stageMoveError" type="error" show-icon :message="stageMoveError" />
</a-flex>
</a-modal>
</div>
</template>