All files / src/components HomeRegisterCta.tsx

92.3% Statements 12/13
100% Branches 2/2
75% Functions 3/4
92.3% Lines 12/13

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 903x                                         50x 50x 50x   50x       1x 1x 1x       1x 1x     50x       9x                                                                                            
"use client";
 
/**
 * Homepage hero CTA cluster. "Register with d-you" opens the RegisterDialog.
 * On the hub its QR code is a real wallet request (sign in to your own
 * account, or create one from your PID) and its simulated phone signs in as
 * the demo patient; both land on /patient with a session. In the static
 * export there is no session, so approving the phone sets the demo persona
 * in the browser instead. The other two links (journey explainer,
 * returning-user sign-in) are unchanged.
 */
import { useState } from "react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { ScanLine, ArrowRight, Info } from "lucide-react";
import { RegisterDialog } from "@/components/RegisterDialog";
import { setDemoPersona } from "@/lib/use-demo-persona";
import { CITIZEN_WALLET } from "@/lib/wallet-config";
import { useT } from "@/lib/i18n/translate";
 
export function HomeRegisterCta() {
  const [open, setOpen] = useState(false);
  const t = useT("home");
  const router = useRouter();
 
  const onComplete = () => {
    // Static export only: no session exists there, so the demo patient is a
    // persona in the browser (sessionStorage drives the nav, localStorage
    // drives the restricted /api/patient mock, see lib/api.ts).
    setDemoPersona("patient1");
    try {
      localStorage.setItem("demo-persona", "patient1");
    } catch {
      /* storage unavailable — non-fatal for the visual demo */
    }
    setOpen(false);
    router.push("/patient");
  };
 
  return (
    <div className="mt-7 flex flex-wrap items-center gap-x-5 gap-y-3">
      <button
        type="button"
        onClick={() => setOpen(true)}
        className="group inline-flex items-center gap-2.5 px-6 py-3.5 rounded-xl text-white font-semibold text-base shadow-md transition-all hover:scale-[1.02]"
        style={{ background: "linear-gradient(135deg,#7D3C98,#2471A3)" }}
      >
        <ScanLine size={20} aria-hidden="true" />
        {t("Register with {wallet}", { wallet: CITIZEN_WALLET.name })}
        <ArrowRight
          size={18}
          aria-hidden="true"
          className="group-hover:translate-x-1 transition-transform"
        />
      </button>
      <Link
        href="/journey"
        title={t(
          "Passwordless and sovereign: no email or password. You approve on your phone and share only the exact claims requested. Tap to see the full patient journey.",
        )}
        className="inline-flex items-center gap-1.5 text-sm font-medium text-(--accent) hover:underline"
      >
        <Info size={15} aria-hidden="true" />
        {t("Why the patient journey needs an EUDI wallet")}
      </Link>
      <Link
        href="/auth/eudi-qr?mode=login"
        className="inline-flex items-center gap-1.5 text-sm font-medium text-(--text-secondary) hover:text-(--accent) transition-colors"
      >
        {t("Already have it? Sign in")}{" "}
        <ArrowRight size={14} aria-hidden="true" />
      </Link>
 
      {open && (
        <RegisterDialog
          mode="register"
          title={t("Register in the European Health Data Space")}
          subtitle={t(
            "Create your EHDS patient account with {wallet}, the German EUDI wallet. You share only the claims requested: your name and date of birth, which the hub keeps only as a secure hash.",
            { wallet: CITIZEN_WALLET.name },
          )}
          callbackUrl="/patient"
          onClose={() => setOpen(false)}
          onComplete={onComplete}
        />
      )}
    </div>
  );
}