Skip to content

Commit 26d6441

Browse files
authored
Merge pull request #49 from git-vish/development
fe: fix pagination
2 parents 28a1974 + cd996d4 commit 26d6441

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

backend/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ GOOGLE_CLIENT_SECRET=your_google_oauth_client_secret
2121
# Obtain an API key from https://console.groq.com/keys
2222
GROQ_API_KEY=your_groq_api_key
2323

24-
# *** LangChain Tracing (Optional) ***
24+
# *** LangChain Tracing ***
2525
# Sign up at https://smith.langchain.com
2626
LANGCHAIN_API_KEY=your_langchain_api_key
2727
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com

frontend/components/form/form-responses.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
2424
import { FORM_URLS } from "@/config/api-urls";
2525
import { tokenService } from "@/lib/services/token";
2626
import { formatDate, formatDateTime } from "@/lib/utils";
27+
import { useForms } from "@/hooks/use-forms";
2728

28-
// Define response type based on your API structure
2929
interface FormResponse {
3030
id: string;
3131
created_at: string;
@@ -42,9 +42,15 @@ export default function FormResponses({ form }: FormResponsesProps) {
4242
const [error, setError] = useState<string | null>(null);
4343
const [pagination, setPagination] = useState<PaginationState>({
4444
pageIndex: 0,
45-
pageSize: 10, // Fixed page size
45+
pageSize: 1,
4646
});
4747

48+
const { forms, isLoading: formsLoading } = useForms();
49+
const totalResponses = useMemo(() => {
50+
const matchedForm = forms.find((f) => f.id === form.id);
51+
return matchedForm ? matchedForm.response_count : 0;
52+
}, [forms, form.id]);
53+
4854
// Fetch form responses
4955
useEffect(() => {
5056
async function fetchResponses() {
@@ -91,7 +97,6 @@ export default function FormResponses({ form }: FormResponsesProps) {
9197
const columns = useMemo<ColumnDef<FormResponse>[]>(() => {
9298
if (!form.fields || responses.length === 0) return [];
9399

94-
// Base columns
95100
const baseColumns: ColumnDef<FormResponse>[] = [
96101
{
97102
accessorKey: "created_at",
@@ -103,14 +108,11 @@ export default function FormResponses({ form }: FormResponsesProps) {
103108
},
104109
];
105110

106-
// Dynamically generate columns from form fields
107111
const fieldColumns = form.fields.map((field) => ({
108112
accessorKey: `answers.${field.tag}`,
109113
header: field.label,
110114
cell: ({ getValue }: { getValue: () => unknown }) => {
111115
const value = getValue();
112-
113-
// Handle different field type rendering
114116
switch (field.type) {
115117
case "multi_select":
116118
return Array.isArray(value) ? value.join(", ") : value;
@@ -138,12 +140,11 @@ export default function FormResponses({ form }: FormResponsesProps) {
138140
state: {
139141
pagination,
140142
},
141-
pageCount: Math.ceil(responses.length / pagination.pageSize),
143+
pageCount: Math.ceil(totalResponses / pagination.pageSize),
142144
onPaginationChange: setPagination,
143145
});
144146

145-
// Render loading state
146-
if (isLoading) {
147+
if (isLoading || formsLoading) {
147148
return (
148149
<div className="mx-auto my-8 space-y-6">
149150
<Card>
@@ -158,7 +159,6 @@ export default function FormResponses({ form }: FormResponsesProps) {
158159
);
159160
}
160161

161-
// Render error state
162162
if (error) {
163163
return (
164164
<div className="mx-auto my-8 space-y-6">
@@ -217,7 +217,6 @@ export default function FormResponses({ form }: FormResponsesProps) {
217217
</ScrollArea>
218218

219219
<div className="flex items-center justify-center px-2">
220-
{/* Pagination controls */}
221220
<div className="flex items-center space-x-2">
222221
<Button
223222
variant="outline"

0 commit comments

Comments
 (0)