-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignOutModal.js
More file actions
107 lines (98 loc) · 3.41 KB
/
SignOutModal.js
File metadata and controls
107 lines (98 loc) · 3.41 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { useAuth } from "@/context/AuthContext";
import { LogOut, X, AlertTriangle } from "lucide-react";
export default function SignOutModal({ isOpen, onClose }) {
const [loading, setLoading] = useState(false);
const { signOut } = useAuth();
const router = useRouter();
const handleSignOut = async () => {
setLoading(true);
try {
await signOut();
onClose();
router.push("/");
} catch (error) {
console.error("Sign out error:", error);
alert("Failed to sign out. Please try again.");
} finally {
setLoading(false);
}
};
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
{/* Backdrop */}
<div
className="absolute inset-0 bg-black/60 backdrop-blur-sm"
onClick={onClose}
></div>
{/* Modal */}
<div className="relative bg-slate-800 rounded-2xl shadow-2xl border border-slate-700 max-w-md w-full p-6 animate-in zoom-in-95 duration-200">
{/* Close Button */}
<button
onClick={onClose}
className="absolute top-4 right-4 text-gray-400 hover:text-white transition-colors"
>
<X className="w-5 h-5" />
</button>
{/* Icon */}
<div className="w-12 h-12 bg-red-500/10 rounded-full flex items-center justify-center mb-4">
<AlertTriangle className="w-6 h-6 text-red-400" />
</div>
{/* Content */}
<h3 className="text-xl font-bold text-white mb-2">Sign Out</h3>
<p className="text-gray-400 mb-6">
Are you sure you want to sign out? Any unsaved changes will be lost.
</p>
{/* Actions */}
<div className="flex space-x-3">
<button
onClick={onClose}
disabled={loading}
className="flex-1 py-2.5 px-4 bg-slate-700 text-white font-medium rounded-lg hover:bg-slate-600 transition-colors disabled:opacity-50"
>
Cancel
</button>
<button
onClick={handleSignOut}
disabled={loading}
className="flex-1 py-2.5 px-4 bg-red-500 text-white font-medium rounded-lg hover:bg-red-600 transition-colors disabled:opacity-50 flex items-center justify-center space-x-2"
>
{loading ? (
<>
<svg
className="animate-spin h-4 w-4 text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
<span>Signing out...</span>
</>
) : (
<>
<LogOut className="w-4 h-4" />
<span>Sign Out</span>
</>
)}
</button>
</div>
</div>
</div>
);
}