All files / web/src/components/practice/start-practice-modal ErrorDisplay.tsx

5.79% Statements 8/138
100% Branches 0/0
0% Functions 0/1
5.79% Lines 8/138

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 1391x 1x 1x 1x 1x 1x 1x 1x                                                                                                                                                                                                                                                                      
'use client'
 
import Link from 'next/link'
import { useTheme } from '@/contexts/ThemeContext'
import { css } from '../../../../styled-system/css'
import { useStartPracticeModal } from '../StartPracticeModalContext'
 
export function ErrorDisplay() {
  const { resolvedTheme } = useTheme()
  const isDark = resolvedTheme === 'dark'
  const { displayError, isNoSkillsError, isSessionLimitError, setShowSkillSelector } =
    useStartPracticeModal()

  if (!displayError) {
    return null
  }

  const isWarning = isNoSkillsError || isSessionLimitError

  return (
    <div
      data-element="error-display"
      data-error-type={
        isNoSkillsError ? 'no-skills' : isSessionLimitError ? 'session-limit' : 'generic'
      }
      className={css({
        padding: '0.75rem',
        borderRadius: '8px',
        textAlign: 'center',
      })}
      style={{
        background: isWarning
          ? isDark
            ? 'rgba(251, 191, 36, 0.12)'
            : 'rgba(251, 191, 36, 0.08)'
          : isDark
            ? 'rgba(239, 68, 68, 0.12)'
            : 'rgba(239, 68, 68, 0.08)',
        border: `1px solid ${
          isWarning
            ? isDark
              ? 'rgba(251, 191, 36, 0.25)'
              : 'rgba(251, 191, 36, 0.15)'
            : isDark
              ? 'rgba(239, 68, 68, 0.25)'
              : 'rgba(239, 68, 68, 0.15)'
        }`,
      }}
    >
      {isSessionLimitError ? (
        <>
          <p
            className={css({
              fontSize: '0.875rem',
              marginBottom: '0.5rem',
            })}
            style={{ color: isDark ? '#fcd34d' : '#b45309' }}
          >
            Weekly session limit reached
          </p>
          <p
            className={css({ fontSize: '0.75rem', marginBottom: '0.75rem' })}
            style={{ color: isDark ? '#d4d4d4' : '#525252' }}
          >
            You&apos;ve used all 5 sessions this week.
          </p>
          <Link
            href="/pricing"
            data-action="upgrade-for-sessions"
            className={css({
              display: 'inline-block',
              padding: '0.5rem 1rem',
              fontSize: '0.8125rem',
              fontWeight: '600',
              color: 'white',
              backgroundColor: isDark ? '#7c3aed' : '#8b5cf6',
              border: 'none',
              borderRadius: '6px',
              textDecoration: 'none',
              transition: 'all 0.15s ease',
              _hover: {
                backgroundColor: isDark ? '#6d28d9' : '#7c3aed',
              },
            })}
          >
            Upgrade for unlimited sessions
          </Link>
        </>
      ) : isNoSkillsError ? (
        <>
          <p
            className={css({
              fontSize: '0.875rem',
              marginBottom: '0.5rem',
            })}
            style={{ color: isDark ? '#fcd34d' : '#b45309' }}
          >
            No skills enabled
          </p>
          <p
            className={css({ fontSize: '0.75rem', marginBottom: '0.75rem' })}
            style={{ color: isDark ? '#d4d4d4' : '#525252' }}
          >
            Enable at least one skill to start practicing.
          </p>
          <button
            type="button"
            data-action="open-skill-selector"
            onClick={() => setShowSkillSelector(true)}
            className={css({
              padding: '0.5rem 1rem',
              fontSize: '0.8125rem',
              fontWeight: '600',
              color: 'white',
              backgroundColor: isDark ? '#d97706' : '#f59e0b',
              border: 'none',
              borderRadius: '6px',
              cursor: 'pointer',
              transition: 'all 0.15s ease',
              _hover: {
                backgroundColor: isDark ? '#b45309' : '#d97706',
              },
            })}
          >
            Open Skill Selector
          </button>
        </>
      ) : (
        <p
          className={css({ fontSize: '0.875rem' })}
          style={{ color: isDark ? '#fca5a5' : '#dc2626' }}
        >
          {displayError.message || 'Something went wrong. Please try again.'}
        </p>
      )}
    </div>
  )
}