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
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,22 @@ export class ReferenceController {
res.status(500).json({ error: "Internal server error" });
}
};

deleteReference = async (req: Request, res: Response) => {
try {
const { referenceId } = req.params;
const userId = req.user!.id;

const deleted = await this.referenceService.deleteReference(referenceId, userId);

if (!deleted) {
return res.status(404).json({ error: "Reference not found or not authorized" });
}

res.json({ message: "Reference deleted successfully" });
} catch (error) {
console.error("Error deleting reference:", error);
res.status(500).json({ error: "Internal server error" });
}
};
}
1 change: 1 addition & 0 deletions platforms/ereputation/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ app.get("/api/references/target/:targetType/:targetId", referenceController.getR
app.get("/api/references/my", authGuard, referenceController.getUserReferences);
app.get("/api/references", authGuard, referenceController.getAllUserReferences);
app.patch("/api/references/:referenceId/revoke", authGuard, referenceController.revokeReference);
app.delete("/api/references/:referenceId", authGuard, referenceController.deleteReference);

// Reference signing routes
app.post("/api/references/signing/session", authGuard, referenceSigningController.createSigningSession.bind(referenceSigningController));
Expand Down
17 changes: 17 additions & 0 deletions platforms/ereputation/api/src/services/ReferenceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,21 @@ export class ReferenceService {
reference.status = "revoked";
return await this.referenceRepository.save(reference);
}

async deleteReference(referenceId: string, authorId: string): Promise<boolean> {
const reference = await this.referenceRepository.findOne({
where: { id: referenceId, authorId }
});

if (!reference) {
return false;
}

await AppDataSource.manager.transaction(async (manager) => {
await manager.delete("ReferenceSignature", { referenceId });
await manager.remove(reference);
});

return true;
}
}
107 changes: 105 additions & 2 deletions platforms/ereputation/client/client/src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { useAuth } from "@/hooks/useAuth";
import { clearAuth } from "@/lib/authUtils";
import { clearAuth, isUnauthorizedError } from "@/lib/authUtils";
import { apiClient } from "@/lib/apiClient";
import { useToast } from "@/hooks/use-toast";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
Expand All @@ -16,20 +17,24 @@ import {
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
} from "@/components/ui/dialog";
import OtherCalculationModal from "@/components/modals/other-calculation-modal";
import ReferenceModal from "@/components/modals/reference-modal";
import ReferenceViewModal from "@/components/modals/reference-view-modal";

export default function Dashboard() {
const { user, isAuthenticated, isLoading } = useAuth();
const { toast } = useToast();
const queryClient = useQueryClient();
const [otherModalOpen, setOtherModalOpen] = useState(false);
const [referenceModalOpen, setReferenceModalOpen] = useState(false);
const [viewModalOpen, setViewModalOpen] = useState(false);
const [selectedActivity, setSelectedActivity] = useState(null);
const [referenceViewModal, setReferenceViewModal] = useState<any>(null);
const [activeFilter, setActiveFilter] = useState<string>('all');
const [currentPage, setCurrentPage] = useState(1);
const [deleteModalOpen, setDeleteModalOpen] = useState<any>(null);

// This page is only rendered when authenticated, no need for redirect logic

Expand Down Expand Up @@ -72,6 +77,48 @@ export default function Dashboard() {
window.location.href = "/";
};

// Delete reference mutation
const deleteMutation = useMutation({
mutationFn: async (referenceId: string) => {
return await apiClient.delete(`/api/references/${referenceId}`);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["/api/dashboard/activities"] });
queryClient.invalidateQueries({ queryKey: ["/api/dashboard/stats"] });
toast({
title: "Reference Deleted",
description: "The reference has been successfully deleted.",
});
setDeleteModalOpen(null);
},
onError: (error) => {
if (isUnauthorizedError(error)) {
toast({
title: "Unauthorized",
description: "You are logged out. Logging in again...",
variant: "destructive",
});
setTimeout(() => {
window.location.href = "/";
}, 500);
return;
}
toast({
title: "Error",
description: "Failed to delete reference. Please try again.",
variant: "destructive",
});
},
});

const confirmDeleteActivity = () => {
if (deleteModalOpen) {
// Activity IDs are prefixed (e.g. "ref-sent-<uuid>"), extract the actual reference UUID
const referenceId = deleteModalOpen.id.replace(/^ref-(sent|received)-/, '');
deleteMutation.mutate(referenceId);
}
};

const handleViewActivity = (activity: any) => {
// For reference activities, show reference details modal
if (activity.type === 'reference' || activity.activity === 'Reference Provided' || activity.activity === 'Reference Received') {
Expand Down Expand Up @@ -580,6 +627,17 @@ export default function Dashboard() {
</svg>
View Details
</DropdownMenuItem>
{activity.activity === 'Reference Provided' && (
<DropdownMenuItem
className="text-red-600"
onClick={() => setDeleteModalOpen(activity)}
>
<svg className="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 20 20">
<path fillRule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clipRule="evenodd" />
</svg>
Delete
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
</td>
Expand Down Expand Up @@ -626,6 +684,17 @@ export default function Dashboard() {
</svg>
View Details
</DropdownMenuItem>
{activity.activity === 'Reference Provided' && (
<DropdownMenuItem
className="text-red-600"
onClick={() => setDeleteModalOpen(activity)}
>
<svg className="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 20 20">
<path fillRule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clipRule="evenodd" />
</svg>
Delete
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
<div className="flex items-center gap-2">
Expand Down Expand Up @@ -915,6 +984,40 @@ export default function Dashboard() {
) : null}
</DialogContent>
</Dialog>

{/* Delete Reference Confirmation Modal */}
<Dialog open={!!deleteModalOpen} onOpenChange={(open) => !open && setDeleteModalOpen(null)}>
<DialogContent className="w-full max-w-sm sm:max-w-md mx-4 sm:mx-auto bg-fig-10 border-2 border-fig/20 shadow-2xl rounded-xl">
<DialogHeader className="text-center">
<div className="mx-auto w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mb-4">
<svg className="w-8 h-8 text-red-600" fill="currentColor" viewBox="0 0 20 20">
<path fillRule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clipRule="evenodd" />
</svg>
</div>
<DialogTitle className="text-xl font-black text-fig">Delete Reference</DialogTitle>
<DialogDescription className="text-fig/70 text-sm font-medium mt-2">
Are you sure you want to permanently delete the reference for <strong>{deleteModalOpen?.target}</strong>? This action cannot be undone.
</DialogDescription>
</DialogHeader>

<div className="flex gap-3 mt-6">
<Button
variant="outline"
onClick={() => setDeleteModalOpen(null)}
className="flex-1 border-2 border-fig/30 text-fig/70 hover:bg-fig-10 hover:border-fig/40 font-bold h-11"
>
Cancel
</Button>
<Button
onClick={confirmDeleteActivity}
disabled={deleteMutation.isPending}
className="flex-1 bg-red-600 hover:bg-red-700 text-white font-bold h-11"
>
{deleteMutation.isPending ? 'Deleting...' : 'Delete'}
</Button>
</div>
</DialogContent>
</Dialog>
</div>
);
}