All files / components/ui ErrorModal.tsx

84.61% Statements 22/26
50% Branches 2/4
81.81% Functions 9/11
84% Lines 21/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203                                  1x                       1x         9x   9x 1x     9x 2x       9x 9x 1x 1x       9x 9x       9x 9x 9x       9x                                                                                                                                                                                           1x 1x                                                   1x 1x                                  
/**
 * ErrorModal - Korean-themed error dialog component
 * Provides user-friendly error recovery with retry functionality
 * Follows Korean cyberpunk aesthetic and accessibility best practices
 */
 
import React, { useCallback, useEffect, useRef } from "react";
import { KOREAN_COLORS, FONT_FAMILY } from "../../types/constants";
import { toHex } from "../../utils/colorUtils";
 
interface ErrorModalProps {
  readonly message: string;
  readonly onRetry: () => void;
  readonly onContinue: () => void;
}
 
// Pre-compute hex colors from Korean color constants
const HEX_COLORS = {
  PRIMARY_CYAN: toHex(KOREAN_COLORS.PRIMARY_CYAN),
  ACCENT_GOLD: toHex(KOREAN_COLORS.ACCENT_GOLD),
  UI_BACKGROUND_DARK: toHex(KOREAN_COLORS.UI_BACKGROUND_DARK),
  TEXT_ERROR: toHex(KOREAN_COLORS.TEXT_ERROR),
} as const;
 
/**
 * Error modal component with Korean cyberpunk styling
 * Provides retry and continue options for graceful error recovery
 * Includes keyboard navigation and focus management
 */
export const ErrorModal: React.FC<ErrorModalProps> = ({
  message,
  onRetry,
  onContinue,
}) => {
  const retryButtonRef = useRef<HTMLButtonElement>(null);
 
  const handleRetry = useCallback(() => {
    onRetry();
  }, [onRetry]);
 
  const handleContinue = useCallback(() => {
    onContinue();
  }, [onContinue]);
 
  // Handle keyboard events (Escape key to close)
  useEffect(() => {
    const handleKeyDown = (e: KeyboardEvent) => {
      Eif (e.key === 'Escape') {
        handleContinue();
      }
    };
    
    document.addEventListener('keydown', handleKeyDown);
    return () => document.removeEventListener('keydown', handleKeyDown);
  }, [handleContinue]);
 
  // Set focus to first interactive element when modal opens
  useEffect(() => {
    Eif (retryButtonRef.current) {
      retryButtonRef.current.focus();
    }
  }, []);
 
  return (
    <div
      role="alertdialog"
      aria-labelledby="error-modal-title"
      aria-describedby="error-modal-description"
      style={{
        position: "fixed",
        top: 0,
        left: 0,
        width: "100%",
        height: "100%",
        backgroundColor: "rgba(0, 0, 0, 0.8)",
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
        zIndex: 9999,
        fontFamily: FONT_FAMILY.CYBER,
      }}
      data-testid="error-modal"
    >
      <div
        style={{
          backgroundColor: `#${HEX_COLORS.UI_BACKGROUND_DARK}`,
          border: `2px solid #${HEX_COLORS.TEXT_ERROR}`,
          borderRadius: "8px",
          padding: "32px",
          maxWidth: "500px",
          boxShadow: `0 8px 32px #${HEX_COLORS.TEXT_ERROR}40`,
        }}
      >
        {/* Error Icon */}
        <div
          style={{
            textAlign: "center",
            fontSize: "48px",
            marginBottom: "16px",
          }}
          aria-hidden="true"
        >
          ⚠️
        </div>
 
        {/* Title */}
        <h2
          id="error-modal-title"
          style={{
            color: `#${HEX_COLORS.TEXT_ERROR}`,
            fontSize: "24px",
            fontWeight: "bold",
            textAlign: "center",
            marginBottom: "16px",
          }}
        >
          오류 발생 | Error Occurred
        </h2>
 
        {/* Message */}
        <p
          id="error-modal-description"
          style={{
            color: `#${HEX_COLORS.PRIMARY_CYAN}`,
            fontSize: "16px",
            textAlign: "center",
            marginBottom: "32px",
            lineHeight: "1.5",
          }}
        >
          {message}
        </p>
 
        {/* Action Buttons */}
        <div
          style={{
            display: "flex",
            gap: "16px",
            justifyContent: "center",
          }}
        >
          <button
            ref={retryButtonRef}
            onClick={handleRetry}
            style={{
              backgroundColor: `#${HEX_COLORS.PRIMARY_CYAN}`,
              color: "#000",
              border: "none",
              borderRadius: "4px",
              padding: "12px 24px",
              fontSize: "16px",
              fontWeight: "bold",
              cursor: "pointer",
              fontFamily: FONT_FAMILY.CYBER,
              transition: "all 0.2s ease",
            }}
            onMouseEnter={(e) => {
              e.currentTarget.style.transform = "scale(1.05)";
              e.currentTarget.style.boxShadow = `0 4px 16px #${HEX_COLORS.PRIMARY_CYAN}80`;
            }}
            onMouseLeave={(e) => {
              e.currentTarget.style.transform = "scale(1)";
              e.currentTarget.style.boxShadow = "none";
            }}
            data-testid="error-modal-retry"
          >
            재시도 | Retry
          </button>
 
          <button
            onClick={handleContinue}
            style={{
              backgroundColor: "transparent",
              color: `#${HEX_COLORS.ACCENT_GOLD}`,
              border: `2px solid #${HEX_COLORS.ACCENT_GOLD}`,
              borderRadius: "4px",
              padding: "12px 24px",
              fontSize: "16px",
              fontWeight: "bold",
              cursor: "pointer",
              fontFamily: FONT_FAMILY.CYBER,
              transition: "all 0.2s ease",
            }}
            onMouseEnter={(e) => {
              e.currentTarget.style.backgroundColor = `#${HEX_COLORS.ACCENT_GOLD}20`;
              e.currentTarget.style.transform = "scale(1.05)";
            }}
            onMouseLeave={(e) => {
              e.currentTarget.style.backgroundColor = "transparent";
              e.currentTarget.style.transform = "scale(1)";
            }}
            data-testid="error-modal-continue"
          >
            무음으로 계속 | Continue Without Sound
          </button>
        </div>
      </div>
    </div>
  );
};
 
export default ErrorModal;