feat: purchase-plans update
This commit is contained in:
@@ -19,7 +19,7 @@ import {
|
||||
} from "lucide-react";
|
||||
import { DashboardHeader } from "@/components/layout/dashboard-header";
|
||||
import { useWorkspace } from "@/components/providers/workspace-provider";
|
||||
import { placementsApi } from "@/lib/api";
|
||||
import { placementsApi, projectsApi } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
@@ -94,13 +94,35 @@ export default function PlacementDetailPage() {
|
||||
const loadPlacement = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
// First, try to load placement without project_id (deprecated endpoint)
|
||||
// If that fails, we'd need projectId
|
||||
const data = await placementsApi.get(workspaceId, placementId);
|
||||
setPlacement(data);
|
||||
// Store projectId from placement for future operations
|
||||
if (data.project?.id) {
|
||||
setProjectId(data.project.id);
|
||||
|
||||
// First, get all projects to find which project this placement belongs to
|
||||
const projectsResponse = await projectsApi.list(workspaceId, { size: 100 });
|
||||
const projects = projectsResponse.items;
|
||||
|
||||
// Search for the placement in all projects
|
||||
let foundProjectId: string | null = null;
|
||||
let foundPlacement: any = null;
|
||||
|
||||
for (const project of projects) {
|
||||
try {
|
||||
const placements = await placementsApi.getByProject(workspaceId, project.id);
|
||||
const placement = placements.find((p) => p.id === placementId);
|
||||
if (placement) {
|
||||
foundProjectId = project.id;
|
||||
foundPlacement = placement;
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
// Skip if can't get placements for this project
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundPlacement) {
|
||||
setPlacement(foundPlacement);
|
||||
setProjectId(foundProjectId);
|
||||
} else {
|
||||
console.error("Placement not found in any project");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to load placement:", err);
|
||||
|
||||
Reference in New Issue
Block a user