Skip to content
Merged
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
52 changes: 45 additions & 7 deletions apps/desktop/src/components/finder/views/contact-view.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RiCornerDownLeftLine } from "@remixicon/react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Building2, CircleMinus, FileText, Pencil, Plus, SearchIcon, User } from "lucide-react";
import { Building2, CircleMinus, FileText, Pencil, Plus, SearchIcon, TrashIcon, User } from "lucide-react";
import { useEffect, useRef, useState } from "react";

import { commands as dbCommands } from "@hypr/plugin-db";
Expand Down Expand Up @@ -130,6 +130,27 @@ export function ContactView({ userId, initialPersonId, initialOrgId }: ContactVi
setEditingOrg(organizationId);
};

const deletePersonMutation = useMutation({
mutationFn: (personId: string) => dbCommands.deleteHuman(personId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["all-people"] });
queryClient.invalidateQueries({ queryKey: ["organization-members"] });

if (selectedPerson === selectedPersonData?.id) {
setSelectedPerson(null);
}
},
});

const handleDeletePerson = async (personId: string) => {
const userConfirmed = await confirm(
"Are you sure you want to delete this contact? This action cannot be undone.",
);
if (userConfirmed) {
deletePersonMutation.mutate(personId);
}
};

return (
<div className="flex h-full">
<div className="w-[200px] border-r border-neutral-200 flex flex-col">
Expand Down Expand Up @@ -295,12 +316,29 @@ export function ContactView({ userId, initialPersonId, initialOrgId }: ContactVi
<OrganizationInfo organizationId={selectedPersonData.organization_id} />
)}
</div>
<button
onClick={() => handleEditPerson(selectedPersonData.id)}
className="p-2 rounded-md hover:bg-neutral-100 transition-colors"
>
<Pencil className="h-4 w-4 text-neutral-500" />
</button>
<div className="flex gap-2">
<button
onClick={() => handleEditPerson(selectedPersonData.id)}
className="p-2 rounded-md hover:bg-neutral-100 transition-colors"
title="Edit contact"
>
<Pencil className="h-4 w-4 text-neutral-500" />
</button>
{!selectedPersonData.is_user && (
<button
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
handleDeletePerson(selectedPersonData.id);
}}
className="p-2 rounded-md hover:bg-red-50 transition-colors"
disabled={deletePersonMutation.isPending}
title="Delete contact"
>
<TrashIcon className="h-4 w-4 text-red-500 hover:text-red-600" />
</button>
)}
</div>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions plugins/db/js/bindings.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ async upsertHuman(human: Human) : Promise<Human> {
async listHumans(filter: ListHumanFilter | null) : Promise<Human[]> {
return await TAURI_INVOKE("plugin:db|list_humans", { filter });
},
async deleteHuman(id: string) : Promise<null> {
return await TAURI_INVOKE("plugin:db|delete_human", { id });
},
async getOrganization(id: string) : Promise<Organization | null> {
return await TAURI_INVOKE("plugin:db|get_organization", { id });
},
Expand Down
1 change: 1 addition & 0 deletions plugins/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fn make_specta_builder<R: tauri::Runtime>() -> tauri_specta::Builder<R> {
commands::humans::get_human,
commands::humans::upsert_human,
commands::humans::list_humans,
commands::humans::delete_human,
commands::organizations::get_organization,
commands::organizations::get_organization_by_user_id,
commands::organizations::upsert_organization,
Expand Down
Loading