File size: 2,493 Bytes
9580dce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"use client";

import { useEffect } from "react";
import Link from "next/link";
import { AlertTriangle, Home, RotateCcw } from "lucide-react";

interface ExerciseErrorProps {
  error: Error & { digest?: string };
  reset: () => void;
  category: string;
  categoryColor: string;
}

export function ExerciseError({
  error,
  reset,
  category,
  categoryColor,
}: ExerciseErrorProps) {
  useEffect(() => {
    console.error(`[${category}] Exercise error:`, error);
  }, [error, category]);

  return (
    <div className="flex items-center justify-center min-h-[60vh]">
      <div className="flex flex-col items-center gap-5 text-center max-w-md px-4">
        {/* Icon */}
        <div
          className="glass-md rounded-2xl p-5"
          style={{
            background: `color-mix(in srgb, ${categoryColor} 12%, transparent)`,
          }}
        >
          <AlertTriangle size={36} style={{ color: categoryColor }} />
        </div>

        {/* Heading */}
        <div>
          <h2
            className="text-lg font-semibold mb-1"
            style={{ color: "var(--text-primary)" }}
          >
            {category} hit an error
          </h2>
          <p
            className="text-sm"
            style={{ color: "var(--text-secondary)" }}
          >
            {error.message || "Something unexpected happened. Give it another shot."}
          </p>
          {error.digest && (
            <p
              className="text-xs mt-2 font-mono"
              style={{ color: "var(--text-muted)" }}
            >
              Ref: {error.digest}
            </p>
          )}
        </div>

        {/* Actions */}
        <div className="flex items-center gap-3">
          <button
            onClick={reset}
            className="inline-flex items-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium transition-all duration-150 hover:brightness-110"
            style={{
              background: categoryColor,
              color: "#ffffff",
            }}
          >
            <RotateCcw size={15} />
            Try Again
          </button>
          <Link
            href="/"
            className="inline-flex items-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium transition-colors"
            style={{
              background: "var(--surface-3)",
              color: "var(--text-secondary)",
            }}
          >
            <Home size={15} />
            Dashboard
          </Link>
        </div>
      </div>
    </div>
  );
}