fix(portal): password validation, Report Cards retry, and X-Impersonation-Session-Id headers (GRO-286, GRO-287) #174

Closed
groombook-engineer[bot] wants to merge 6 commits from fix/portal-password-validation-report-cards-retry into main
7 changed files with 466 additions and 125 deletions
+2 -1
View File
@@ -245,7 +245,8 @@ export function App() {
} }
// Dev mode: use dev login selector (no setup check needed in dev mode) // Dev mode: use dev login selector (no setup check needed in dev mode)
if (authDisabled && !getDevUser()) { // Skip redirect if user explicitly chose "continue as default dev user" (dev-login-skipped flag)
if (authDisabled && !getDevUser() && !localStorage.getItem("dev-login-skipped")) {
return <Navigate to="/login" replace />; return <Navigate to="/login" replace />;
} }
+1
View File
@@ -39,6 +39,7 @@ export function DevLoginSelector() {
function skipLogin() { function skipLogin() {
localStorage.removeItem("dev-user"); localStorage.removeItem("dev-user");
localStorage.setItem("dev-login-skipped", "1");
navigate("/admin"); navigate("/admin");
} }
+1 -1
View File
@@ -133,7 +133,7 @@ export function CustomerPortal() {
case "pets": case "pets":
return <PetProfiles readOnly={!!isReadOnly} sessionId={sessionId} />; return <PetProfiles readOnly={!!isReadOnly} sessionId={sessionId} />;
case "reports": case "reports":
return <ReportCards />; return <ReportCards sessionId={sessionId} />;
case "billing": case "billing":
return <BillingPayments readOnly={!!isReadOnly} sessionId={sessionId} />; return <BillingPayments readOnly={!!isReadOnly} sessionId={sessionId} />;
case "messages": case "messages":
@@ -72,7 +72,9 @@ function PersonalInfo({ sessionId, readOnly }: { sessionId: string | null; readO
const fetchPersonalInfo = async () => { const fetchPersonalInfo = async () => {
try { try {
setLoading(true); setLoading(true);
const response = await fetch("/api/portal/me"); const response = await fetch("/api/portal/me", {
headers: { "X-Impersonation-Session-Id": sessionId },
});
if (response.ok) { if (response.ok) {
const data: PersonalInfoData = await response.json(); const data: PersonalInfoData = await response.json();
setForm({ setForm({
@@ -142,6 +144,47 @@ function PersonalInfo({ sessionId, readOnly }: { sessionId: string | null; readO
} }
function PasswordChange({ readOnly }: { readOnly: boolean }) { function PasswordChange({ readOnly }: { readOnly: boolean }) {
const [currentPassword, setCurrentPassword] = useState("");
const [newPassword, setNewPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
const [validationError, setValidationError] = useState<string | null>(null);
const [submitting, setSubmitting] = useState(false);
const passwordsMatch = newPassword === confirmPassword;
const canSubmit =
!readOnly &&
currentPassword.length > 0 &&
newPassword.length > 0 &&
confirmPassword.length > 0 &&
passwordsMatch;
const handleSubmit = async () => {
setValidationError(null);
if (!passwordsMatch) {
setValidationError("Passwords do not match.");
return;
}
if (newPassword.length === 0 || confirmPassword.length === 0) {
setValidationError("All fields are required.");
return;
}
setSubmitting(true);
// TODO: wire up to actual password-change API endpoint (e.g., POST /api/portal/password)
// const response = await fetch("/api/portal/password", { ... });
setTimeout(() => {
setSubmitting(false);
setCurrentPassword("");
setNewPassword("");
setConfirmPassword("");
// On success, clear error and show confirmation (API integration needed first)
}, 500);
};
if (readOnly) { if (readOnly) {
return ( return (
<div className="bg-white rounded-2xl border border-stone-200 p-5 shadow-sm"> <div className="bg-white rounded-2xl border border-stone-200 p-5 shadow-sm">
@@ -156,18 +199,44 @@ function PasswordChange({ readOnly }: { readOnly: boolean }) {
<div className="space-y-4 max-w-md"> <div className="space-y-4 max-w-md">
<div> <div>
<label className="block text-sm font-medium text-stone-700 mb-1">Current Password</label> <label className="block text-sm font-medium text-stone-700 mb-1">Current Password</label>
<input type="password" className="w-full border border-stone-300 rounded-lg px-3 py-2 text-sm" /> <input
type="password"
value={currentPassword}
onChange={e => setCurrentPassword(e.target.value)}
className="w-full border border-stone-300 rounded-lg px-3 py-2 text-sm"
/>
</div> </div>
<div> <div>
<label className="block text-sm font-medium text-stone-700 mb-1">New Password</label> <label className="block text-sm font-medium text-stone-700 mb-1">New Password</label>
<input type="password" className="w-full border border-stone-300 rounded-lg px-3 py-2 text-sm" /> <input
type="password"
value={newPassword}
onChange={e => { setNewPassword(e.target.value); setValidationError(null); }}
className="w-full border border-stone-300 rounded-lg px-3 py-2 text-sm"
/>
</div> </div>
<div> <div>
<label className="block text-sm font-medium text-stone-700 mb-1">Confirm New Password</label> <label className="block text-sm font-medium text-stone-700 mb-1">Confirm New Password</label>
<input type="password" className="w-full border border-stone-300 rounded-lg px-3 py-2 text-sm" /> <input
type="password"
value={confirmPassword}
onChange={e => { setConfirmPassword(e.target.value); setValidationError(null); }}
className="w-full border border-stone-300 rounded-lg px-3 py-2 text-sm"
/>
</div> </div>
<button className="px-4 py-2 bg-(--color-accent) text-white rounded-lg text-sm font-medium hover:bg-(--color-accent-hover)"> {validationError && (
Update Password <p className="text-sm text-red-500">{validationError}</p>
)}
<button
onClick={handleSubmit}
disabled={!canSubmit || submitting}
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
canSubmit && !submitting
? "bg-(--color-accent) text-white hover:bg-(--color-accent-hover)"
: "bg-stone-100 text-stone-400 cursor-not-allowed"
}`}
>
{submitting ? "Updating..." : "Update Password"}
</button> </button>
</div> </div>
</div> </div>
@@ -185,7 +254,9 @@ function ManagePets({ sessionId, readOnly }: { sessionId: string | null; readOnl
const fetchPets = async () => { const fetchPets = async () => {
try { try {
setLoading(true); setLoading(true);
const response = await fetch("/api/portal/pets"); const response = await fetch("/api/portal/pets", {
headers: { "X-Impersonation-Session-Id": sessionId },
});
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
setPets(Array.isArray(data) ? data : []); setPets(Array.isArray(data) ? data : []);
@@ -225,7 +296,6 @@ function ManagePets({ sessionId, readOnly }: { sessionId: string | null; readOnl
<PetForm <PetForm
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
pet={(editingPet ?? undefined) as any} pet={(editingPet ?? undefined) as any}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onSave={() => { setEditingPetId(null); setShowAddForm(false); }} onSave={() => { setEditingPetId(null); setShowAddForm(false); }}
onCancel={() => { setEditingPetId(null); setShowAddForm(false); }} onCancel={() => { setEditingPetId(null); setShowAddForm(false); }}
/> />
@@ -118,7 +118,7 @@ export const AppointmentsSection: React.FC<AppointmentsSectionProps> = ({ sessio
try { try {
const response = await fetch('/api/portal/appointments', { const response = await fetch('/api/portal/appointments', {
headers: { Authorization: `Bearer ${sessionId}` }, headers: { "X-Impersonation-Session-Id": sessionId ?? "" },
}); });
if (response.ok) { if (response.ok) {
@@ -379,7 +379,7 @@ export function ConfirmationSection({
try { try {
const headers: Record<string, string> = {}; const headers: Record<string, string> = {};
if (sessionId) { if (sessionId) {
headers['Authorization'] = `Bearer ${sessionId}`; headers['X-Impersonation-Session-Id'] = sessionId;
} }
const res = await fetch(`/api/portal/appointments/${appt.id}/confirm`, { const res = await fetch(`/api/portal/appointments/${appt.id}/confirm`, {
method: 'POST', method: 'POST',
@@ -455,7 +455,7 @@ function CancelAppointmentButton({
try { try {
const headers: Record<string, string> = {}; const headers: Record<string, string> = {};
if (sessionId) { if (sessionId) {
headers['Authorization'] = `Bearer ${sessionId}`; headers['X-Impersonation-Session-Id'] = sessionId;
} }
const res = await fetch(`/api/portal/appointments/${appt.id}/cancel`, { const res = await fetch(`/api/portal/appointments/${appt.id}/cancel`, {
method: 'POST', method: 'POST',
@@ -507,7 +507,7 @@ export function CustomerNotesSection({
try { try {
const headers: Record<string, string> = { 'Content-Type': 'application/json' }; const headers: Record<string, string> = { 'Content-Type': 'application/json' };
if (sessionId) { if (sessionId) {
headers['Authorization'] = `Bearer ${sessionId}`; headers['X-Impersonation-Session-Id'] = sessionId;
} }
const res = await fetch(`/api/portal/appointments/${appt.id}/notes`, { const res = await fetch(`/api/portal/appointments/${appt.id}/notes`, {
method: 'PATCH', method: 'PATCH',
@@ -600,7 +600,7 @@ export function RescheduleFlow({
setError(null); setError(null);
try { try {
const headers: Record<string, string> = { 'Content-Type': 'application/json' }; const headers: Record<string, string> = { 'Content-Type': 'application/json' };
if (sessionId) headers['Authorization'] = `Bearer ${sessionId}`; if (sessionId) headers['X-Impersonation-Session-Id'] = sessionId;
const res = await fetch(`/api/portal/appointments/${appt.id}/reschedule`, { const res = await fetch(`/api/portal/appointments/${appt.id}/reschedule`, {
method: 'POST', method: 'POST',
headers, headers,
@@ -744,10 +744,10 @@ function BookingFlow({ onClose, sessionId }: BookingFlowProps) {
try { try {
const [petsRes, servicesRes] = await Promise.all([ const [petsRes, servicesRes] = await Promise.all([
fetch('/api/portal/pets', { fetch('/api/portal/pets', {
headers: { Authorization: `Bearer ${sessionId}` }, headers: { "X-Impersonation-Session-Id": sessionId ?? "" },
}), }),
fetch('/api/portal/services', { fetch('/api/portal/services', {
headers: { Authorization: `Bearer ${sessionId}` }, headers: { "X-Impersonation-Session-Id": sessionId ?? "" },
}), }),
]); ]);
@@ -784,7 +784,7 @@ function BookingFlow({ onClose, sessionId }: BookingFlowProps) {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization: `Bearer ${sessionId}`, "X-Impersonation-Session-Id": sessionId ?? "",
}, },
body: JSON.stringify({ body: JSON.stringify({
petId: selectedPet.id, petId: selectedPet.id,
+340 -84
View File
@@ -1,4 +1,5 @@
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { CreditCard, DollarSign, Package, Zap } from "lucide-react";
interface Invoice { interface Invoice {
id: string; id: string;
@@ -31,6 +32,9 @@ export function BillingPayments({ sessionId, readOnly }: BillingPaymentsProps) {
const [packages, setPackages] = useState<Package[]>([]); const [packages, setPackages] = useState<Package[]>([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [tab, setTab] = useState<"invoices" | "payment" | "packages">("invoices");
const [autopay, setAutopay] = useState(false);
const [showPaymentModal, setShowPaymentModal] = useState(false);
useEffect(() => { useEffect(() => {
async function fetchData() { async function fetchData() {
@@ -71,6 +75,9 @@ export function BillingPayments({ sessionId, readOnly }: BillingPaymentsProps) {
}).format(cents / 100); }).format(cents / 100);
}; };
const pending = invoices.filter((i) => i.status === "pending");
const totalPending = pending.reduce((sum, i) => sum + i.totalCents, 0);
if (loading) { if (loading) {
return ( return (
<div className="p-6"> <div className="p-6">
@@ -92,98 +99,347 @@ export function BillingPayments({ sessionId, readOnly }: BillingPaymentsProps) {
} }
return ( return (
<div className="p-6 space-y-8"> <div className="space-y-6">
<h2 className="text-2xl font-semibold">Billing & Payments</h2> {/* Outstanding Balance Banner */}
{totalPending > 0 && (
{/* Payment Methods */} <div className="bg-white rounded-2xl border border-stone-200 p-5 shadow-sm flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
<section> <div>
<h3 className="text-lg font-medium mb-4">Payment Methods</h3> <p className="text-sm text-stone-500">Outstanding Balance</p>
{paymentMethods.length === 0 ? ( <p className="text-3xl font-bold text-stone-800">{formatCents(totalPending)}</p>
<p className="text-gray-500 italic">No payment methods on file</p> <p className="text-xs text-stone-400 mt-0.5">
) : ( {pending.length} unpaid invoice{pending.length > 1 ? "s" : ""}
<div className="space-y-3"> </p>
{paymentMethods.map((method) => (
<div
key={`${method.brand}-${method.last4}`}
className="flex items-center justify-between p-4 border rounded-lg"
>
<div className="flex items-center gap-3">
<div className="w-10 h-6 bg-gray-200 rounded flex items-center justify-center text-xs">
{method.brand.toUpperCase()}
</div>
<span>**** {method.last4}</span>
<span className="text-gray-500">
{method.expiryMonth}/{method.expiryYear}
</span>
</div>
{!readOnly && (
<button className="text-sm text-blue-600 hover:underline">
Remove
</button>
)}
</div>
))}
</div> </div>
)} <button
</section> onClick={() => setShowPaymentModal(true)}
className="px-6 py-2 bg-(--color-accent) text-white rounded-lg text-sm font-medium hover:bg-(--color-accent-hover)"
>
Pay Now
</button>
</div>
)}
{/* Packages */} {/* Tabs */}
<section> <div className="flex gap-2">
<h3 className="text-lg font-medium mb-4">Packages</h3> {([
{packages.length === 0 ? ( { id: "invoices" as const, label: "Invoices", icon: DollarSign },
<p className="text-gray-500 italic">No packages purchased</p> { id: "payment" as const, label: "Payment Methods", icon: CreditCard },
) : ( { id: "packages" as const, label: "Packages", icon: Package },
<div className="space-y-3"> ]).map(({ id, label, icon: Icon }) => (
{packages.map((pkg, index) => ( <button
<div key={id}
key={index} onClick={() => setTab(id)}
className="flex items-center justify-between p-4 border rounded-lg" className={`flex items-center gap-1.5 px-4 py-2 rounded-lg text-sm font-medium ${
> tab === id
<span>{pkg.name}</span> ? "bg-(--color-accent-light) text-(--color-accent-dark)"
<span className="text-gray-600">{pkg.remaining} remaining</span> : "text-stone-500 hover:bg-stone-50"
</div> }`}
))} >
</div> <Icon size={14} />
)} {label}
</section> </button>
))}
</div>
{/* Invoices */} {/* Invoices */}
<section> {tab === "invoices" && (
<h3 className="text-lg font-medium mb-4">Invoice History</h3> <div className="bg-white rounded-2xl border border-stone-200 shadow-sm overflow-hidden">
{invoices.length === 0 ? ( <div className="overflow-x-auto">
<p className="text-gray-500 italic">No invoices yet</p> <table className="w-full text-sm">
) : ( <thead>
<div className="space-y-3"> <tr className="text-left text-xs text-stone-400 border-b border-stone-100">
{invoices.map((invoice) => ( <th className="px-5 py-3 font-medium">Date</th>
<div <th className="px-5 py-3 font-medium">Description</th>
key={invoice.id} <th className="px-5 py-3 font-medium">Amount</th>
className="flex items-center justify-between p-4 border rounded-lg" <th className="px-5 py-3 font-medium">Status</th>
> <th className="px-5 py-3 font-medium"></th>
<div className="flex flex-col"> </tr>
<span className="font-medium"> </thead>
{invoice.description || `Invoice ${invoice.id.slice(0, 8)}`} <tbody>
</span> {invoices.map((inv) => (
<span className="text-sm text-gray-500">{invoice.date}</span> <tr key={inv.id} className="border-b border-stone-50 hover:bg-stone-50/50">
<td className="px-5 py-3 text-stone-700">
{new Date(inv.date).toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric",
})}
</td>
<td className="px-5 py-3 text-stone-600">
{inv.description || `Invoice ${inv.id.slice(0, 8)}`}
</td>
<td className="px-5 py-3 font-medium text-stone-800">
{formatCents(inv.totalCents)}
</td>
<td className="px-5 py-3">
<span
className={`px-2 py-0.5 rounded-full text-xs font-medium ${
inv.status === "paid"
? "bg-green-100 text-green-700"
: inv.status === "pending"
? "bg-yellow-100 text-yellow-700"
: inv.status === "failed"
? "bg-red-100 text-red-700"
: "bg-gray-100 text-gray-700"
}`}
>
{inv.status.charAt(0).toUpperCase() + inv.status.slice(1)}
</span>
</td>
<td className="px-5 py-3">
<button className="text-stone-400 hover:text-stone-600">
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
</svg>
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
)}
{/* Payment Methods */}
{tab === "payment" && (
<div className="space-y-4">
{paymentMethods.length === 0 ? (
<p className="text-gray-500 italic">No payment methods on file</p>
) : (
<div className="space-y-3">
{paymentMethods.map((method) => (
<div
key={`${method.brand}-${method.last4}`}
className="flex items-center justify-between p-4 border border-stone-200 rounded-lg bg-white"
>
<div className="flex items-center gap-3">
<div className="w-10 h-6 bg-gray-200 rounded flex items-center justify-center text-xs">
{method.brand.toUpperCase()}
</div>
<span className="text-stone-700">**** {method.last4}</span>
<span className="text-stone-500">
{method.expiryMonth}/{method.expiryYear}
</span>
</div>
{!readOnly && (
<button className="text-sm text-blue-600 hover:underline">
Remove
</button>
)}
</div> </div>
<div className="flex items-center gap-4"> ))}
<span className="font-semibold"> </div>
{formatCents(invoice.totalCents)} )}
</span>
<span {/* Autopay */}
className={`px-2 py-1 text-xs rounded ${ <div className="bg-white rounded-2xl border border-stone-200 p-5 shadow-sm">
invoice.status === "pending" <div className="flex items-center justify-between">
? "bg-yellow-100 text-yellow-800" <div className="flex items-center gap-3">
: "bg-green-100 text-green-800" <div className="w-10 h-10 rounded-lg bg-(--color-accent-light) flex items-center justify-center">
}`} <Zap size={18} className="text-(--color-accent)" />
> </div>
{invoice.status.charAt(0).toUpperCase() + invoice.status.slice(1)} <div>
</span> <p className="text-sm font-medium text-stone-800">Autopay</p>
<p className="text-xs text-stone-500">
Automatically charge after each appointment
</p>
</div> </div>
</div> </div>
))} {!readOnly ? (
<button
onClick={() => setAutopay(!autopay)}
className={`w-12 h-6 rounded-full transition-colors ${
autopay ? "bg-(--color-accent)" : "bg-stone-300"
}`}
>
<div
className={`w-5 h-5 bg-white rounded-full shadow transition-transform ${
autopay ? "translate-x-6" : "translate-x-0.5"
}`}
/>
</button>
) : (
<span className="text-xs text-stone-400">
{autopay ? "Enabled" : "Disabled"}
</span>
)}
</div>
</div> </div>
)} </div>
</section> )}
{/* Packages */}
{tab === "packages" && (
<div className="space-y-4">
{packages.length === 0 ? (
<p className="text-gray-500 italic">No packages purchased</p>
) : (
packages.map((pkg, index) => (
<div
key={index}
className="bg-white rounded-2xl border border-stone-200 p-5 shadow-sm"
>
<div className="flex items-center justify-between">
<span className="font-medium text-stone-800">{pkg.name}</span>
<span className="text-stone-600">{pkg.remaining} remaining</span>
</div>
</div>
))
)}
</div>
)}
{/* Payment Modal */}
{showPaymentModal && (
<PaymentModal
pending={pending}
totalPending={totalPending}
onClose={() => setShowPaymentModal(false)}
/>
)}
</div>
);
}
function PaymentModal({
pending,
totalPending: _totalPending,
onClose,
}: {
pending: Invoice[];
totalPending: number;
onClose: () => void;
}) {
const [selectedInvoices, setSelectedInvoices] = useState<Set<string>>(
new Set(pending.map((i) => i.id))
);
const [isProcessing, setIsProcessing] = useState(false);
const [isComplete, setIsComplete] = useState(false);
const formatCents = (cents: number) =>
new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
}).format(cents / 100);
const toggleInvoice = (id: string) => {
const next = new Set(selectedInvoices);
if (next.has(id)) {
next.delete(id);
} else {
next.add(id);
}
setSelectedInvoices(next);
};
const handlePay = async () => {
setIsProcessing(true);
await new Promise((resolve) => setTimeout(resolve, 1500));
setIsProcessing(false);
setIsComplete(true);
};
const selectedTotal = pending
.filter((i) => selectedInvoices.has(i.id))
.reduce((sum, i) => sum + i.totalCents, 0);
if (isComplete) {
return (
<div className="fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4">
<div className="bg-white rounded-2xl shadow-xl max-w-md w-full p-8 text-center">
<div className="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
<svg className="w-8 h-8 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
</div>
<h2 className="font-semibold text-stone-800 text-lg mb-2">Payment Successful</h2>
<p className="text-stone-500 text-sm mb-6">
Your payment of {formatCents(selectedTotal)} has been processed. A receipt has been sent to your email.
</p>
<button
onClick={onClose}
className="w-full px-4 py-2 bg-(--color-accent) text-white rounded-lg text-sm font-medium"
>
Done
</button>
</div>
</div>
);
}
return (
<div className="fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4">
<div className="bg-white rounded-2xl shadow-xl max-w-md w-full p-6">
<div className="flex items-center justify-between mb-6">
<h2 className="font-semibold text-stone-800 text-lg">Pay Outstanding Balance</h2>
<button onClick={onClose} className="text-stone-400 hover:text-stone-600">
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<p className="text-sm text-stone-500 mb-4">Select invoices to pay:</p>
<div className="space-y-3 mb-6">
{pending.map((inv) => (
<label
key={inv.id}
className={`flex items-center justify-between p-3 rounded-lg border cursor-pointer transition-colors ${
selectedInvoices.has(inv.id)
? "border-(--color-accent) bg-(--color-accent-lighter)"
: "border-stone-200 hover:border-stone-300"
}`}
>
<div className="flex items-center gap-3">
<input
type="checkbox"
checked={selectedInvoices.has(inv.id)}
onChange={() => toggleInvoice(inv.id)}
className="w-4 h-4 rounded border-stone-300 text-(--color-accent) focus:ring-(--color-accent)"
/>
<div>
<p className="text-sm font-medium text-stone-800">
{inv.description || `Invoice ${inv.id.slice(0, 8)}`}
</p>
<p className="text-xs text-stone-500">
{new Date(inv.date).toLocaleDateString()}
</p>
</div>
</div>
<span className="text-sm font-medium text-stone-800">
{formatCents(inv.totalCents)}
</span>
</label>
))}
</div>
<div className="border-t border-stone-200 pt-4 mb-6">
<div className="flex justify-between items-center">
<span className="text-sm text-stone-600">Total</span>
<span className="text-lg font-bold text-stone-800">
{formatCents(selectedTotal)}
</span>
</div>
</div>
<div className="flex gap-3">
<button
onClick={onClose}
className="flex-1 px-4 py-2 border border-stone-200 rounded-lg text-sm font-medium text-stone-600 hover:bg-stone-50"
>
Cancel
</button>
<button
onClick={handlePay}
disabled={selectedInvoices.size === 0 || isProcessing}
className="flex-1 px-4 py-2 bg-(--color-accent) text-white rounded-lg text-sm font-medium hover:bg-(--color-accent-hover) disabled:opacity-50 disabled:cursor-not-allowed"
>
{isProcessing ? "Processing..." : "Pay Now"}
</button>
</div>
</div>
</div> </div>
); );
} }
+36 -23
View File
@@ -24,36 +24,49 @@ interface Appointment {
reportCardId?: string; reportCardId?: string;
} }
export function ReportCards() { interface ReportCardsProps {
sessionId: string | null;
}
export function ReportCards({ sessionId }: ReportCardsProps) {
const [appointments, setAppointments] = useState<Appointment[]>([]); const [appointments, setAppointments] = useState<Appointment[]>([]);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [selectedCard, setSelectedCard] = useState<Appointment | null>(null); const [selectedCard, setSelectedCard] = useState<Appointment | null>(null);
useEffect(() => { const loadReportCards = async () => {
const fetchReportCards = async () => { if (!sessionId) {
try { setAppointments([]);
const response = await fetch("/api/portal/appointments"); setIsLoading(false);
return;
}
try {
setError(null);
setIsLoading(true);
const response = await fetch("/api/portal/appointments", {
headers: { "X-Impersonation-Session-Id": sessionId },
});
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
const allAppointments: Appointment[] = data.appointments || data || []; const allAppointments: Appointment[] = data.appointments || data || [];
const reportCardAppointments = allAppointments.filter( const reportCardAppointments = allAppointments.filter(
(appt) => appt.reportCardId (appt) => appt.reportCardId
); );
setAppointments(reportCardAppointments); setAppointments(reportCardAppointments);
} else { } else {
setError("Failed to load report cards."); setError("Failed to load report cards.");
}
} catch {
setError("Failed to load report cards. Please try again.");
} finally {
setIsLoading(false);
} }
}; } catch {
setError("Failed to load report cards. Please try again.");
} finally {
setIsLoading(false);
}
};
fetchReportCards(); useEffect(() => {
}, []); loadReportCards();
}, [sessionId]);
if (isLoading) { if (isLoading) {
return ( return (
@@ -69,7 +82,7 @@ export function ReportCards() {
<div className="text-center py-12"> <div className="text-center py-12">
<p className="text-red-600 mb-4">{error}</p> <p className="text-red-600 mb-4">{error}</p>
<button <button
onClick={() => window.location.reload()} onClick={() => loadReportCards()}
className="px-4 py-2 bg-stone-100 text-stone-700 rounded-md hover:bg-stone-200" className="px-4 py-2 bg-stone-100 text-stone-700 rounded-md hover:bg-stone-200"
> >
Retry Retry