+
+ {isLoading ? (
+
+ ) : (
+
-
-
- {credential.verificationStatus ? 'Verified' : 'Pending'}
+
+
{credential.vaccineType}
+
+
+
+
+
+ {credential.verificationStatus ? 'Verified' : 'Pending'}
+
+
+
+
+
+
+ {credential.vaccinationDate}
+
-
-
-
- {credential.vaccinationDate}
+
+
+ {credential.id}
-
-
-
-
- {credential.id}
-
-
-
+
+ )}
)}
diff --git a/frontend/src/components/credential-edit-modal.tsx b/frontend/src/components/credential-edit-modal.tsx
index a0773ab9..b7de85cc 100644
--- a/frontend/src/components/credential-edit-modal.tsx
+++ b/frontend/src/components/credential-edit-modal.tsx
@@ -1,8 +1,10 @@
'use client';
-import { useState, useEffect } from 'react';
+import { useState, useEffect, useCallback } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { X, Edit2, CheckCircle } from 'lucide-react';
+import { LoadingButton } from './animations';
+import { useCredentialOperation } from '@/hooks/useCredentialOperation';
interface Credential {
id: string;
@@ -26,25 +28,33 @@ export function CredentialEditModal({
}: CredentialEditModalProps) {
const [vaccineType, setVaccineType] = useState('');
const [vaccinationDate, setVaccinationDate] = useState('');
+ const { execute, isPending, error, clearError } = useCredentialOperation();
useEffect(() => {
if (credential && isOpen) {
setVaccineType(credential.vaccineType);
setVaccinationDate(credential.vaccinationDate);
+ clearError();
}
- }, [credential, isOpen]);
+ }, [credential, isOpen, clearError]);
- const handleSubmit = (e: React.FormEvent) => {
+ const handleSubmit = useCallback(async (e: React.FormEvent) => {
e.preventDefault();
- if (credential) {
+ if (!credential) return;
+
+ await execute(async () => {
+ // Simulate API call delay
+ await new Promise((resolve) => setTimeout(resolve, 1000));
onSave({
...credential,
vaccineType,
vaccinationDate,
});
onClose();
- }
- };
+ }, {
+ context: 'CredentialEdit',
+ });
+ }, [credential, vaccineType, vaccinationDate, execute, onSave, onClose]);
if (!credential) return null;
@@ -90,7 +100,8 @@ export function CredentialEditModal({
type="text"
value={vaccineType}
onChange={(e) => setVaccineType(e.target.value)}
- className="w-full bg-white/10 border border-white/20 rounded p-3 sm:p-2 text-white outline-none focus:border-green-400 text-base sm:text-sm"
+ disabled={isPending}
+ className="w-full bg-white/10 border border-white/20 rounded p-3 sm:p-2 text-white outline-none focus:border-green-400 disabled:opacity-50 text-base sm:text-sm"
required
/>
@@ -100,26 +111,46 @@ export function CredentialEditModal({
type="text"
value={vaccinationDate}
onChange={(e) => setVaccinationDate(e.target.value)}
- className="w-full bg-white/10 border border-white/20 rounded p-3 sm:p-2 text-white outline-none focus:border-green-400 text-base sm:text-sm"
+ disabled={isPending}
+ className="w-full bg-white/10 border border-white/20 rounded p-3 sm:p-2 text-white outline-none focus:border-green-400 disabled:opacity-50 text-base sm:text-sm"
required
/>