Skip to content
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

feat: Add a onPreviewSubmit callback to preview surveys #1641

Merged
merged 3 commits into from
Jan 7, 2025

Conversation

lucasheriques
Copy link
Contributor

Changes

Adds a new onPreviewSubmit parameter to renderSurveysPreview.

The main usage of renderSurveysPreview is on posthog internal website to demo surveys.

By adding this callback, it allow us to call arbitrary functions after pressing the submit button in the survey.

It'll be used to fix this issue: PostHog/posthog#23650 and allow us to move to the next question after clicking the submit button.

...

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Jan 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Jan 7, 2025 2:34pm

Copy link

github-actions bot commented Jan 6, 2025

Size Change: +3.86 kB (+0.12%)

Total Size: 3.23 MB

Filename Size Change
dist/all-external-dependencies.js 207 kB +408 B (+0.2%)
dist/array.full.es5.js 263 kB +854 B (+0.33%)
dist/array.full.js 366 kB +408 B (+0.11%)
dist/array.full.no-external.js 365 kB +408 B (+0.11%)
dist/array.js 180 kB +23 B (+0.01%)
dist/array.no-external.js 179 kB +23 B (+0.01%)
dist/main.js 181 kB +23 B (+0.01%)
dist/module.full.js 366 kB +408 B (+0.11%)
dist/module.full.no-external.js 365 kB +408 B (+0.11%)
dist/module.js 180 kB +23 B (+0.01%)
dist/module.no-external.js 179 kB +23 B (+0.01%)
dist/surveys-preview.js 58 kB +436 B (+0.76%)
dist/surveys.js 63.7 kB +416 B (+0.66%)
ℹ️ View Unchanged
Filename Size
dist/customizations.full.js 12.6 kB
dist/dead-clicks-autocapture.js 14.4 kB
dist/exception-autocapture.js 9.48 kB
dist/external-scripts-loader.js 2.64 kB
dist/recorder-v2.js 115 kB
dist/recorder.js 115 kB
dist/tracing-headers.js 1.76 kB
dist/web-vitals.js 10.4 kB

compressed-size-action

const surveyPreviewRef = useRef<HTMLDivElement>(null)
const [currentPageIndex, setCurrentPageIndex] = useState(0)

console.log('Current page index:', currentPageIndex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this log here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add a linter to forbid this

@@ -618,6 +627,7 @@ export function Questions({
originalQuestionIndex,
displayQuestionIndex,
}),
onPreviewSubmit: (res) => onPreviewSubmit(res),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onPreviewSubmit: (res) => onPreviewSubmit(res),
onPreviewSubmit,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks updated both!

@rafaeelaudibert
Copy link
Member

Not sure if the team has let you known how posthog-js versioning works, but you can add a bump minor or bump patch label to this PR and some GitHub Actions will be triggered to actually release that - and bump it in our main repo.

Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks solid to me!

@lucasheriques lucasheriques added the bump minor Bump minor version when this PR gets merged label Jan 7, 2025
@lucasheriques lucasheriques merged commit 30f0d49 into main Jan 7, 2025
29 checks passed
@lucasheriques lucasheriques deleted the feat/new-on-preview-submit-callback branch January 7, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump minor Bump minor version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants