From e4124564755051e16e6bb7fcbe78c5532a7ffffe Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:52:26 +0530 Subject: [PATCH 01/22] ProjectHub: simplify fetching and handle auth Adjust ProjectHub to match a simplified projects response and improve auth handling. Removed the auto-pagination effect and switched to using projectsResponse.projects directly. Added Asgardeo auth loading into the skeleton/loading state so the UI waits for auth, and wired MockConfig to set the ProjectCard isStatsError flag when mocks are disabled. Also added imports for navigation and providers and left a commented-out single-project auto-navigation snippet for future use. --- .../webapp/src/pages/ProjectHub.tsx | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/customer-portal/webapp/src/pages/ProjectHub.tsx b/apps/customer-portal/webapp/src/pages/ProjectHub.tsx index c18458489a..1f1a4a87d1 100644 --- a/apps/customer-portal/webapp/src/pages/ProjectHub.tsx +++ b/apps/customer-portal/webapp/src/pages/ProjectHub.tsx @@ -21,6 +21,9 @@ import { useLogger } from "@/hooks/useLogger"; import ProjectCard from "@/components/projectHub/projectCard/ProjectCard"; import ProjectCardSkeleton from "@/components/projectHub/projectCard/ProjectCardSkeleton"; import { FolderOpen } from "@wso2/oxygen-ui-icons-react"; +import { useNavigate } from "react-router"; +import { useMockConfig } from "@/providers/MockConfigProvider"; +import { useAsgardeo } from "@asgardeo/react"; /** * ProjectHub component. @@ -29,26 +32,26 @@ import { FolderOpen } from "@wso2/oxygen-ui-icons-react"; */ export default function ProjectHub(): JSX.Element { const logger = useLogger(); + const navigate = useNavigate(); + const { isLoading: isAuthLoading } = useAsgardeo(); + const { isMockEnabled } = useMockConfig(); const { data: projectsResponse, - fetchNextPage, - hasNextPage, - isFetchingNextPage, isLoading, isError, } = useGetProjects({}, true); - useEffect(() => { - if (hasNextPage && !isFetchingNextPage && !isError) { - fetchNextPage(); - } - }, [hasNextPage, isFetchingNextPage, isError, fetchNextPage]); - const projects = useMemo( - () => projectsResponse?.pages.flatMap((page) => page.projects) || [], - [projectsResponse?.pages], + () => projectsResponse?.projects || [], + [projectsResponse?.projects], ); + // useEffect(() => { + // if (!isLoading && !isError && projects.length === 1) { + // navigate(`/${projects[0].id}/dashboard`); + // } + // }, [projects, isLoading, isError, navigate]); + useEffect(() => { if (isError) { logger.error("Failed to load projects in ProjectHub"); @@ -62,7 +65,7 @@ export default function ProjectHub(): JSX.Element { }, [projects.length, logger]); const renderContent = () => { - if (isLoading) { + if (isLoading || isAuthLoading) { return ( ))} From 78124544e8c0d69b8abc1a7ecf15c4b359e1a61a Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:52:43 +0530 Subject: [PATCH 02/22] test: enhance ProjectHub tests and mocks Add and wire up mocks for useAsgardeo and useMockConfig, and update the ProjectCard mock to surface an isStatsError attribute via data-stats-error. Set sensible default mock returns in beforeEach (auth not loading, mocks enabled, projects returned). Add tests for auth-loading skeletons and for isStatsError behavior when mock config is enabled/disabled. Adjust mocked getProjects data shape in tests (use projects directly) and simplify some existing tests; remove the fetchNextPage test. Overall improves coverage and handles auth/config variations in ProjectHub tests. --- .../src/pages/__tests__/ProjectHub.test.tsx | 89 ++++++++++++------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/apps/customer-portal/webapp/src/pages/__tests__/ProjectHub.test.tsx b/apps/customer-portal/webapp/src/pages/__tests__/ProjectHub.test.tsx index 7de971a1ad..a5cfdfe0cf 100644 --- a/apps/customer-portal/webapp/src/pages/__tests__/ProjectHub.test.tsx +++ b/apps/customer-portal/webapp/src/pages/__tests__/ProjectHub.test.tsx @@ -34,9 +34,28 @@ vi.mock("@wso2/oxygen-ui-icons-react", () => ({ FolderOpen: () => , })); +// Mock useAsgardeo +const mockUseAsgardeo = vi.fn(); +vi.mock("@asgardeo/react", () => ({ + useAsgardeo: () => mockUseAsgardeo(), +})); + +// Mock useMockConfig +const mockUseMockConfig = vi.fn(); +vi.mock("@/providers/MockConfigProvider", () => ({ + useMockConfig: () => mockUseMockConfig(), +})); + // Mock sub-components vi.mock("@/components/projectHub/projectCard/ProjectCard", () => ({ - default: ({ title }: any) =>
{title}
, + default: ({ title, isStatsError }: any) => ( +
+ {title} +
+ ), })); vi.mock("@/components/projectHub/projectCard/ProjectCardSkeleton", () => ({ @@ -62,6 +81,15 @@ vi.mock("@/hooks/useLogger", () => ({ describe("ProjectHub", () => { beforeEach(() => { vi.clearAllMocks(); + mockUseAsgardeo.mockReturnValue({ isLoading: false }); + mockUseMockConfig.mockReturnValue({ isMockEnabled: true }); + mockUseGetProjects.mockReturnValue({ + isLoading: false, + data: { + projects: mockProjects, + }, + isError: false, + }); }); it("should render loading skeletons when isLoading is true", () => { @@ -76,23 +104,46 @@ describe("ProjectHub", () => { expect(screen.getAllByTestId("project-skeleton")).toHaveLength(3); }); - it("should render project cards when data is loaded", () => { + it("should render loading skeletons when isAuthLoading is true", () => { + mockUseAsgardeo.mockReturnValue({ isLoading: true }); mockUseGetProjects.mockReturnValue({ isLoading: false, - data: { - pages: [{ projects: mockProjects }], - }, + data: null, // Data might not be available yet isError: false, }); render(); + expect(screen.getAllByTestId("project-skeleton")).toHaveLength(3); + }); + + it("should render project cards when data is loaded", () => { + render(); + expect(screen.getAllByTestId("project-card")).toHaveLength( mockProjects.length, ); expect(screen.getByText(mockProjects[0].name)).toBeInTheDocument(); }); + it("should pass isStatsError=true to ProjectCard when mocks are disabled", () => { + mockUseMockConfig.mockReturnValue({ isMockEnabled: false }); + + render(); + + const cards = screen.getAllByTestId("project-card"); + expect(cards[0]).toHaveAttribute("data-stats-error", "true"); + }); + + it("should pass isStatsError=false to ProjectCard when mocks are enabled", () => { + mockUseMockConfig.mockReturnValue({ isMockEnabled: true }); + + render(); + + const cards = screen.getAllByTestId("project-card"); + expect(cards[0]).toHaveAttribute("data-stats-error", "false"); + }); + it("should render error message when isError is true", async () => { mockUseGetProjects.mockReturnValue({ isLoading: false, @@ -114,7 +165,7 @@ describe("ProjectHub", () => { mockUseGetProjects.mockReturnValue({ isLoading: false, data: { - pages: [{ projects: [] }], + projects: [], }, isError: false, }); @@ -125,14 +176,6 @@ describe("ProjectHub", () => { }); it("should log debug message when projects are loaded", async () => { - mockUseGetProjects.mockReturnValue({ - isLoading: false, - data: { - pages: [{ projects: mockProjects }], - }, - isError: false, - }); - render(); await waitFor(() => { expect(mockLogger.debug).toHaveBeenCalledWith( @@ -140,22 +183,4 @@ describe("ProjectHub", () => { ); }); }); - - it("should call fetchNextPage when hasNextPage is true", () => { - const mockFetchNextPage = vi.fn(); - mockUseGetProjects.mockReturnValue({ - isLoading: false, - data: { - pages: [{ projects: mockProjects }], - }, - fetchNextPage: mockFetchNextPage, - hasNextPage: true, - isFetchingNextPage: false, - isError: false, - }); - - render(); - - expect(mockFetchNextPage).toHaveBeenCalled(); - }); }); From db41a8773eddc112ffc821ffbdab0ca67de89971 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:52:59 +0530 Subject: [PATCH 03/22] Add ErrorIndicator handling to ProjectCardStats Introduce an optional isError prop and import ErrorIndicator. When isError is true, render ErrorIndicator for Open Cases and Active Chats instead of their numeric values, preserving the existing typography/styling otherwise. This surfaces error states in the project card stats UI. --- .../projectCard/ProjectCardStats.tsx | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCardStats.tsx b/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCardStats.tsx index 2d7f3e5691..fdbb47f31c 100644 --- a/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCardStats.tsx +++ b/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCardStats.tsx @@ -21,13 +21,14 @@ import { MessageSquare, } from "@wso2/oxygen-ui-icons-react"; import { type JSX } from "react"; +import ErrorIndicator from "@/components/common/errorIndicator/ErrorIndicator"; import { formatProjectDate } from "@/utils/projectCard"; - interface ProjectCardStatsProps { activeChats: number; date: string; openCases: number; + isError?: boolean; } /** @@ -40,6 +41,7 @@ export default function ProjectCardStats({ openCases, activeChats, date, + isError, }: ProjectCardStatsProps): JSX.Element { return ( @@ -63,9 +65,13 @@ export default function ProjectCardStats({ Open Cases - - {openCases} - + {isError ? ( + + ) : ( + + {openCases} + + )} {/* Active Chats */} @@ -81,9 +87,13 @@ export default function ProjectCardStats({ Active Chats - - {activeChats} - + {isError ? ( + + ) : ( + + {activeChats} + + )} {/* Date */} From baa00c0b33f98e732500cd8937e2861a7cb0d984 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:53:14 +0530 Subject: [PATCH 04/22] Show error indicator for project status Add an optional isError prop and import ErrorIndicator in ProjectCardBadges. When isError is true, render ErrorIndicator for the status instead of the status Chip; otherwise continue rendering the status Chip with getStatusColor. This surfaces status load errors in the project card UI. --- .../projectCard/ProjectCardBadges.tsx | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCardBadges.tsx b/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCardBadges.tsx index 5265ab148b..6ab24804b1 100644 --- a/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCardBadges.tsx +++ b/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCardBadges.tsx @@ -17,11 +17,12 @@ import { Box, Chip, Form } from "@wso2/oxygen-ui"; import { type JSX } from "react"; import { getStatusColor } from "@/utils/projectCard"; - +import ErrorIndicator from "@/components/common/errorIndicator/ErrorIndicator"; interface ProjectCardBadgesProps { projectKey: string; status: string; + isError?: boolean; } /** @@ -33,17 +34,22 @@ interface ProjectCardBadgesProps { export default function ProjectCardBadges({ projectKey, status, + isError, }: ProjectCardBadgesProps): JSX.Element { return ( - + {isError ? ( + + ) : ( + + )} ); From 0a834caa864d0065fbce7f065419eb681121c99f Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:53:26 +0530 Subject: [PATCH 05/22] Add isStatsError prop to ProjectCard Expose an optional isStatsError prop on ProjectCardProps, destructure it in the component, and forward it as isError to ProjectCardBadges and ProjectCardStats so child components can render an error state for stats. --- .../components/projectHub/projectCard/ProjectCard.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCard.tsx b/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCard.tsx index da8c56e38a..ed324f011f 100644 --- a/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCard.tsx +++ b/apps/customer-portal/webapp/src/components/projectHub/projectCard/ProjectCard.tsx @@ -38,6 +38,7 @@ export interface ProjectCardProps { status?: string; subtitle: string; title: string; + isStatsError?: boolean; } /** @@ -56,6 +57,7 @@ export default function ProjectCard({ activeChats, date, onViewDashboard, + isStatsError, }: ProjectCardProps): JSX.Element { // Hook to navigate between routes. const navigate = useNavigate(); @@ -85,7 +87,11 @@ export default function ProjectCard({ }} > {/* project card badges */} - + {/* project card info */} {/* project card stats */} @@ -93,6 +99,7 @@ export default function ProjectCard({ activeChats={resolvedActiveChats} date={date} openCases={resolvedOpenCases} + isError={isStatsError} /> {/* project card actions */} From 657394793c17b5cfd1373c22656a273de1a54e3d Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:53:37 +0530 Subject: [PATCH 06/22] Mock ErrorIndicator and add error-state test Add a mock for the ErrorIndicator component and a new test in ProjectCardStats.test.tsx that verifies error indicators are shown when isError is true (for "Open Cases" and "Active Chats") and that numeric counts are not rendered. This supplements existing tests for counts and formatted date. --- .../__tests__/ProjectCardStats.test.tsx | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCardStats.test.tsx b/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCardStats.test.tsx index b88df3a6bc..1555707ed7 100644 --- a/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCardStats.test.tsx +++ b/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCardStats.test.tsx @@ -43,6 +43,13 @@ vi.mock("@/utils/projectCard", () => ({ formatProjectDate: vi.fn((date) => `Formatted ${date}`), })); +// Mock ErrorIndicator +vi.mock("@/components/common/errorIndicator/ErrorIndicator", () => ({ + default: ({ entityName }: any) => ( +
Error: {entityName}
+ ), +})); + describe("ProjectCardStats", () => { it("should render counts and formatted date", () => { const props = { @@ -71,4 +78,19 @@ describe("ProjectCardStats", () => { expect(screen.getByTestId("alert-icon")).toBeInTheDocument(); expect(screen.getByTestId("message-icon")).toBeInTheDocument(); }); + + it("should render error indicators when isError is true", () => { + const props = { + openCases: 0, + activeChats: 0, + date: "2025-07-17", + isError: true, + }; + + render(); + + expect(screen.getByText("Error: Open Cases")).toBeInTheDocument(); + expect(screen.getByText("Error: Active Chats")).toBeInTheDocument(); + expect(screen.queryByText("0")).not.toBeInTheDocument(); + }); }); From 5654e9cdf65d9b02c23c5685d56b97173e778447 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:53:50 +0530 Subject: [PATCH 07/22] Mock ErrorIndicator and add error test Mock the ErrorIndicator component in ProjectCardBadges tests and add a test that verifies the error indicator is rendered when isError is true, while the status chip is not displayed. Updates the ProjectCardBadges.test.tsx to improve coverage for error rendering behavior. --- .../__tests__/ProjectCardBadges.test.tsx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCardBadges.test.tsx b/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCardBadges.test.tsx index a24e3edbf3..77d0fc0582 100644 --- a/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCardBadges.test.tsx +++ b/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCardBadges.test.tsx @@ -48,6 +48,13 @@ vi.mock("@/utils/projectCard", () => ({ }), })); +// Mock ErrorIndicator +vi.mock("@/components/common/errorIndicator/ErrorIndicator", () => ({ + default: ({ entityName }: any) => ( +
Error: {entityName}
+ ), +})); + describe("ProjectCardBadges", () => { it("should render project key and status", () => { const props = { @@ -73,4 +80,17 @@ describe("ProjectCardBadges", () => { const statusChip = chips.find((chip) => chip.textContent === props.status); expect(statusChip?.getAttribute("data-color")).toBe("warning"); }); + + it("should render error indicator for status when isError is true", () => { + const props = { + projectKey: "PROJ-1", + status: "All Good", + isError: true, + }; + + render(); + + expect(screen.getByText("Error: Status")).toBeInTheDocument(); + expect(screen.queryByText(props.status)).not.toBeInTheDocument(); + }); }); From 5ae5e81573f769a39c44d0e6406ec49b6c7779c4 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:54:03 +0530 Subject: [PATCH 08/22] Add isError handling and test in ProjectCard mocks Update mocked ProjectCardBadges and ProjectCardStats to accept an isError prop and render 'Error'/'No Error' accordingly. Add a new test that renders ProjectCard with isStatsError=true and asserts the badges and stats sub-components receive and display the error state. --- .../projectCard/__tests__/ProjectCard.test.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCard.test.tsx b/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCard.test.tsx index b2289ba470..934a25ef03 100644 --- a/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCard.test.tsx +++ b/apps/customer-portal/webapp/src/components/projectHub/projectCard/__tests__/ProjectCard.test.tsx @@ -31,9 +31,9 @@ vi.mock("@wso2/oxygen-ui", () => ({ // Mock sub-components vi.mock("../ProjectCardBadges", () => ({ - default: ({ projectKey, status }: any) => ( + default: ({ projectKey, status, isError }: any) => (
- {projectKey} {status} + {projectKey} {status} {isError ? "Error" : "No Error"}
), })); @@ -47,9 +47,9 @@ vi.mock("../ProjectCardInfo", () => ({ })); vi.mock("../ProjectCardStats", () => ({ - default: ({ activeChats, date, openCases }: any) => ( + default: ({ activeChats, date, openCases, isError }: any) => (
- {activeChats} {date} {openCases} + {activeChats} {date} {openCases} {isError ? "Error" : "No Error"}
), })); @@ -114,4 +114,11 @@ describe("ProjectCard", () => { expect(onViewDashboard).toHaveBeenCalled(); expect(mockNavigate).not.toHaveBeenCalled(); }); + + it("should pass isError to sub-components when isStatsError is true", () => { + render(); + + expect(screen.getByTestId("badges")).toHaveTextContent("Error"); + expect(screen.getByTestId("stats")).toHaveTextContent("Error"); + }); }); From b5777a1557c83c331251847c05646084b0f9077e Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:54:16 +0530 Subject: [PATCH 09/22] Account for auth loading and fallback in UserProfile Import MockConfigProvider and expand useAsgardeo destructure to include isSignedIn and isLoading (aliased to isAuthLoading). Update user rendering logic to show the loading state while authentication is loading, and fall back to the error user if no user data is available. Also tidy ternary formatting for readability. --- .../src/components/common/header/UserProfile.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/customer-portal/webapp/src/components/common/header/UserProfile.tsx b/apps/customer-portal/webapp/src/components/common/header/UserProfile.tsx index 7300aad7ae..818a858d26 100644 --- a/apps/customer-portal/webapp/src/components/common/header/UserProfile.tsx +++ b/apps/customer-portal/webapp/src/components/common/header/UserProfile.tsx @@ -17,6 +17,7 @@ import { Skeleton, UserMenu } from "@wso2/oxygen-ui"; import type { JSX } from "react"; import { useNavigate } from "react-router"; +import { useMockConfig } from "@/providers/MockConfigProvider"; import { useAsgardeo } from "@asgardeo/react"; import { User } from "@wso2/oxygen-ui-icons-react"; import { useLogger } from "@/hooks/useLogger"; @@ -31,7 +32,8 @@ import ErrorIndicator from "@/components/common/errorIndicator/ErrorIndicator"; export default function UserProfile(): JSX.Element { // Navigation hook. const navigate = useNavigate(); - const { signOut } = useAsgardeo(); + const { signOut, isSignedIn, isLoading: isAuthLoading } = useAsgardeo(); + const { isMockEnabled } = useMockConfig(); const { data: userDetails, isLoading, isError } = useGetUserDetails(); // Logger hook. @@ -68,7 +70,12 @@ export default function UserProfile(): JSX.Element { avatar: , }; - const userToRender = isLoading ? loadingUser : isError ? errorUser : user; + const userToRender = + isLoading || isAuthLoading + ? loadingUser + : isError + ? errorUser + : user || errorUser; return ( <> From c9038cf6f304f57aee7d35074ddfd760e988788b Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:54:46 +0530 Subject: [PATCH 10/22] Switch projects hook to useQuery with auth/mock Replace useInfiniteQuery with useQuery in useGetProjects. Integrate Asgardeo auth to obtain ID token and add MockConfigProvider support to return paginated mock data (with API_MOCK_DELAY). Update queryKey to include mock flag, simplify pagination to offset/limit, and remove infinite pagination handlers. Implement real backend POST to /projects/search with Authorization and error handling, add logger messages, and gate execution via an enabled flag (mock enabled or user signed in and auth not loading). --- .../webapp/src/api/useGetProjects.ts | 111 +++++++++++------- 1 file changed, 71 insertions(+), 40 deletions(-) diff --git a/apps/customer-portal/webapp/src/api/useGetProjects.ts b/apps/customer-portal/webapp/src/api/useGetProjects.ts index a10783257c..053206a96f 100644 --- a/apps/customer-portal/webapp/src/api/useGetProjects.ts +++ b/apps/customer-portal/webapp/src/api/useGetProjects.ts @@ -14,11 +14,9 @@ // specific language governing permissions and limitations // under the License. -import { - useInfiniteQuery, - type UseInfiniteQueryResult, - type InfiniteData, -} from "@tanstack/react-query"; +import { useQuery, type UseQueryResult } from "@tanstack/react-query"; +import { useAsgardeo } from "@asgardeo/react"; +import { useMockConfig } from "@/providers/MockConfigProvider"; import { useLogger } from "@/hooks/useLogger"; import { mockProjects } from "@/models/mockData"; import { ApiQueryKeys, API_MOCK_DELAY } from "@/constants/apiConstants"; @@ -27,62 +25,95 @@ import type { SearchProjectsResponse } from "@/models/responses"; /** * Custom hook to search projects. - * This hook uses an infinite query to fetch projects in pages. + * This hook uses a standard query to fetch projects. * * @param {SearchProjectsRequest} searchData - The search and pagination parameters. * @param {boolean} fetchAll - If true, treats this as a shared "all projects" query. - * @returns {UseInfiniteQueryResult, Error>} The infinite query result object. + * @returns {UseQueryResult} The query result object. */ export default function useGetProjects( searchData?: SearchProjectsRequest, fetchAll: boolean = false, -): UseInfiniteQueryResult, Error> { +): UseQueryResult { const logger = useLogger(); + const { getIdToken, isSignedIn, isLoading: isAuthLoading } = useAsgardeo(); + const { isMockEnabled } = useMockConfig(); const limit = fetchAll ? 100 : searchData?.pagination?.limit || 10; + const offset = searchData?.pagination?.offset || 0; // A stable key for the "all projects" query ensures cache sharing const queryKey = fetchAll - ? [ApiQueryKeys.PROJECTS, "all"] - : [ApiQueryKeys.PROJECTS, searchData ?? "default"]; + ? [ApiQueryKeys.PROJECTS, "all", isMockEnabled] + : [ApiQueryKeys.PROJECTS, searchData ?? "default", isMockEnabled]; - return useInfiniteQuery({ - getPreviousPageParam: (firstPage) => { - const prevOffset = firstPage.offset - limit; - return prevOffset >= 0 ? prevOffset : undefined; - }, - getNextPageParam: (lastPage) => { - const nextOffset = lastPage.offset + limit; - return nextOffset < lastPage.totalRecords ? nextOffset : undefined; - }, - initialPageParam: 0, - queryFn: async ({ pageParam = 0 }): Promise => { + return useQuery({ + queryKey, + queryFn: async (): Promise => { logger.debug( - `Fetching projects... offset: ${pageParam}, limit: ${limit}, fetchAll: ${fetchAll}`, + `Fetching projects... offset: ${offset}, limit: ${limit}, fetchAll: ${fetchAll}, mock: ${isMockEnabled}`, ); - // Mock behavior: simulate network latency for the in-memory `mockProjects` data. - await new Promise((resolve) => setTimeout(resolve, API_MOCK_DELAY)); + if (isMockEnabled) { + // Mock behavior: simulate network latency for the in-memory `mockProjects` data. + await new Promise((resolve) => setTimeout(resolve, API_MOCK_DELAY)); + + const results: SearchProjectsResponse = { + limit, + offset, + projects: mockProjects + .slice(offset, offset + limit) + .map((project) => ({ + createdOn: project.createdOn, + description: project.description, + id: project.id, + key: project.key, + name: project.name, + })), + totalRecords: mockProjects.length, + }; + + logger.debug("Projects fetched successfully (mock)", results); - const offset = typeof pageParam === "number" ? pageParam : 0; + return results; + } - const results: SearchProjectsResponse = { - limit, - offset, - projects: mockProjects.slice(offset, offset + limit).map((project) => ({ - createdOn: project.createdOn, - description: project.description, - id: project.id, - key: project.key, - name: project.name, - })), - totalRecords: mockProjects.length, - }; + try { + const idToken = await getIdToken(); + const baseUrl = import.meta.env.CUSTOMER_PORTAL_BACKEND_BASE_URL; - logger.debug("Projects fetched successfully", results); + if (!baseUrl) { + throw new Error("CUSTOMER_PORTAL_BACKEND_BASE_URL is not configured"); + } - return results; + const requestUrl = `${baseUrl}/projects/search`; + const body = {}; + + const response = await fetch(requestUrl, { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + Authorization: `Bearer ${idToken}`, + "x-user-id-token": idToken, + }, + body: JSON.stringify(body), + }); + + logger.debug(`[useGetProjects] Response status: ${response.status}`); + + if (!response.ok) { + throw new Error(`Error fetching projects: ${response.statusText}`); + } + + const data: SearchProjectsResponse = await response.json(); + logger.debug("[useGetProjects] Data received:", data); + return data; + } catch (error) { + logger.error("[useGetProjects] Error:", error); + throw error; + } }, - queryKey, staleTime: Infinity, + enabled: isMockEnabled || (isSignedIn && !isAuthLoading), }); } From d212839b330173a26e1c4a8a8c1158df7fda8bac Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:55:01 +0530 Subject: [PATCH 11/22] Enable user details query only when authenticated Use isSignedIn and isLoading (aliased to isAuthLoading) from useAsgardeo and update the react-query `enabled` flag so the request only runs when mock mode is active or the user is signed in and auth loading has finished. This prevents the user details fetch from firing prematurely while authentication state is still being determined. --- apps/customer-portal/webapp/src/api/useGetUserDetails.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/customer-portal/webapp/src/api/useGetUserDetails.ts b/apps/customer-portal/webapp/src/api/useGetUserDetails.ts index 8b38d92218..24d6cb9d92 100644 --- a/apps/customer-portal/webapp/src/api/useGetUserDetails.ts +++ b/apps/customer-portal/webapp/src/api/useGetUserDetails.ts @@ -27,7 +27,7 @@ import { useLogger } from "@/hooks/useLogger"; * @returns {UseQueryResult} The user details. */ const useGetUserDetails = (): UseQueryResult => { - const { getIdToken } = useAsgardeo(); + const { getIdToken, isSignedIn, isLoading: isAuthLoading } = useAsgardeo(); const { isMockEnabled } = useMockConfig(); const logger = useLogger(); @@ -77,7 +77,7 @@ const useGetUserDetails = (): UseQueryResult => { throw error; } }, - enabled: true, + enabled: isMockEnabled || (isSignedIn && !isAuthLoading), }); }; From a456618efc939dec9655068923c66883827acaa4 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:55:15 +0530 Subject: [PATCH 12/22] Default size and scale TriangleAlert icon Set a default size prop ('small') for ErrorIndicator and compute an iconSize (16/24/32 for small/medium/large). Pass the computed iconSize to TriangleAlert and use the size prop directly on IconButton (removing the redundant fallback). This ensures consistent visual scaling and prevents undefined size values. --- .../components/common/errorIndicator/ErrorIndicator.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/customer-portal/webapp/src/components/common/errorIndicator/ErrorIndicator.tsx b/apps/customer-portal/webapp/src/components/common/errorIndicator/ErrorIndicator.tsx index 0a93b33174..3790a1d61b 100644 --- a/apps/customer-portal/webapp/src/components/common/errorIndicator/ErrorIndicator.tsx +++ b/apps/customer-portal/webapp/src/components/common/errorIndicator/ErrorIndicator.tsx @@ -31,12 +31,14 @@ interface ErrorIndicatorProps { */ export default function ErrorIndicator({ entityName, - size, + size = "small", }: ErrorIndicatorProps): JSX.Element { + const iconSize = size === "small" ? 16 : size === "medium" ? 24 : 32; + return ( - - + + ); From 5926674894255f69d9a8247fae88c58a77bd3e84 Mon Sep 17 00:00:00 2001 From: "K.Dileepa Thushan Peiris" Date: Thu, 5 Feb 2026 01:55:27 +0530 Subject: [PATCH 13/22] Enhance Header tests for auth & project errors Add a mock for useAsgardeo and extend the ProjectSwitcher test mock to include an isError prop (exposed via data-error). Add tests to verify that Header forwards auth loading (isLoading from useAsgardeo) to ProjectSwitcher and that search projects errors set isError on ProjectSwitcher. Also adjust mocked ProjectSwitcher props handling to assert these behaviors. --- .../common/header/__tests__/Header.test.tsx | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/customer-portal/webapp/src/components/common/header/__tests__/Header.test.tsx b/apps/customer-portal/webapp/src/components/common/header/__tests__/Header.test.tsx index 34951e2259..7de7abc25f 100644 --- a/apps/customer-portal/webapp/src/components/common/header/__tests__/Header.test.tsx +++ b/apps/customer-portal/webapp/src/components/common/header/__tests__/Header.test.tsx @@ -134,12 +134,27 @@ vi.mock("../SearchBar", () => ({ default: () =>
, })); +// Mock useAsgardeo +const mockUseAsgardeo = vi.fn(() => ({ + isLoading: false, +})); +vi.mock("@asgardeo/react", () => ({ + useAsgardeo: () => mockUseAsgardeo(), +})); + vi.mock("../ProjectSwitcher", () => ({ - default: ({ projects, selectedProject, onProjectChange, isLoading }: any) => ( + default: ({ + projects, + selectedProject, + onProjectChange, + isLoading, + isError, + }: any) => (