Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add user feedback handling and modal [WIP]

Tomas Valenta150680c948ed
diff --git a/components/AgentLogFilesList.tsx b/components/AgentLogFilesList.tsx
index c33ab6fb8..6dfa6da2d 100644
--- a/components/AgentLogFilesList.tsx
+++ b/components/AgentLogFilesList.tsx
@@ -112,7 +112,7 @@ function AgentLogFilesList({
onClick={handleClick}
>
<Upload size={14} />
- <span className="text-sm font-medium">Upload log file</span>
+ <span className="text-sm font-medium">Upload log folder</span>
</button>
</header>
@@ -130,7 +130,7 @@ function AgentLogFilesList({
className="w-full flex flex-col items-center justify-center rounded-lg border-2 border-dashed border-gray-500 p-12 text-center hover:border-gray-400 transition-all focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
>
<Upload size={48} className="text-gray-500" strokeWidth={1.5} />
- <span className="mt-2 block text-sm font-semibold text-gray-300">Upload log file</span>
+ <span className="mt-2 block text-sm font-semibold text-gray-300">Upload log folder</span>
</button>
</div>
)}
diff --git a/components/Feedback/FeedbackButton.tsx b/components/Feedback/FeedbackButton.tsx
new file mode 100644
index 000000000..5ad44aec1
--- /dev/null
+++ b/components/Feedback/FeedbackButton.tsx
@@ -0,0 +1,27 @@
+import { MouseEvent } from 'react'
+import {
+ MessageCircle,
+} from 'lucide-react'
+import clsx from 'clsx'
+
+export interface Props {
+ onClick: (e: MouseEvent<HTMLButtonElement>) => void
+ isOpen: boolean
+}
+
+function FeedbackButton({
+ onClick,
+ isOpen,
+}: Props) {
+ return (
+ <button
+ className={clsx({ 'border-white/10 text-gray-100': isOpen, 'border-white/5 text-gray-400': !isOpen }, 'group ml-auto flex items-center space-x-1 cursor-pointer py-1 px-2 rounded-md bg-gray-900 border border-white/5 hover:border-white/10 transition-all')}
+ onMouseDown={onClick}
+ >
+ <MessageCircle size={14} className="" />
+ <span className="text-sm">Send feedback to CEO</span>
+ </button>
+ )
+}
+
+export default FeedbackButton
\ No newline at end of file
diff --git a/components/Feedback/FeedbackModal.tsx b/components/Feedback/FeedbackModal.tsx
new file mode 100644
index 000000000..7a67ebcb3
--- /dev/null
+++ b/components/Feedback/FeedbackModal.tsx
@@ -0,0 +1,83 @@
+import { useUser } from '@supabase/auth-helpers-react'
+import { FormEvent, MouseEvent, useRef, useState } from 'react'
+import { useOnClickOutside } from 'usehooks-ts'
+
+import Textarea from 'components/Textarea'
+import SpinnerIcon from 'components/Spinner'
+import { useAddFeedback } from 'hooks/useAddFeedback'
+import clsx from 'clsx'
+
+export interface Props {
+ isOpen: boolean
+ onClose: () => any
+}
+
+function FeedbackModal({ isOpen, onClose }: Props) {
+ const [feedback, setFeedback] = useState('')
+ const [isSavingFeedback, setIsSavingFeedback] = useState(false)
+ const user = useUser()
+ const ref = useRef<HTMLFormElement>(null)
+
+ useOnClickOutside(ref, onClose, 'mousedown')
+
+ const addFeedback = useAddFeedback()
+
+ async function saveFeedback(
+ e: FormEvent<HTMLFormElement> | MouseEvent<HTMLButtonElement, globalThis.MouseEvent>,
+ ) {
+ e.preventDefault()
+ if (!user?.id) return
+ if (!feedback) return
+ if (isSavingFeedback) return
+
+ setIsSavingFeedback(true)
+
+ await addFeedback(feedback)
+
+ setIsSavingFeedback(false)
+ onClose()
+ }
+
+ return (
+ <div className="relative flex flex-row-reverse pt-1">
+ {isOpen &&
+ <form
+ ref={ref}
+ autoComplete="of"
+ className="
+ flex
+ p-3
+ border
+ z-50
+ bg-gray-900
+ border-gray-600
+ w-[400px]
+ rounded
+ absolute
+ flex-col
+ items-end
+ font-sans
+ space-y-3
+ "
+ onSubmit={saveFeedback}
+ >
+ <Textarea
+ value={feedback}
+ onChange={e => setFeedback(e.target.value)}
+ isOpen={isOpen}
+ />
+ <button
+ className={clsx({ 'border-white/10 text-gray-100': isOpen, 'border-white/5 text-gray-400': !isOpen }, 'group ml-auto flex items-center space-x-1 cursor-pointer py-1 px-2 rounded-md bg-gray-900 border border-white/5 hover:border-white/10 transition-all')}
+ onMouseDown={saveFeedback}
+ disabled={isSavingFeedback || feedback.trim() === ''}
+ >
+ {isSavingFeedback ? <SpinnerIcon className="text-white" /> : null}
+ {!isSavingFeedback && <span className="text-sm">Send</span>}
+ </button>
+ </form>
+ }
+ </div>
+ )
+}
+
+export default FeedbackModal
diff --git a/components/Feedback/index.tsx b/components/Feedback/index.tsx
new file mode 100644
index 000000000..6bfe22ef4
--- /dev/null
+++ b/components/Feedback/index.tsx
@@ -0,0 +1,29 @@
+import { useState } from 'react'
+
+import FeedbackButton from './FeedbackButton'
+import FeedbackModal from './FeedbackModal'
+
+function Feedback() {
+ const [isFeedbackVisible, setIsFeedbackVisible] = useState(false)
+
+ return (
+ <div className="flex flex-col items-end flex-1">
+ <div>
+ <FeedbackButton
+ isOpen={isFeedbackVisible}
+ onClick={(e) => {
+ e.preventDefault()
+ e.stopPropagation()
+ setIsFeedbackVisible(f => !f)
+ }}
+ />
+ <FeedbackModal
+ isOpen={isFeedbackVisible}
+ onClose={() => setIsFeedbackVisible(f => !f)}
+ />
+ </div>
+ </div>
+ )
+}
+
+export default Feedback
diff --git a/components/FeedbackButton.tsx b/components/FeedbackButton.tsx
deleted file mode 100644
index c07decf77..000000000
--- a/components/FeedbackButton.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-import {
- MessageCircle,
-} from 'lucide-react'
-
-export interface Props {
- onClick: (e: any) => void
-}
-
-function FeedbackButton({
- onClick,
-}: Props) {
- return (
- <button
- className="group ml-auto flex items-center space-x-1 cursor-pointer transition-all py-1 px-2 rounded-md bg-gray-900 border border-white/5 hover:border-white/10"
- onClick={onClick}
- >
- <MessageCircle size={14} className="text-gray-400 group-hover:text-gray-100 transition-all" />
- <span className="text-sm text-gray-400 group-hover:text-gray-100 transition-all">Send feedback to CEO</span>
- </button>
- )
-}
-
-export default FeedbackButton
\ No newline at end of file
diff --git a/components/Layout.tsx b/components/Layout.tsx
index 4aa0dc9dd..15a0554bb 100644
--- a/components/Layout.tsx
+++ b/components/Layout.tsx
@@ -16,7 +16,7 @@ import {
import DashboardDesktopSidebar from 'components/Sidebar/DashboardDesktopSidebar'
import DashboardMobileSidebar from 'components/Sidebar/DashboardMobileSidebar'
-import FeedbackButton from 'components/FeedbackButton'
+import Feedback from 'components/Feedback'
const inter = Inter({
subsets: ['latin'],
@@ -115,16 +115,12 @@ function Layout({ children }: PropsWithChildren) {
</button>
<div className="xl:hidden">
- <FeedbackButton
- onClick={() => { console.log('todo') }}
- />
+ <Feedback />
</div>
</div>
<div className="hidden xl:flex py-2 px-6 border-b border-white/5">
- <FeedbackButton
- onClick={() => { console.log('todo') }}
- />
+ <Feedback />
</div>
{children}
diff --git a/components/Modal.tsx b/components/Modal.tsx
new file mode 100644
index 000000000..a47679a5a
--- /dev/null
+++ b/components/Modal.tsx
@@ -0,0 +1,113 @@
+import { Dialog, Transition } from '@headlessui/react'
+import { Fragment, ReactNode } from 'react'
+
+import Text from 'components/Text'
+
+interface Props {
+ title: string
+ children: ReactNode
+ isOpen: boolean
+ onClose: () => any
+}
+
+function Modal({ title, children, isOpen, onClose }: Props) {
+ return (
+ <Transition
+ as={Fragment}
+ show={isOpen}
+ appear
+ >
+ <Dialog
+ as="div"
+ className="absolute z-10"
+ onClose={onClose}
+ >
+ <Transition.Child
+ as={Fragment}
+ enter="ease-out duration-300"
+ enterFrom="opacity-0"
+ enterTo="opacity-100"
+ leave="ease-in duration-200"
+ leaveFrom="opacity-100"
+ leaveTo="opacity-0"
+ >
+ <div className="fixed inset-0 bg-gray-900/60" />
+ </Transition.Child>
+
+ <div
+ className="
+ fixed
+ inset-0
+ flex
+ justify-center
+ overflow-y-auto
+ "
+ >
+ <div
+ className="
+ relative
+ top-[-100px]
+ flex
+ min-h-full
+ max-w-[800px]
+ flex-1
+ items-center
+ justify-center
+ p-4
+ text-center
+ "
+ >
+ <Transition.Child
+ as={Fragment}
+ enter="ease-out duration-300"
+ enterFrom="opacity-0 scale-95"
+ enterTo="opacity-100 scale-100"
+ leave="ease-in duration-200"
+ leaveFrom="opacity-100 scale-100"
+ leaveTo="opacity-0 scale-95"
+ >
+ <Dialog.Panel
+ className="
+ flex
+ w-full
+ max-w-full
+ flex-col
+ items-start
+ space-y-4
+ rounded
+ border-[1px]
+ bg-gray-900
+ p-6
+ align-middle
+ text-white
+ border-gray-700
+ shadow-lg
+ shadow-gray-900/60
+ backdrop-blur
+ transition-all
+ "
+ >
+ <div
+ className="
+ flex
+ items-center
+ justify-start
+ "
+ >
+ <Dialog.Title
+ as={Text}
+ size={Text.size.S2}
+ text={title}
+ />
+ </div>
+ {children}
+ </Dialog.Panel>
+ </Transition.Child>
+ </div>
+ </div>
+ </Dialog>
+ </Transition>
+ )
+}
+
+export default Modal
diff --git a/components/Textarea.tsx b/components/Textarea.tsx
new file mode 100644
index 000000000..8865b22ec
--- /dev/null
+++ b/components/Textarea.tsx
@@ -0,0 +1,50 @@
+import clsx from 'clsx'
+import { ChangeEvent, useEffect, useRef } from 'react'
+
+export interface Props {
+ value: string
+ className?: string
+ placeholder?: string
+ onChange: (e: ChangeEvent<HTMLTextAreaElement>) => any
+ isOpen: boolean
+}
+
+function Textarea({ value = '', className, placeholder, onChange, isOpen }: Props) {
+ const ref = useRef<HTMLTextAreaElement>(null)
+
+ useEffect(function handleFocus() {
+ if (!ref) return
+ if (isOpen) {
+ ref.current?.focus()
+ }
+ }, [isOpen])
+
+ return (
+ <textarea
+ ref={ref}
+ placeholder={placeholder}
+ value={value}
+ className={clsx(
+ 'w-full',
+ 'px-2.5',
+ 'py-2',
+ 'rounded',
+ 'border',
+ 'min-h-[200px]',
+ 'focus:outline-none',
+ 'font-sans',
+ 'border-transparent',
+ 'bg-gray-950/40',
+ 'outline-none',
+ 'transition-colors',
+ 'text-sm',
+ 'text-white',
+ 'placeholder:text-gray-100',
+ className,
+ )}
+ onChange={onChange}
+ />
+ )
+}
+
+export default Textarea
diff --git a/hooks/useAddFeedback.ts b/hooks/useAddFeedback.ts
index 7ffb492ef..4baf6fd18 100644
--- a/hooks/useAddFeedback.ts
+++ b/hooks/useAddFeedback.ts
@@ -23,7 +23,7 @@ async function handlePostFeedback(url: string, { arg }: { arg: PostFeedback }) {
export function useAddFeedback() {
const {
trigger,
- } = useSWRMutation('/api/logs', handlePostFeedback)
+ } = useSWRMutation('/api/feedback', handlePostFeedback)
return useCallback(async (feedback: string) =>
trigger({
diff --git a/pages/log/[logFileID].tsx b/pages/log/[logFileID].tsx
index 2cb4ffe22..b61a182d6 100644
--- a/pages/log/[logFileID].tsx
+++ b/pages/log/[logFileID].tsx
@@ -19,7 +19,6 @@ import AgentFunctions from 'components/AgentFunctions'
import AgentContext from 'components/AgentContext'
import AgentContextDetail from 'components/AgentContextDetail'
-
interface PathProps extends ParsedUrlQuery {
logFileID: string
}