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

Rewrite Person Detail Page to Server-side Component #609

Merged
merged 14 commits into from
Aug 6, 2023

Conversation

ShubhamPalriwala
Copy link
Contributor

What does this PR do?

Migrates the /environments/[environmentId]/people/[personId]/ page to server side component leveraging:

  • Server-Components
  • Server-Actions
  • Loading skeleton with pulse animation
  • Removes the usage of 1 big DB query to multiple modular smaller services!

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change adds a new database migration
  • This change requires a documentation update

Checklist

  • Added a screen recording or screenshots to this PR
  • Filled out the "How to test" section in this PR
  • Read the contributing guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • Updated the Formbricks Docs if changes were necessary

@vercel
Copy link

vercel bot commented Jul 24, 2023

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

Name Status Preview Comments Updated (UTC)
formbricks-cloud ❌ Failed (Inspect) Aug 6, 2023 7:54am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
formbricks-com ⬜️ Ignored (Inspect) Visit Preview Aug 6, 2023 7:54am

Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

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

🙏
I just took a first look and continue the review next week. Here are a first few comments :-)

Copy link
Member

Choose a reason for hiding this comment

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

please add

export const revalidate = REVALIDATION_INTERVAL;

import { REVALIDATION_INTERVAL } from "@formbricks/lib/constants";

on top of the file to make sure nextjs invalidates cache once in a while to show the new responses/displays/...
when not set the only option to get new data is to hard refresh (F5) the page.

displays = displays ?? [];

const surveyIds = responses?.map((response) => response.surveyId) || [];
const surveys = await Promise.all(surveyIds.map((surveyIdx) => getSurvey(surveyIdx)));
Copy link
Member

Choose a reason for hiding this comment

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

I think for the database it could be faster to call getSurveys() because it can list all surveys with just one call instead of making multiple database calls for the surveys needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, added a check to only fetch the surveys in the environment if the user atleast has one response, this would help reduce the extra DB calls to fetch the surveys even when a user has no responses!

@@ -88,3 +89,17 @@ export const ZResponseUpdateInput = z.object({
});

export type TResponseUpdateInput = z.infer<typeof ZResponseUpdateInput>;

export const ZResponseWithSurveyData = z.object({
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to have a type for the response card. We can maybe wait with this until we have the redesigned response card (PR in the making by contributor).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, we can wait on this prolly haha 🤞🏼

import { TResponseWithSurveyData } from "@formbricks/types/v1/responses";

export default async function PersonPage({ params }) {
let [personWithAttributes, displays, sessionsWithActions, responses] = await Promise.all([
Copy link
Member

Choose a reason for hiding this comment

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

you don't need to fetch all these in page.tsx. You can also fetch them in the server-component you need it. Next.js takes care of caching and deduping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done! took some time for this, let me know what you think

Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

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

@ShubhamPalriwala The overall structure is great but there were a few things I thought could be simplified or renamed to make it more consistent. For example I moved the whole types and services needed for the activityFeed into a custom prisma call inside the activity service to not make the other services more complicated for an activity feature that will probably need changing in the near future.
You can review the my commits to see what changed 😊
I will merge the changes into main now 💪

@mattinannt mattinannt merged commit fdb1aa2 into main Aug 6, 2023
5 of 6 checks passed
@mattinannt mattinannt deleted the shubham/for-903-rewrite-person-detail-page branch August 6, 2023 07:53
waseemrabani pushed a commit to LuminosoInsight/formbricks that referenced this pull request Feb 2, 2024
* feat: migration /[personId] page to server side

* feat: decouple components in person page

* fix: ZDisplaysWithSurveyName now extends the ZDisplay type

* feat: drop custom service and use existing service for survey and response

* run pnpm format

* shift data fetching to component level but still server side

* rename event to action

* move special person services to activity service

* remove activityFeedItem type in ActivityFeed

* simplify TResponseWithSurvey

---------

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
waseemrabani pushed a commit to LuminosoInsight/formbricks that referenced this pull request Feb 2, 2024
* feat: migration /[personId] page to server side

* feat: decouple components in person page

* fix: ZDisplaysWithSurveyName now extends the ZDisplay type

* feat: drop custom service and use existing service for survey and response

* run pnpm format

* shift data fetching to component level but still server side

* rename event to action

* move special person services to activity service

* remove activityFeedItem type in ActivityFeed

* simplify TResponseWithSurvey

---------

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
waseemrabani pushed a commit to LuminosoInsight/formbricks that referenced this pull request Feb 2, 2024
* feat: migration /[personId] page to server side

* feat: decouple components in person page

* fix: ZDisplaysWithSurveyName now extends the ZDisplay type

* feat: drop custom service and use existing service for survey and response

* run pnpm format

* shift data fetching to component level but still server side

* rename event to action

* move special person services to activity service

* remove activityFeedItem type in ActivityFeed

* simplify TResponseWithSurvey

---------

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants