Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/backend/src/app/leads/leads.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,15 @@ export class LeadsController {
) {
return this.leadsService.convert(id, organizationId);
}

@Post(':id/revert')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Revert converted lead back to replied status' })
@ApiParam({ name: 'id', type: Number })
revert(
@OrgId() organizationId: number,
@Param('id', ParseIntPipe) id: number,
) {
return this.leadsService.revert(id, organizationId);
}
}
9 changes: 9 additions & 0 deletions apps/backend/src/app/leads/leads.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ export class LeadsService {
return this.leadsRepository.delete(id);
}

async revert(id: number, organizationId: number) {
await this.findById(id, organizationId);
return this.leadsRepository.update(id, {
status: 'replied',
dealId: null,
contactId: null,
});
}

async convert(id: number, organizationId: number) {
const lead = await this.findById(id, organizationId);

Expand Down
53 changes: 33 additions & 20 deletions apps/web/src/components/Leads/LeadsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ const LeadsList = () => {
onError: () => toast.error('Failed to convert lead'),
});

const { mutate: revertLead } = useMutation({
mutationFn: (id: number) => leadsApi.revert(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['leads'] });
toast.success('Lead reverted');
},
onError: () => toast.error('Failed to revert lead'),
});

const leads = leadsData?.pages.flatMap((p) => p.data) ?? [];
const metadata = leadsData?.pages[0]?.metadata ?? [];
const totalCount = leadsData?.pages[0]?.pagination?.total;
Expand All @@ -79,27 +88,31 @@ const LeadsList = () => {
() => ({
id: 'actions',
header: 'Actions',
cell: ({ row }) => (
<TableActions>
<Button
plain
className="text-xs"
onClick={() => convertLead(Number(row.original.id))}
disabled={
(row.original as unknown as Record<string, unknown>)['status'] ===
'converted'
}
>
→ Deal
</Button>
<DeleteAction
onClick={() => setLeadToDelete(Number(row.original.id))}
disabled={isDeleting}
/>
</TableActions>
),
cell: ({ row }) => {
const status = (row.original as unknown as Record<string, unknown>)[
'status'
] as string;
const id = Number(row.original.id);
return (
<TableActions>
{status === 'converted' ? (
<Button plain className="text-xs" onClick={() => revertLead(id)}>
← Revert
</Button>
) : (
<Button plain className="text-xs" onClick={() => convertLead(id)}>
→ Deal
</Button>
)}
<DeleteAction
onClick={() => setLeadToDelete(id)}
disabled={isDeleting}
/>
</TableActions>
);
},
}),
[convertLead, isDeleting],
[convertLead, revertLead, isDeleting],
);

const icpProfileColumn: ColumnDef<BaseRow> = useMemo(
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/lib/api/leads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ export const leadsApi = {
return apiClient.post(`/leads/${id}/convert`, {});
},

async revert(id: number): Promise<Lead> {
return apiClient.post(`/leads/${id}/revert`, {});
},

async getTableViewLeads(filters?: {
search?: string;
status?: string;
Expand Down
Loading