Skip to content

Commit

Permalink
fix: person loading skeleton (formbricks#3160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhruwang authored Sep 19, 2024
1 parent 6b64367 commit 0b55344
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,37 @@ export const PersonDataView = ({ environment, personCount, itemsPerPage }: Perso
};

fetchData();
}, [pageNumber]);
}, [pageNumber, personCount, itemsPerPage, environment.id]);

// Fetch additional person attributes and update table data
useEffect(() => {
const fetchAttributes = async () => {
const updatedPersonTableData = await Promise.all(
persons.map(async (person) => {
const attributes = await getPersonAttributesAction({
environmentId: environment.id,
personId: person.id,
});
return {
createdAt: person.createdAt,
personId: person.id,
userId: person.userId,
email: attributes?.data?.email ?? "",
attributes: attributes?.data ?? {},
};
})
);
setPersonTableData(updatedPersonTableData);
setIsDataLoaded(true);
try {
const updatedPersonTableData = await Promise.all(
persons.map(async (person) => {
const attributes = await getPersonAttributesAction({
environmentId: environment.id,
personId: person.id,
});
return {
createdAt: person.createdAt,
personId: person.id,
userId: person.userId,
email: attributes?.data?.email ?? "",
attributes: attributes?.data ?? {},
};
})
);
setPersonTableData(updatedPersonTableData);
} catch (error) {
console.error("Error fetching person attributes:", error);
} finally {
setIsDataLoaded(true);
}
};

if (persons.length > 0) {
fetchAttributes();
}
}, [persons]);
fetchAttributes();
}, [persons, environment.id]);

const fetchNextPage = async () => {
if (hasMore && !loadingNextPage) {
Expand All @@ -91,7 +94,7 @@ export const PersonDataView = ({ environment, personCount, itemsPerPage }: Perso
};

const deletePersons = (personIds: string[]) => {
setPersons(persons.filter((p) => !personIds.includes(p.id)));
setPersons((prevPersons) => prevPersons.filter((p) => !personIds.includes(p.id)));
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PersonDataView } from "@/app/(app)/environments/[environmentId]/(people)/people/components/PersonDataView";
import { PersonSecondaryNavigation } from "@/app/(app)/environments/[environmentId]/(people)/people/components/PersonSecondaryNavigation";
import { CircleHelpIcon } from "lucide-react";
import { ITEMS_PER_PAGE } from "@formbricks/lib/constants";
import { getEnvironment } from "@formbricks/lib/environment/service";
import { getPersonCount } from "@formbricks/lib/person/service";
import { Button } from "@formbricks/ui/Button";
Expand Down Expand Up @@ -32,7 +31,7 @@ const Page = async ({ params }: { params: { environmentId: string } }) => {
<PageHeader pageTitle="People" cta={HowToAddPeopleButton}>
<PersonSecondaryNavigation activeId="people" environmentId={params.environmentId} />
</PageHeader>
<PersonDataView environment={environment} personCount={personCount} itemsPerPage={ITEMS_PER_PAGE} />
<PersonDataView environment={environment} personCount={personCount} itemsPerPage={25} />
</PageContentWrapper>
);
};
Expand Down

0 comments on commit 0b55344

Please sign in to comment.