Files
temetro/frontend/components/wallet/wallet-sync-step.tsx
T
Khalid Abdi 591b2f9170 frontend: center wallet-sync stepper and record-history timeline
Replace the bespoke left-aligned DialogStepper with the Origin UI Stepper
primitive (components/ui/stepper.tsx) so the numbered indicators sit centered
inline with their labels. Rebuild the patient sheet's Record History section as
a vertical Timeline (components/ui/timeline.tsx) showing the actor name, an
entity-type icon, the action, and the date, replacing the flat avatar list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 20:50:54 +03:00

136 lines
4.5 KiB
TypeScript

"use client";
import { Check, Loader2, Send, X } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { DialogFooter, DialogPanel } from "@/components/ui/dialog";
import {
Stepper,
StepperIndicator,
StepperItem,
StepperSeparator,
StepperTitle,
} from "@/components/ui/stepper";
import type { UseWalletSync } from "./use-wallet-sync";
// Two-step header shown at the top of a dialog when the selected patient has a
// linked wallet: "Details" → "Sync to wallet". Centered so the numbered
// indicators sit inline with their labels.
export function DialogStepper({ step }: { step: "form" | "wallet" }) {
const { t } = useTranslation();
const steps = [
{ value: 1, label: t("walletSync.step1") },
{ value: 2, label: t("walletSync.step2") },
];
const activeValue = step === "form" ? 1 : 2;
return (
<Stepper className="mx-auto mt-3 max-w-sm" value={activeValue}>
{steps.map(({ value, label }, i) => (
<StepperItem className="not-last:flex-1" key={value} step={value}>
<span className="inline-flex items-center gap-2">
<StepperIndicator />
<StepperTitle className="whitespace-nowrap text-xs">
{label}
</StepperTitle>
</span>
{i < steps.length - 1 && <StepperSeparator className="mx-3" />}
</StepperItem>
))}
</Stepper>
);
}
// Step 2 body + footer: offer to push the just-saved change to the patient's
// wallet, then show the approval status. Rendered in place of the form's
// DialogPanel/DialogFooter, so it returns them as a fragment.
export function WalletSyncStep({
patientName,
summary,
sync,
onDone,
}: {
patientName: string;
summary: string;
sync: UseWalletSync;
onDone: () => void;
}) {
const { t } = useTranslation();
const { state, update, error, push } = sync;
const status = update?.status ?? "pending";
return (
<>
<DialogPanel className="min-h-0 flex-1 overflow-y-auto">
{state === "idle" || state === "error" ? (
<div className="flex flex-col gap-4">
<div className="flex flex-col gap-1">
<p className="font-medium text-foreground text-sm">
{t("walletSync.prompt", { name: patientName })}
</p>
<p className="text-muted-foreground text-sm">
{t("walletSync.promptBody")}
</p>
</div>
<div className="flex flex-col gap-1.5">
<span className="text-muted-foreground text-xs">
{t("walletSync.changesLabel")}
</span>
<div className="rounded-lg border bg-muted/50 px-3 py-2 text-foreground text-sm">
{summary}
</div>
</div>
{error && (
<p className="text-destructive text-sm" role="alert">
{error === "generic" ? t("walletSync.errors.generic") : error}
</p>
)}
</div>
) : (
<div className="flex flex-col items-center gap-4 py-6 text-center">
{status === "approved" ? (
<div className="flex size-12 items-center justify-center rounded-full bg-success/15 text-success">
<Check className="size-6" />
</div>
) : status === "denied" ? (
<div className="flex size-12 items-center justify-center rounded-full bg-destructive/15 text-destructive">
<X className="size-6" />
</div>
) : (
<Loader2 className="size-8 animate-spin text-muted-foreground" />
)}
<div className="flex flex-col gap-1">
<p className="font-medium text-foreground text-sm">
{t(`walletPush.status.${status}.title`)}
</p>
<p className="text-muted-foreground text-sm">
{t(`walletPush.status.${status}.body`)}
</p>
</div>
</div>
)}
</DialogPanel>
<DialogFooter>
{state === "idle" || state === "error" ? (
<>
<Button onClick={onDone} type="button" variant="outline">
{t("walletSync.skip")}
</Button>
<Button onClick={() => push([summary])} type="button">
<Send className="size-4" />
{t("walletSync.send")}
</Button>
</>
) : (
<Button onClick={onDone} type="button">
{t("walletSync.done")}
</Button>
)}
</DialogFooter>
</>
);
}