-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a modal which allows users to provide more feedback
- Loading branch information
Showing
2 changed files
with
98 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as React from 'react'; | ||
import { | ||
Button, | ||
Dialog, | ||
DialogContent, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
} from '@srcbook/components'; | ||
import TextareaAutosize from 'react-textarea-autosize'; | ||
|
||
interface AiFeedbackModalProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
onSubmit: (feedback: string) => void; | ||
} | ||
|
||
export function AiFeedbackModal({ isOpen, onClose, onSubmit }: AiFeedbackModalProps) { | ||
const [feedback, setFeedback] = React.useState(''); | ||
|
||
const handleSubmit = () => { | ||
onSubmit(feedback); | ||
setFeedback(''); | ||
onClose(); | ||
}; | ||
|
||
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { | ||
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) { | ||
e.preventDefault(); | ||
handleSubmit(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Dialog open={isOpen} onOpenChange={onClose}> | ||
<DialogContent className="sm:max-w-[425px]"> | ||
<DialogHeader> | ||
<DialogTitle>Provide Feedback</DialogTitle> | ||
</DialogHeader> | ||
<div className="grid gap-4 py-4"> | ||
<TextareaAutosize | ||
placeholder="Tell us more about what went wrong..." | ||
className="flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring" | ||
value={feedback} | ||
onChange={(e) => setFeedback(e.target.value)} | ||
onKeyDown={handleKeyDown} | ||
minRows={3} | ||
maxRows={10} | ||
/> | ||
</div> | ||
<DialogFooter> | ||
<Button variant="ghost" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
<Button onClick={handleSubmit}>Submit Feedback</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters