File size: 2,607 Bytes
78013c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"use client";

import React, { useState } from "react";
import { KeyRound, Lock } from "lucide-react";
import GlassButton from "./GlassButton";
import GlassInput from "./GlassInput";
import toast from "react-hot-toast";

interface GlassResetPasswordDialogProps {
  isOpen: boolean;
  onClose: () => void;
  onConfirm: (newPassword: string) => Promise<void>;
  title: string;
  description: string;
}

export default function GlassResetPasswordDialog({
  isOpen,
  onClose,
  onConfirm,
  title,
  description,
}: GlassResetPasswordDialogProps): React.ReactElement | null {
  const [newPassword, setNewPassword] = useState("");
  const [loading, setLoading] = useState(false);

  if (!isOpen) return null;

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    if (newPassword.length < 8) {
      toast.error("Password must be at least 8 characters");
      return;
    }
    setLoading(true);
    try {
      await onConfirm(newPassword);
      setNewPassword(""); 
    } finally {
      setLoading(false);
    }
  };

  return (
    <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm animate-fade-in">
      <div className="glass-panel-static w-full max-w-sm p-6 shadow-2xl relative">
        <div className="flex items-center gap-3 mb-2 text-warning">
          <div className="p-2 rounded-lg bg-warning/10 border border-warning/20">
            <KeyRound size={20} />
          </div>
          <h2 className="text-lg font-bold font-[Outfit] text-slate-200">{title}</h2>
        </div>
        <p className="text-sm text-slate-400 mb-6">{description}</p>
        
        <form onSubmit={handleSubmit}>
          <div className="mb-6">
            <GlassInput
              type="password"
              placeholder="New Password (min 8 chars)"
              value={newPassword}
              onChange={(e) => setNewPassword(e.target.value)}
              icon={<Lock size={16} className="text-slate-400" />}
              autoComplete="new-password"
            />
          </div>

          <div className="flex gap-3 justify-end mt-4">
            <GlassButton
              type="button"
              variant="ghost"
              onClick={() => {
                setNewPassword("");
                onClose();
              }}
              disabled={loading}
            >
              Cancel
            </GlassButton>
            <GlassButton type="submit" variant="primary" loading={loading}>
              Reset Password
            </GlassButton>
          </div>
        </form>
      </div>
    </div>
  );
}