Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | 3x 11x 8x 8x 10x 10x 10x 10x 10x 4x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 10x | "use client";
import { useEffect, useState } from "react";
import { CalendarClock, Download, KeyRound, Loader2 } from "lucide-react";
import { fetchApi } from "@/lib/api";
import type { AgreementView } from "@/lib/agreement";
import OfferTerms from "@/components/OfferTerms";
import { useT } from "@/lib/i18n/translate";
/** A date and time in the reader's locale, or a dash. */
function when(iso: string | number | undefined): string {
if (!iso) return "—";
const d = new Date(iso);
return Number.isNaN(d.getTime())
? "—"
: d.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
}
/**
* What a data user asks about an open transfer (#876): since when the data
* can be fetched, until when, how, and under which policy. The agreement
* comes from the connector (api/agreements/[id]); the period is the agreed
* policy's, counted from the signing.
*/
export default function TransferDetails({
participantId,
contractId,
openedAt,
providerDid,
providerName,
consumerName,
sample = false,
}: {
participantId: string;
contractId: string;
/** When the transfer reached STARTED: from then the data can be fetched. */
openedAt: number;
providerDid: string;
providerName: string;
consumerName: string;
/** A sample agreement from the fixtures: the connector holds no record. */
sample?: boolean;
}) {
const t = useT("research");
const [agreement, setAgreement] = useState<AgreementView | null>(null);
const [error, setError] = useState("");
const [loading, setLoading] = useState(true);
useEffect(() => {
if (sample) {
setLoading(false);
return;
}
let live = true;
fetchApi(
`/api/agreements/${encodeURIComponent(
contractId,
)}?participantId=${encodeURIComponent(participantId)}`,
)
.then(async (r) => {
const body = await r.json();
Iif (!live) return;
if (r.ok) setAgreement(body as AgreementView);
else EsetError(String(body.detail || body.error || r.status));
})
.catch((e) => live && setError(String(e)))
.finally(() => live && setLoading(false));
return () => {
live = false;
};
}, [contractId, participantId, sample]);
return (
<div
data-testid="transfer-details"
className="mt-3 space-y-4 rounded-lg border border-(--border) bg-(--surface)/60 p-4 text-sm"
>
<dl className="grid grid-cols-1 sm:grid-cols-3 gap-3">
<div>
<dt className="text-[10px] uppercase tracking-wide text-(--text-secondary)">
{t("Access open since")}
</dt>
<dd data-testid="transfer-opened" className="text-(--text-primary)">
{openedAt ? when(openedAt) : t("no open transfer")}
</dd>
</div>
<div>
<dt className="text-[10px] uppercase tracking-wide text-(--text-secondary)">
{t("Contract signed")}
</dt>
<dd className="text-(--text-primary)">
{loading ? "…" : when(agreement?.signedAt)}
</dd>
</div>
<div>
<dt className="text-[10px] uppercase tracking-wide text-(--text-secondary)">
{t("Usable until")}
</dt>
<dd data-testid="transfer-until" className="text-(--text-primary)">
{loading
? "…"
: agreement?.validUntil
? when(agreement.validUntil)
: t("no end date in the contract")}
</dd>
</div>
</dl>
<div className="space-y-1">
<p className="flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-(--text-secondary)">
<Download size={14} />
{t("How to get the data")}
</p>
<p className="text-(--text-primary)">
{t(
"Open shows the data here; Download saves it as a JSON file. Each time, the hub fetches it from {provider}'s data plane with a short-lived token your connector holds; the token never reaches your browser.",
{ provider: providerName },
)}
</p>
<p className="flex items-start gap-1.5 text-xs text-(--text-secondary)">
<CalendarClock size={14} className="mt-0.5 shrink-0" />
{t(
"The access stays open until the transfer is completed or ended, or the contract period runs out; after that a new negotiation is needed.",
)}
</p>
</div>
<div className="space-y-1">
<p className="flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-(--text-secondary)">
<KeyRound size={14} />
{t("Access policy")}
</p>
<p className="text-(--text-primary)">
{t(
"{provider} decides who may see the offer at all. {consumer} saw it, so its connector met that policy, proving its membership with its credentials (DCP); the provider does not disclose the policy itself.",
{ provider: providerName, consumer: consumerName },
)}
</p>
</div>
{loading ? (
<p className="flex items-center gap-2 text-(--text-secondary)">
<Loader2 size={14} className="animate-spin" />
{t("Loading the agreement…")}
</p>
) : sample ? (
<p className="text-xs text-(--text-secondary)">
{t(
"A sample agreement from the demonstrator's fixtures: the connector holds no record of it, so there is no signed policy to show.",
)}
</p>
) : agreement ? (
<OfferTerms
agreed
policy={agreement.policy}
providerDid={providerDid}
providerName={providerName}
consumerName={consumerName}
/>
) : (
<p className="text-xs text-(--badge-inactive-text)">
{t("The agreement could not be read: {detail}", { detail: error })}
</p>
)}
</div>
);
}
|