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

[FEATURE] Move Survey Overview Page to Server Components #515

Closed
mattinannt opened this issue Jul 10, 2023 · 2 comments · Fixed by #554
Closed

[FEATURE] Move Survey Overview Page to Server Components #515

mattinannt opened this issue Jul 10, 2023 · 2 comments · Fixed by #554
Assignees
Labels
enhancement New feature or request

Comments

@mattinannt
Copy link
Member

Over the last few months the future of Next.js & React got unveiled. At Formbricks we started using the app directory pretty early but at that point it wasn't clear how data-fetching and mutation should work in Server Components so we kept the client-side approach with APIs & SWR. But now we would like to make the switch to Next.js and React how Vercel imagines it to use the newest performance and DX optimizations Vercel introduces.

To have a better approach for data-fetching and type safety we are now moving to internal data services, e.g. a getSurveys() method to retrieve all the surveys of the current user. The Typescript type of a survey is standardised in a Zod Schema. That way we can also format data in a more convenient way in the app and keep this separated from the way we store in in a relational database. E.g. our Person object got a lot simpler to use that way because we don't need to think about the complex relational model that is used for storing.

You can find the new services in packages/lib/services and the Zod schemas in packages/types/v1

Please use this approach together with the information from Next.js on Server-Components to build a new Survey Overview page ( apps/web/app/environments/[environmentId]/surveys ). For data-fetching use our services in the Server-Components and build new Services if necessary. Use Client-Components only for the small parts where client-side functionality is really needed. For Data-Mutation use Server-Actions.

(We already recently moved the People Overview to Server Components, you can also check it out for reference)

TODO:

  • Use our internal services for data fetching and data mutation (packages/lib/services) (create new services or zod schemas if necessary)
  • Use Client Components only when needed and let Server Components be the default
  • Use Server-Actions when data mutation is needed

See Next.js documentation for examples and explanations: https://nextjs.org/docs/getting-started/react-essentials

How we code at Formbricks 🤓

  • Everything is type-safe
  • All UI components are in the package formbricks/ui
  • Run pnpm dev to find a demo app to test in-app surveys at localhost:3002
  • We use chatGPT to help refactor code. Use our Formbricks ✨ megaprompt ✨ to create the right context before you write your prompt.
@mattinannt mattinannt added the enhancement New feature or request label Jul 10, 2023
@Ankur-Datta-4
Copy link
Contributor

I'd like to work on this issue @mattinannt . Also the services developed for Issue- #473 can be used. So shall I work on the branch which deals with that, on #488 ?

@mattinannt
Copy link
Member Author

I'd like to work on this issue @mattinannt . Also the services developed for Issue- #473 can be used. So shall I work on the branch which deals with that, on #488 ?

I would like to keep them in separate PRs to make the review and merge process easier 😊 But you can copy the services/types from this PR into your feature code and we can see what we get merged first 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants