mirror of
https://github.com/supabase/supabase.git
synced 2026-07-07 11:40:20 +08:00
Add a docs feedback widget to allow upvoting and downvoting pages. Votes (completely anonymized, barely more than a counter) go to a database in the main supabase-com project. If the user has accepted telemetry, the votes also go to Logflare with a bit more info. Post-vote, logged-in users can leave a comment, which goes to the `platform/feedback/send` endpoint. There is a warning in the feedback modal that the feedback is not anonymous.
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { Button, Form, Input, Modal } from 'ui'
|
|
|
|
export type FeedbackFields = {
|
|
page: string
|
|
comment: string
|
|
}
|
|
|
|
type FeedbackModalProps = {
|
|
visible: boolean
|
|
page: string
|
|
onCancel: () => void
|
|
onSubmit: (values: FeedbackFields) => void
|
|
}
|
|
|
|
function FeedbackModal({ visible, page, onCancel, onSubmit }: FeedbackModalProps) {
|
|
return (
|
|
<Modal hideFooter header="Leave a comment" visible={visible} onEscapeKeyDown={onCancel}>
|
|
<Form
|
|
initialValues={{ page, comment: '' }}
|
|
validateOnBlur
|
|
validate={(vals) => {
|
|
const errors: Partial<FeedbackFields> = {}
|
|
|
|
if (!vals.comment) {
|
|
errors.comment = 'Required'
|
|
}
|
|
|
|
return errors
|
|
}}
|
|
onReset={onCancel}
|
|
onSubmit={onSubmit}
|
|
>
|
|
{({ isSubmitting }: { isSubmitting: boolean }) => (
|
|
<>
|
|
<Modal.Content className="pt-4 pb-2">
|
|
<Input type="hidden" id="page" name="page" value={page} />
|
|
<Input.TextArea
|
|
label="Comment"
|
|
id="comment"
|
|
name="comment"
|
|
size="medium"
|
|
className="mb-2"
|
|
textAreaClassName="resize-none"
|
|
afterLabel=" (not anonymous)"
|
|
/>
|
|
</Modal.Content>
|
|
<Modal.Separator />
|
|
<Modal.Content className="pt-2 pb-4">
|
|
<div className="flex items-center justify-end gap-2">
|
|
<Button htmlType="reset" type="default" onClick={onCancel} disabled={isSubmitting}>
|
|
Cancel
|
|
</Button>
|
|
<Button htmlType="submit" loading={isSubmitting} disabled={isSubmitting}>
|
|
Submit feedback
|
|
</Button>
|
|
</div>
|
|
</Modal.Content>
|
|
</>
|
|
)}
|
|
</Form>
|
|
</Modal>
|
|
)
|
|
}
|
|
|
|
export { FeedbackModal }
|