Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions components/Dashboard/FormPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TooltipProvider,
TooltipTrigger,
} from '@/components/ui/tooltip'
import { useListForms } from '@/hooks/query/form'
import {useGetFormResponsesByProjectId, useListForms} from '@/hooks/query/form'
import { useSelectedProject } from '@/hooks/query/project'
import { cn } from '@/lib/utils'
import {
Expand Down Expand Up @@ -45,6 +45,7 @@ const actionButtons = [
},
]


const FormPane: React.FC = () => {
const { project } = useSelectedProject()
const { forms } = useListForms(project?.id)
Expand Down Expand Up @@ -105,6 +106,16 @@ const FormPane: React.FC = () => {
}
}

const projectId = project?.id || ""
const { data: formResponses } = useGetFormResponsesByProjectId(projectId)

const getResponseCount = (formId: string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please wrap this in useMemo() hook

if (formResponses && formResponses.pages[0].getFormResponsesByProjectId) {
return formResponses.pages[0].getFormResponsesByProjectId?.length;
}
return 0;
};

return (
<div className="mt-4 flex flex-col gap-1">
{forms?.map((form, index) => (
Expand Down Expand Up @@ -140,7 +151,11 @@ const FormPane: React.FC = () => {
{form?.name}
</span>
<span className="flex items-center gap-1 truncate text-sm text-gray-500">
0 responses. Created{' '}
<Link href="/dashboard/web/testimonials" className="underline">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Handle the check for 0 responses also,
if the value of responses is 0 then show the 0 responses text else the <Link> component

{getResponseCount(form?.id || '')}{' '}
{getResponseCount(form?.id || '') === 1 ? 'response' : 'responses'}.
</Link>
Created{' '}
{form?.createdAt && formatToLocalDateTime(form?.createdAt)}
</span>
</p>
Expand Down