-
Notifications
You must be signed in to change notification settings - Fork 44
feat(canvas): add Leave feedback survey modal to Channels view #2792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
raquelmsmith
merged 4 commits into
main
from
posthog-code/channels-leave-feedback-modal
Jun 20, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3dc9389
feat(canvas): add Leave feedback survey modal to Channels view
raquelmsmith d13dcdf
refactor(canvas): fix feedback modal padding and reset, parameterise …
raquelmsmith 1bb3379
fix(canvas): use quill Textarea for feedback input
raquelmsmith 69da6e9
style(canvas): wrap FeedbackModal JSX to satisfy Biome format
raquelmsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
81 changes: 81 additions & 0 deletions
81
packages/ui/src/features/canvas/components/FeedbackModal.test.tsx
This file contains hidden or 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,81 @@ | ||
| import { Theme } from "@radix-ui/themes"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| const { captureSurveyResponse } = vi.hoisted(() => ({ | ||
| captureSurveyResponse: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@posthog/ui/shell/analytics", () => ({ captureSurveyResponse })); | ||
|
|
||
| import { FeedbackModal, type FeedbackModalMode } from "./FeedbackModal"; | ||
|
|
||
| function renderModal(mode: FeedbackModalMode | null, onFinished = vi.fn()) { | ||
| render( | ||
| <Theme> | ||
| <FeedbackModal mode={mode} onFinished={onFinished} /> | ||
| </Theme>, | ||
| ); | ||
| return onFinished; | ||
| } | ||
|
|
||
| describe("FeedbackModal", () => { | ||
| beforeEach(() => { | ||
| captureSurveyResponse.mockReset(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| { mode: "leaving" as const, expected: "Skip", missing: "Cancel" }, | ||
| { mode: "feedback" as const, expected: "Cancel", missing: "Skip" }, | ||
| ])( | ||
| "shows the $expected secondary button in $mode mode", | ||
| ({ mode, expected, missing }) => { | ||
| renderModal(mode); | ||
| expect( | ||
| screen.getByRole("button", { name: expected }), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.queryByRole("button", { name: missing }), | ||
| ).not.toBeInTheDocument(); | ||
| }, | ||
| ); | ||
|
|
||
| it("disables submit until text is entered", async () => { | ||
| const user = userEvent.setup(); | ||
| renderModal("feedback"); | ||
| const submit = screen.getByRole("button", { name: "Send feedback" }); | ||
| // The quill Button signals disabled state via aria-disabled, not the native attr. | ||
| expect(submit).toHaveAttribute("aria-disabled", "true"); | ||
|
|
||
| await user.type(screen.getByPlaceholderText("Share your feedback"), "hi"); | ||
| expect(submit).not.toHaveAttribute("aria-disabled", "true"); | ||
| }); | ||
|
|
||
| it("captures the trimmed response and finishes on submit", async () => { | ||
| const user = userEvent.setup(); | ||
| const onFinished = renderModal("leaving"); | ||
|
|
||
| await user.type( | ||
| screen.getByPlaceholderText("Share your feedback"), | ||
| " great work ", | ||
| ); | ||
| await user.click(screen.getByRole("button", { name: "Send feedback" })); | ||
|
|
||
| expect(captureSurveyResponse).toHaveBeenCalledTimes(1); | ||
| expect(captureSurveyResponse).toHaveBeenCalledWith( | ||
| expect.objectContaining({ response: "great work" }), | ||
| ); | ||
| expect(onFinished).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("finishes without capturing when skipped", async () => { | ||
| const user = userEvent.setup(); | ||
| const onFinished = renderModal("leaving"); | ||
|
|
||
| await user.click(screen.getByRole("button", { name: "Skip" })); | ||
|
|
||
| expect(captureSurveyResponse).not.toHaveBeenCalled(); | ||
| expect(onFinished).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
110 changes: 110 additions & 0 deletions
110
packages/ui/src/features/canvas/components/FeedbackModal.tsx
This file contains hidden or 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,110 @@ | ||
| import { | ||
| Button, | ||
| Dialog, | ||
| DialogBody, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| Textarea, | ||
| } from "@posthog/quill"; | ||
| import { | ||
| FEEDBACK_SURVEY_ID, | ||
| FEEDBACK_SURVEY_QUESTION_ID, | ||
| } from "@posthog/ui/features/canvas/feedbackSurvey"; | ||
| import { captureSurveyResponse } from "@posthog/ui/shell/analytics"; | ||
| import { useState } from "react"; | ||
|
|
||
| export type FeedbackModalMode = "feedback" | "leaving"; | ||
|
|
||
| export interface FeedbackModalProps { | ||
| /** `null` closes the modal. `"leaving"` shows a Skip button, `"feedback"` a Cancel button. */ | ||
| mode: FeedbackModalMode | null; | ||
| /** Called after the response is submitted, and when the modal is skipped/cancelled/dismissed. */ | ||
| onFinished: () => void; | ||
| } | ||
|
|
||
| /** | ||
| * Feedback modal for the Channels space. Submitting records the text as a | ||
| * PostHog survey response (see {@link FEEDBACK_SURVEY_ID}). The secondary button | ||
| * reads "Skip" when opened by "Go back to Code" (`mode === "leaving"`) and | ||
| * "Cancel" when opened by "Leave feedback". | ||
| */ | ||
| export function FeedbackModal({ mode, onFinished }: FeedbackModalProps) { | ||
| const open = mode !== null; | ||
|
|
||
| return ( | ||
| <Dialog | ||
| open={open} | ||
| onOpenChange={(isOpen) => { | ||
| // Esc / outside-click dismiss behaves like the secondary button. | ||
| if (!isOpen) onFinished(); | ||
| }} | ||
| > | ||
| <DialogContent showCloseButton={false} className="sm:max-w-md"> | ||
| <DialogHeader> | ||
| <DialogTitle>Leave feedback</DialogTitle> | ||
| <DialogDescription> | ||
| How's the Channels experience? Tell us what's working and what you'd | ||
| change. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| {/* Mounted only while open so the textarea resets on each open without | ||
| syncing state to the `mode` prop in an effect. */} | ||
| {mode !== null && ( | ||
| <FeedbackModalForm mode={mode} onFinished={onFinished} /> | ||
| )} | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
|
|
||
| function FeedbackModalForm({ | ||
| mode, | ||
| onFinished, | ||
| }: { | ||
| mode: FeedbackModalMode; | ||
| onFinished: () => void; | ||
| }) { | ||
| const [value, setValue] = useState(""); | ||
|
|
||
| const handleSubmit = () => { | ||
| const response = value.trim(); | ||
| if (!response) return; | ||
| captureSurveyResponse({ | ||
| surveyId: FEEDBACK_SURVEY_ID, | ||
| questionId: FEEDBACK_SURVEY_QUESTION_ID, | ||
| response, | ||
| }); | ||
| onFinished(); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <DialogBody> | ||
| <Textarea | ||
| value={value} | ||
| onChange={(event) => setValue(event.target.value)} | ||
| placeholder="Share your feedback" | ||
| rows={4} | ||
| maxLength={4000} | ||
| autoFocus | ||
| /> | ||
| </DialogBody> | ||
| <DialogFooter> | ||
| <Button variant="outline" size="sm" onClick={onFinished}> | ||
| {mode === "leaving" ? "Skip" : "Cancel"} | ||
| </Button> | ||
| <Button | ||
| variant="primary" | ||
| size="sm" | ||
| disabled={value.trim().length === 0} | ||
| onClick={handleSubmit} | ||
| > | ||
| Send feedback | ||
| </Button> | ||
| </DialogFooter> | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or 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,8 @@ | ||
| // PostHog survey backing the Channels "Leave feedback" modal. Created via the | ||
| // MCP in project 2 ("PostHog App + Website") and launched so it collects | ||
| // responses. Responses are sent client-side as a `survey sent` event and only | ||
| // attach to this survey if the app reports to the same project. | ||
| // https://us.posthog.com/project/2/surveys/019ee235-2e3b-0000-64b3-5f2efa487452 | ||
| export const FEEDBACK_SURVEY_ID = "019ee235-2e3b-0000-64b3-5f2efa487452"; | ||
| export const FEEDBACK_SURVEY_QUESTION_ID = | ||
| "d1b5bf40-c255-434f-8799-d4ca13873d74"; |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.