feat: board and status selects in deal editor
This commit is contained in:
@ -41,7 +41,11 @@ const useDealsAndStatusesDnd = (): ReturnType => {
|
||||
const getStatusByDealId = (dealId: number) => {
|
||||
const deal = deals.find(deal => deal.id === dealId);
|
||||
if (!deal) return;
|
||||
return statuses.find(status => status.id === deal.statusId);
|
||||
return statuses.find(status => status.id === deal.status.id);
|
||||
};
|
||||
|
||||
const getStatusById = (statusId: number) => {
|
||||
return statuses.find(status => status.id === statusId);
|
||||
};
|
||||
|
||||
const swipeSliderDuringDrag = (activeId: number, over: Over) => {
|
||||
@ -105,19 +109,19 @@ const useDealsAndStatusesDnd = (): ReturnType => {
|
||||
const activeStatusId = getStatusByDealId(activeDealId)?.id;
|
||||
if (!activeStatusId) return;
|
||||
|
||||
const { overStatusId, newLexorank } = getDropTarget(
|
||||
const { overStatus, newLexorank } = getDropTarget(
|
||||
over.id,
|
||||
activeDealId,
|
||||
activeStatusId
|
||||
);
|
||||
if (!overStatusId) return;
|
||||
if (!overStatus) return;
|
||||
|
||||
debouncedSetDeals(
|
||||
deals.map(deal =>
|
||||
deal.id === activeDealId
|
||||
? {
|
||||
...deal,
|
||||
statusId: overStatusId,
|
||||
status: overStatus,
|
||||
lexorank: newLexorank || deal.lexorank,
|
||||
}
|
||||
: deal
|
||||
@ -134,7 +138,7 @@ const useDealsAndStatusesDnd = (): ReturnType => {
|
||||
} else {
|
||||
const deal = deals.find(deal => deal.id === over.id);
|
||||
if (!deal) return;
|
||||
overStatusId = deal.statusId;
|
||||
overStatusId = deal.status.id;
|
||||
}
|
||||
|
||||
if (!overStatusId || activeStatusId === overStatusId) return;
|
||||
@ -156,42 +160,42 @@ const useDealsAndStatusesDnd = (): ReturnType => {
|
||||
activeDealId: number,
|
||||
activeStatusId: number,
|
||||
isOnDragEnd: boolean = false
|
||||
) => {
|
||||
): { overStatus?: StatusSchema; newLexorank?: string } => {
|
||||
if (typeof overId === "string") {
|
||||
return {
|
||||
overStatusId: getStatusId(overId),
|
||||
overStatus: getStatusById(getStatusId(overId)),
|
||||
newLexorank: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const overDealId = Number(overId);
|
||||
const overStatusId = getStatusByDealId(overDealId)?.id;
|
||||
const overStatus = getStatusByDealId(overDealId);
|
||||
|
||||
if (!overStatusId || (!isOnDragEnd && activeDealId === overDealId)) {
|
||||
return { overStatusId: undefined, newLexorank: undefined };
|
||||
if (!overStatus || (!isOnDragEnd && activeDealId === overDealId)) {
|
||||
return { overStatus: undefined, newLexorank: undefined };
|
||||
}
|
||||
|
||||
const statusDeals = sortByLexorank(
|
||||
deals.filter(deal => deal.statusId === overStatusId)
|
||||
deals.filter(deal => deal.status.id === overStatus.id)
|
||||
);
|
||||
const overDealIndex = statusDeals.findIndex(
|
||||
deal => deal.id === overDealId
|
||||
);
|
||||
|
||||
if (activeStatusId === overStatusId) {
|
||||
if (activeStatusId === overStatus.id) {
|
||||
const newLexorank = getNewRankForSameStatus(
|
||||
statusDeals,
|
||||
overDealIndex,
|
||||
activeDealId
|
||||
);
|
||||
return { overStatusId, newLexorank };
|
||||
return { overStatus, newLexorank };
|
||||
}
|
||||
|
||||
const newLexorank = getNewRankForAnotherStatus(
|
||||
statusDeals,
|
||||
overDealIndex
|
||||
);
|
||||
return { overStatusId, newLexorank };
|
||||
return { overStatus, newLexorank };
|
||||
};
|
||||
|
||||
const handleDragEnd = ({ active, over }: DragOverEvent) => {
|
||||
@ -215,9 +219,9 @@ const useDealsAndStatusesDnd = (): ReturnType => {
|
||||
if (typeof over.id === "string" && isStatusId(over.id)) {
|
||||
overStatusId = getStatusId(over.id);
|
||||
} else {
|
||||
const deal = deals.find(deal => deal.statusId === over.id);
|
||||
const deal = deals.find(deal => deal.status.id === over.id);
|
||||
if (!deal) return;
|
||||
overStatusId = deal.statusId;
|
||||
overStatusId = deal.status.id;
|
||||
}
|
||||
|
||||
if (!overStatusId) return;
|
||||
@ -237,15 +241,15 @@ const useDealsAndStatusesDnd = (): ReturnType => {
|
||||
const activeStatusId = getStatusByDealId(activeDealId)?.id;
|
||||
if (!activeStatusId) return;
|
||||
|
||||
const { overStatusId, newLexorank } = getDropTarget(
|
||||
const { overStatus, newLexorank } = getDropTarget(
|
||||
over.id,
|
||||
activeDealId,
|
||||
activeStatusId,
|
||||
true
|
||||
);
|
||||
if (!overStatusId) return;
|
||||
if (!overStatus) return;
|
||||
|
||||
onDealDragEnd(activeDealId, overStatusId, newLexorank);
|
||||
onDealDragEnd(activeDealId, overStatus.id, newLexorank);
|
||||
};
|
||||
|
||||
const onDealDragEnd = (
|
||||
|
||||
Reference in New Issue
Block a user