🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Implement pagination for goals list and enhance GoalFormModal reset functionality
Bill Yang0056d506fcf4
diff --git a/client/src/app/[site]/goals/components/GoalFormModal.tsx b/client/src/app/[site]/goals/components/GoalFormModal.tsxindex e48b1f397..f0275bf61 100644--- a/client/src/app/[site]/goals/components/GoalFormModal.tsx+++ b/client/src/app/[site]/goals/components/GoalFormModal.tsx@@ -149,6 +149,10 @@ export default function GoalFormModal({});}+ // Reset form and state after successful submission+ form.reset();+ setUseProperties(false);+setIsOpen(false);} catch (error) {console.error("Error saving goal:", error);@@ -162,6 +166,7 @@ export default function GoalFormModal({setIsOpen(open);if (!open) {form.reset();+ setUseProperties(false);}}}>diff --git a/client/src/app/[site]/goals/components/GoalsList.tsx b/client/src/app/[site]/goals/components/GoalsList.tsxindex d7c43948e..e3a521f87 100644--- a/client/src/app/[site]/goals/components/GoalsList.tsx+++ b/client/src/app/[site]/goals/components/GoalsList.tsx@@ -1,78 +1,19 @@"use client";import GoalCard from "./GoalCard";-import { Button } from "../../../../components/ui/button";-import { ChevronLeft, ChevronRight } from "lucide-react";-import {- Goal,- PaginationMeta,-} from "../../../../api/analytics/goals/useGetGoals";+import { Goal } from "../../../../api/analytics/goals/useGetGoals";interface GoalsListProps {goals: Goal[];siteId: number;- paginationMeta: PaginationMeta;- onPageChange: (page: number) => void;}-export default function GoalsList({- goals,- siteId,- paginationMeta,- onPageChange,-}: GoalsListProps) {- const { page, pageSize, total, totalPages } = paginationMeta;-- const handlePrevPage = () => {- if (page > 1) {- onPageChange(page - 1);- }- };-- const handleNextPage = () => {- if (page < totalPages) {- onPageChange(page + 1);- }- };-+export default function GoalsList({ goals, siteId }: GoalsListProps) {return (- <div className="space-y-6">- <div className="flex flex-col gap-3">- {goals.map((goal) => (- <GoalCard key={goal.goalId} goal={goal} siteId={siteId} />- ))}- </div>-- {totalPages > 1 && (- <div className="flex justify-between items-center">- <div className="text-sm text-gray-500">- Showing {goals.length} of {total} goals- </div>- <div className="flex items-center space-x-2">- <Button- variant="outline"- size="sm"- onClick={handlePrevPage}- disabled={page === 1}- >- <ChevronLeft className="h-4 w-4 mr-1" />- Previous- </Button>- <div className="text-sm px-3">- Page {page} of {totalPages}- </div>- <Button- variant="outline"- size="sm"- onClick={handleNextPage}- disabled={page === totalPages}- >- Next- <ChevronRight className="h-4 w-4 ml-1" />- </Button>- </div>- </div>- )}+ <div className="flex flex-col gap-3">+ {goals.map((goal) => (+ <GoalCard key={goal.goalId} goal={goal} siteId={siteId} />+ ))}</div>);}diff --git a/client/src/app/[site]/goals/page.tsx b/client/src/app/[site]/goals/page.tsxindex 4a440d480..a1d206ac6 100644--- a/client/src/app/[site]/goals/page.tsx+++ b/client/src/app/[site]/goals/page.tsx@@ -7,6 +7,7 @@ import {} from "../../../api/analytics/goals/useGetGoals";import { DisabledOverlay } from "../../../components/DisabledOverlay";import { NothingFound } from "../../../components/NothingFound";+import { TablePagination } from "../../../components/pagination";import { useSetPageTitle } from "../../../hooks/useSetPageTitle";import { GOALS_PAGE_FILTERS, useStore } from "../../../lib/store";import { SubHeader } from "../components/SubHeader/SubHeader";@@ -18,30 +19,64 @@ export default function GoalsPage() {const { time, site } = useStore();const isPast24HoursMode = time.mode === "last-24-hours";- const [currentPage, setCurrentPage] = useState(1);- const pageSize = 9; // Show 9 cards (3x3 grid)+ const [pagination, setPagination] = useState({+ pageIndex: 0, // TablePagination uses 0-based indexing+ pageSize: 10, // Show 10 goals per page+ });// Use the appropriate hook based on the modeconst { data: goalsData, isLoading } = isPast24HoursMode? useGetGoalsPastMinutes({- page: currentPage,- pageSize,+ page: pagination.pageIndex + 1, // API uses 1-based indexing+ pageSize: pagination.pageSize,}): useGetGoals({- page: currentPage,- pageSize,+ page: pagination.pageIndex + 1, // API uses 1-based indexing+ pageSize: pagination.pageSize,});- // Handle page change- const handlePageChange = (newPage: number) => {- setCurrentPage(newPage);- // Scroll to top of page when changing pages- window.scrollTo({- top: 0,- behavior: "smooth",- });+ // Create pagination controller for TablePagination+ const paginationController = {+ getState: () => ({ pagination }),+ getCanPreviousPage: () => pagination.pageIndex > 0,+ getCanNextPage: () => {+ if (!goalsData?.meta) return false;+ return pagination.pageIndex + 1 < goalsData.meta.totalPages;+ },+ getPageCount: () => goalsData?.meta?.totalPages || 1,+ setPageIndex: (index: number) => {+ setPagination((prev) => ({ ...prev, pageIndex: index }));+ // Scroll to top of page when changing pages+ window.scrollTo({+ top: 0,+ behavior: "smooth",+ });+ },+ previousPage: () => {+ if (pagination.pageIndex > 0) {+ setPagination((prev) => ({ ...prev, pageIndex: prev.pageIndex - 1 }));+ window.scrollTo({ top: 0, behavior: "smooth" });+ }+ },+ nextPage: () => {+ if (+ goalsData?.meta &&+ pagination.pageIndex + 1 < goalsData.meta.totalPages+ ) {+ setPagination((prev) => ({ ...prev, pageIndex: prev.pageIndex + 1 }));+ window.scrollTo({ top: 0, behavior: "smooth" });+ }+ },};+ // Transform data for TablePagination+ const paginationData = goalsData+ ? {+ items: goalsData.data,+ total: goalsData.meta.total,+ }+ : undefined;+// Goal card skeleton componentconst GoalCardSkeleton = () => (<div className="rounded-lg bg-neutral-900 border border-neutral-800 overflow-hidden relative animate-pulse">@@ -108,12 +143,20 @@ export default function GoalsPage() {action={<CreateGoalButton siteId={Number(site)} />}/>) : (- <GoalsList- goals={goalsData.data}- siteId={Number(site)}- paginationMeta={goalsData.meta}- onPageChange={handlePageChange}- />+ <div className="space-y-6">+ <GoalsList goals={goalsData.data} siteId={Number(site)} />++ {goalsData.meta.totalPages > 1 && (+ <TablePagination+ table={paginationController}+ data={paginationData}+ pagination={pagination}+ setPagination={setPagination}+ isLoading={isLoading}+ itemName="goals"+ />+ )}+ </div>)}</div></DisabledOverlay>diff --git a/memory-bank/activeContext.md b/memory-bank/activeContext.mdindex 8cf9198e9..e12fffe03 100644--- a/memory-bank/activeContext.md+++ b/memory-bank/activeContext.md@@ -20,3 +20,12 @@ This file tracks the project's current status, including recent changes, current- Are there any deployment or infrastructure concerns that need attention? (Previously existing)[2025-06-08 06:42:07] - Docker build diagnosis confirmed: Build context mismatch identified as root cause. COPY shared ./shared fails because shared/ directory not present in ./server context. Dockerfiles from commit 974e6cc expect monorepo root context but CI uses subdirectory contexts.++[2025-06-09 19:42:35] - **COMPLETED: GoalFormModal Form Reset Bug Fix**++- **Issue**: Form state wasn't resetting when saving goals in GoalFormModal component+- **Root Cause**: Form was only being reset in onOpenChange handler when manually closing dialog, not after successful submission+- **Diagnosis Process**: Added debug logging to identify that form.reset() was never called after successful goal creation/update+- **Solution**: Added form.reset() and setUseProperties(false) after successful submission in onSubmit function+- **Files Modified**: [`client/src/app/[site]/goals/components/GoalFormModal.tsx`](client/src/app/[site]/goals/components/GoalFormModal.tsx:162)+- **Impact**: Form now properly clears all fields and state after successful goal creation/editing