64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
"use client";
|
|||
|
|
|
||
|
|
import { useRouter } from "next/navigation";
|
||
|
|
import { useState } from "react";
|
||
|
|
|
||
|
|
import { BirthForm } from "@/app/profil/BirthForm";
|
||
|
|
import { api, errorText } from "@/lib/api";
|
||
|
|
|
||
|
|
/** The logged-in invitee: gives their own birth data if needed, then the comparison is made. */
|
||
|
|
export function AcceptInvite({ token, hasOwnChart }: { token: string; hasOwnChart: boolean }) {
|
||
|
|
const router = useRouter();
|
||
|
|
const [busy, setBusy] = useState(false);
|
||
|
|
const [error, setError] = useState<string | null>(null);
|
||
|
|
const [needsChart, setNeedsChart] = useState(!hasOwnChart);
|
||
|
|
|
||
|
|
async function accept() {
|
||
|
|
setBusy(true);
|
||
|
|
setError(null);
|
||
|
|
try {
|
||
|
|
const s = await api<{ id: string }>("/invites/accept", { body: { token } });
|
||
|
|
router.push(`/osszevetesek/${s.id}`);
|
||
|
|
router.refresh();
|
||
|
|
} catch (e) {
|
||
|
|
setError(errorText(e));
|
||
|
|
setBusy(false);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (needsChart) {
|
||
|
|
return (
|
||
|
|
<div className="field" style={{ gap: 12 }}>
|
||
|
|
<p>Add meg a születési adataidat: ebből készül a képleted, és ezt vetjük össze.</p>
|
||
|
|
<BirthForm
|
||
|
|
initial={null}
|
||
|
|
onSaved={() => {
|
||
|
|
setNeedsChart(false);
|
||
|
|
accept();
|
||
|
|
}}
|
||
|
|
/>
|
||
|
|
{error && (
|
||
|
|
<p className="msg msg-error" role="alert">
|
||
|
|
{error}
|
||
|
|
</p>
|
||
|
|
)}
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
return (
|
||
|
|
<div className="field" style={{ gap: 12 }}>
|
||
|
|
<p>A saját képleteddel vetjük össze.</p>
|
||
|
|
<div className="form-actions">
|
||
|
|
<button type="button" className="btn btn-primary" onClick={accept} disabled={busy}>
|
||
|
|
{busy ? "Készül az összevetés…" : "Összevetés elkészítése"}
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
{error && (
|
||
|
|
<p className="msg msg-error" role="alert">
|
||
|
|
{error}
|
||
|
|
</p>
|
||
|
|
)}
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|