54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
||
import { useParams } from "react-router-dom";
|
||
import { api } from "../api";
|
||
import { EmptyState, ErrorState, LoadingState } from "../components/State";
|
||
|
||
export function CandidateDetailPage() {
|
||
const { projectId = "", candidateId = "" } = useParams();
|
||
const detail = useQuery({
|
||
queryKey: ["candidate", projectId, candidateId],
|
||
queryFn: () => api.candidate(projectId, candidateId),
|
||
});
|
||
const history = useQuery({
|
||
queryKey: ["observations", projectId, candidateId],
|
||
queryFn: () => api.observations(projectId, candidateId),
|
||
});
|
||
if (detail.isLoading) return <LoadingState />;
|
||
if (detail.isError) return <ErrorState message={(detail.error as Error).message} />;
|
||
const item = detail.data!;
|
||
return (
|
||
<section className="grid">
|
||
<h1>{item.title}</h1>
|
||
<div className="card">
|
||
<p>
|
||
{item.manufacturer} {item.model}
|
||
</p>
|
||
<p>
|
||
Preis: {item.current_best_price || "–"} {item.currency || ""}
|
||
</p>
|
||
<p>Ranking: {item.ranking_status}</p>
|
||
<p>Diff: {item.current_diff_status}</p>
|
||
<p>Lifecycle: {item.product_lifecycle_status}</p>
|
||
</div>
|
||
<div className="card">
|
||
<h2>Attribute</h2>
|
||
{(item.current_dynamic_attributes || []).map((attr) => (
|
||
<p key={attr.raw_name}>
|
||
{attr.raw_name}: {String(attr.normalized_value ?? "")} {attr.unit || ""}
|
||
</p>
|
||
))}
|
||
</div>
|
||
<div className="card">
|
||
<h2>Historie</h2>
|
||
{history.isLoading ? <LoadingState /> : null}
|
||
{(history.data?.items || []).length === 0 ? <EmptyState>Noch keine Beobachtungen.</EmptyState> : null}
|
||
{(history.data?.items || []).map((obs) => (
|
||
<p key={obs.observation_id}>
|
||
{obs.observed_at}: {obs.best_price} {obs.currency}
|
||
</p>
|
||
))}
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|