File size: 4,408 Bytes
baa4c21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { AnimatePresence, motion } from 'framer-motion';
import type { ActionAlert } from '~/types/actions';
import { classNames } from '~/utils/classNames';

interface Props {
  alert: ActionAlert;
  clearAlert: () => void;
  postMessage: (message: string) => void;
}

export default function ChatAlert({ alert, clearAlert, postMessage }: Props) {
  const { description, content, source } = alert;

  const isPreview = source === 'preview';
  const title = isPreview ? 'Preview Error' : 'Terminal Error';
  const message = isPreview
    ? 'We encountered an error while running the preview. Would you like Bolt to analyze and help resolve this issue?'
    : 'We encountered an error while running terminal commands. Would you like Bolt to analyze and help resolve this issue?';

  return (
    <AnimatePresence>

      <motion.div

        initial={{ opacity: 0, y: -20 }}

        animate={{ opacity: 1, y: 0 }}

        exit={{ opacity: 0, y: -20 }}

        transition={{ duration: 0.3 }}

        className={`rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-background-depth-2 p-4`}

      >

        <div className="flex items-start">

          {/* Icon */}

          <motion.div

            className="flex-shrink-0"

            initial={{ scale: 0 }}

            animate={{ scale: 1 }}

            transition={{ delay: 0.2 }}

          >

            <div className={`i-ph:warning-duotone text-xl text-bolt-elements-button-danger-text`}></div>

          </motion.div>

          {/* Content */}

          <div className="ml-3 flex-1">

            <motion.h3

              initial={{ opacity: 0 }}

              animate={{ opacity: 1 }}

              transition={{ delay: 0.1 }}

              className={`text-sm font-medium text-bolt-elements-textPrimary`}

            >

              {title}

            </motion.h3>

            <motion.div

              initial={{ opacity: 0 }}

              animate={{ opacity: 1 }}

              transition={{ delay: 0.2 }}

              className={`mt-2 text-sm text-bolt-elements-textSecondary`}

            >

              <p>{message}</p>

              {description && (

                <div className="text-xs text-bolt-elements-textSecondary p-2 bg-bolt-elements-background-depth-3 rounded mt-4 mb-4">

                  Error: {description}

                </div>

              )}

            </motion.div>



            {/* Actions */}

            <motion.div

              className="mt-4"

              initial={{ opacity: 0, y: 10 }}

              animate={{ opacity: 1, y: 0 }}

              transition={{ delay: 0.3 }}

            >

              <div className={classNames(' flex gap-2')}>

                <button

                  onClick={() =>

                    postMessage(

                      `*Fix this ${isPreview ? 'preview' : 'terminal'} error* \n\`\`\`${isPreview ? 'js' : 'sh'}\n${content}\n\`\`\`\n`,

                    )

                  }

                  className={classNames(

                    `px-2 py-1.5 rounded-md text-sm font-medium`,

                    'bg-bolt-elements-button-primary-background',

                    'hover:bg-bolt-elements-button-primary-backgroundHover',

                    'focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-bolt-elements-button-danger-background',

                    'text-bolt-elements-button-primary-text',

                    'flex items-center gap-1.5',

                  )}

                >

                  <div className="i-ph:chat-circle-duotone"></div>

                  Ask Bolt

                </button>

                <button

                  onClick={clearAlert}

                  className={classNames(

                    `px-2 py-1.5 rounded-md text-sm font-medium`,

                    'bg-bolt-elements-button-secondary-background',

                    'hover:bg-bolt-elements-button-secondary-backgroundHover',

                    'focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-bolt-elements-button-secondary-background',

                    'text-bolt-elements-button-secondary-text',

                  )}

                >

                  Dismiss

                </button>

              </div>

            </motion.div>

          </div>

        </div>

      </motion.div>

    </AnimatePresence>
  );
}