From 860f1298b6c77c9b4dd93150b73edba9d3c24196 Mon Sep 17 00:00:00 2001 From: 2003dinijay Date: Mon, 13 Jul 2026 10:47:48 +0530 Subject: [PATCH 1/4] [CSM Portal Microapp] Add a Settings section under More (Users/Roles/Groups/Permissions) Mirrors the webapp's admin Settings panel (CsmAdminLayout + CsmUsersPage): a Users tab with search/role/status filtering backed by POST /users/search, plus Roles/Groups/Permissions as WIP tabs reusing the existing ComingSoonPage. Reached from More > Settings, last in the list to match CSM_NAV_ITEMS. The Settings component is self-contained (owns its own data fetching and state) so it can be relocated to a different page without rewiring. --- apps/csm-portal/microapp/src/App.tsx | 2 + .../src/components/common/ComingSoonPage.tsx | 10 +- .../microapp/src/components/layout/TopBar.tsx | 2 - .../src/components/settings/Settings.tsx | 167 ++++++++++++++++++ .../src/components/settings/UserCard.tsx | 95 ++++++++++ .../components/settings/UsersFiltersSheet.tsx | 141 +++++++++++++++ .../src/components/settings/config.ts | 79 +++++++++ .../src/components/settings/filters.ts | 36 ++++ .../microapp/src/config/endpoints.ts | 1 + .../microapp/src/pages/MorePage.tsx | 15 +- .../microapp/src/pages/ProfilePage.tsx | 109 +----------- .../microapp/src/pages/SettingsPage.tsx | 24 +++ .../microapp/src/services/adminUsers.ts | 57 ++++++ .../microapp/src/types/adminUser.dto.ts | 92 ++++++++++ .../microapp/src/types/adminUser.model.ts | 62 +++++++ apps/csm-portal/microapp/src/types/index.ts | 2 + 16 files changed, 783 insertions(+), 111 deletions(-) create mode 100644 apps/csm-portal/microapp/src/components/settings/Settings.tsx create mode 100644 apps/csm-portal/microapp/src/components/settings/UserCard.tsx create mode 100644 apps/csm-portal/microapp/src/components/settings/UsersFiltersSheet.tsx create mode 100644 apps/csm-portal/microapp/src/components/settings/config.ts create mode 100644 apps/csm-portal/microapp/src/components/settings/filters.ts create mode 100644 apps/csm-portal/microapp/src/pages/SettingsPage.tsx create mode 100644 apps/csm-portal/microapp/src/services/adminUsers.ts create mode 100644 apps/csm-portal/microapp/src/types/adminUser.dto.ts create mode 100644 apps/csm-portal/microapp/src/types/adminUser.model.ts diff --git a/apps/csm-portal/microapp/src/App.tsx b/apps/csm-portal/microapp/src/App.tsx index e4de3a891f..2ca96dc19a 100644 --- a/apps/csm-portal/microapp/src/App.tsx +++ b/apps/csm-portal/microapp/src/App.tsx @@ -30,6 +30,7 @@ import TimeCardsPage from "@pages/TimeCardsPage"; import SecurityCenterPage from "@pages/SecurityCenterPage"; import UpdatesPage from "@pages/UpdatesPage"; import EngagementsPage from "@pages/EngagementsPage"; +import SettingsPage from "@pages/SettingsPage"; import ProfilePage from "@pages/ProfilePage"; export default function App() { @@ -68,6 +69,7 @@ export default function App() { } /> } /> } /> + } /> } /> diff --git a/apps/csm-portal/microapp/src/components/common/ComingSoonPage.tsx b/apps/csm-portal/microapp/src/components/common/ComingSoonPage.tsx index f2ff1ae5ed..6796b7c185 100644 --- a/apps/csm-portal/microapp/src/components/common/ComingSoonPage.tsx +++ b/apps/csm-portal/microapp/src/components/common/ComingSoonPage.tsx @@ -19,20 +19,26 @@ import { Card, Chip, Stack, Typography } from "@wso2/oxygen-ui"; interface ComingSoonPageProps { title: string; description: string; + blockedOn?: string; } // Placeholder for microapp sections not yet built, mirroring the webapp's CsmComingSoonPage // (apps/csm-portal/webapp/src/features/csm-coming-soon/pages/CsmComingSoonPage.tsx) — used // deliberately so a reserved tab/route feels real instead of dead or missing. -export function ComingSoonPage({ title, description }: ComingSoonPageProps) { +export function ComingSoonPage({ title, description, blockedOn }: ComingSoonPageProps) { return ( {title} - + {description} + {blockedOn && ( + + Blocked on: {blockedOn} + + )} ); diff --git a/apps/csm-portal/microapp/src/components/layout/TopBar.tsx b/apps/csm-portal/microapp/src/components/layout/TopBar.tsx index a8498caae0..9a1625fb21 100644 --- a/apps/csm-portal/microapp/src/components/layout/TopBar.tsx +++ b/apps/csm-portal/microapp/src/components/layout/TopBar.tsx @@ -52,8 +52,6 @@ export function TopBar() { ) : ( - // Mirrors the webapp's Brand (apps/csm-portal/webapp/src/components/header/Brand.tsx): - // same logo asset + "CSM Portal" title, shown on root pages in place of the back button. Company Logo diff --git a/apps/csm-portal/microapp/src/components/settings/Settings.tsx b/apps/csm-portal/microapp/src/components/settings/Settings.tsx new file mode 100644 index 0000000000..771e67ed82 --- /dev/null +++ b/apps/csm-portal/microapp/src/components/settings/Settings.tsx @@ -0,0 +1,167 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import { useEffect, useRef, useState } from "react"; +import { Badge, Chip, IconButton, Stack, Tab, Tabs, Typography } from "@wso2/oxygen-ui"; +import { SlidersHorizontal } from "@wso2/oxygen-ui-icons-react"; +import { useInfiniteQuery } from "@tanstack/react-query"; +import { adminUsers } from "@src/services/adminUsers"; +import { ComingSoonPage } from "@components/common/ComingSoonPage"; +import { EmptyState } from "@components/support/EmptyState"; +import { ErrorState } from "@components/support/ErrorState"; +import { SearchBar } from "@components/support/SearchBar"; +import { useDebouncedValue } from "@utils/useDebouncedValue"; +import { ADMIN_TABS, type AdminTabId } from "./config"; +import { UserCard, UserCardSkeleton } from "./UserCard"; +import { UsersFiltersSheet } from "./UsersFiltersSheet"; +import { EMPTY_USERS_FILTERS, countActiveUsersFilters, toUserSearchFilters, type UsersFilters } from "./filters"; + +// The account-administration section: mirrors the webapp's CsmAdminLayout (Users/Roles/Groups/ +// Permissions tabs, only Users built) rather than personal profile editing. Deliberately +// self-contained — it owns its own tab state, search/filters, and data fetching — so it's a +// drop-in that can move to a different page later without threading state through props. +export default function Settings() { + const [tab, setTab] = useState("users"); + const activeTab = ADMIN_TABS.find((t) => t.id === tab) ?? ADMIN_TABS[0]; + + return ( + + Settings + + setTab(value)}> + {ADMIN_TABS.map((t) => ( + + {t.label} + {t.wip && ( + + )} + + } + /> + ))} + + + {activeTab.id === "users" ? ( + + ) : ( + + )} + + ); +} + +function UsersTab() { + const [search, setSearch] = useState(""); + const debouncedSearch = useDebouncedValue(search, 300); + const [filters, setFilters] = useState(EMPTY_USERS_FILTERS); + const [filtersOpen, setFiltersOpen] = useState(false); + const activeFilterCount = countActiveUsersFilters(filters); + + const { data, isLoading, isError, refetch, fetchNextPage, hasNextPage, isFetchingNextPage } = useInfiniteQuery( + adminUsers.infinite(toUserSearchFilters(debouncedSearch, filters)), + ); + + const sentinelRef = useRef(null); + useEffect(() => { + const el = sentinelRef.current; + if (!el) return; + + const observer = new IntersectionObserver( + ([entry]) => { + if (entry?.isIntersecting && hasNextPage && !isFetchingNextPage) { + void fetchNextPage(); + } + }, + { threshold: 0.1 }, + ); + observer.observe(el); + return () => observer.disconnect(); + }, [hasNextPage, isFetchingNextPage, fetchNextPage]); + + const users = data?.pages.flatMap((page) => page.users) ?? []; + const total = data?.pages[0]?.total ?? users.length; + + return ( + + + Search across username and email. Filter by role and status. + + + + + + setFiltersOpen(true)}> + + + + + + {isLoading ? ( + + ) : isError ? ( + void refetch()} /> + ) : users.length === 0 ? ( + + ) : ( + + + {users.length} of {total} + + + {users.map((user) => ( + + ))} + + {/* IntersectionObserver can miss a zero-height target, so give the sentinel 1px to observe. */} +
+ + {isFetchingNextPage && } + {!hasNextPage && ( + + You're all caught up! + + )} + + )} + + setFiltersOpen(false)} + filters={filters} + onApply={setFilters} + /> + + ); +} + +function UsersSkeleton() { + return ( + + {Array.from({ length: 6 }).map((_, index) => ( + + ))} + + ); +} diff --git a/apps/csm-portal/microapp/src/components/settings/UserCard.tsx b/apps/csm-portal/microapp/src/components/settings/UserCard.tsx new file mode 100644 index 0000000000..e9b16ae441 --- /dev/null +++ b/apps/csm-portal/microapp/src/components/settings/UserCard.tsx @@ -0,0 +1,95 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import { Card, Chip, Skeleton, Stack, Typography } from "@wso2/oxygen-ui"; +import type { AdminUser } from "@src/types"; +import { INTERNAL_USER_ROLES } from "./config"; + +// Mobile-card equivalent of the webapp's CsmUsersPage table row: username, name, email, role +// chips (or the postgres-source userType when roles aren't present), active/inactive status, and +// timezone — same fields, same fallbacks ("—"). +export function UserCard({ user }: { user: AdminUser }) { + return ( + + + + + {user.userName} + + {user.active !== undefined && ( + + )} + + + + {user.name || "—"} + + + {user.email} + + + + {user.roles && user.roles.length > 0 ? ( + user.roles.map((role) => ( + + )) + ) : user.userType ? ( + + ) : null} + + + + {user.timezone ?? "—"} + + + + ); +} + +export function UserCardSkeleton() { + return ( + + + + + + + + + + + + + + + ); +} diff --git a/apps/csm-portal/microapp/src/components/settings/UsersFiltersSheet.tsx b/apps/csm-portal/microapp/src/components/settings/UsersFiltersSheet.tsx new file mode 100644 index 0000000000..e9a391f724 --- /dev/null +++ b/apps/csm-portal/microapp/src/components/settings/UsersFiltersSheet.tsx @@ -0,0 +1,141 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import { useEffect, useState } from "react"; +import { + Button, + Chip, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + Divider, + IconButton, + Stack, + Typography, +} from "@wso2/oxygen-ui"; +import { X } from "@wso2/oxygen-ui-icons-react"; +import type { AdminUserRole } from "@src/types"; +import { ALL_USER_ROLES, USER_ROLE_LABELS } from "./config"; +import { EMPTY_USERS_FILTERS, type UsersFilters } from "./filters"; + +const STATUS_OPTIONS: { value: UsersFilters["active"]; label: string }[] = [ + { value: "all", label: "All" }, + { value: "active", label: "Active" }, + { value: "inactive", label: "Inactive" }, +]; + +function toggleRole(roles: AdminUserRole[], role: AdminUserRole): AdminUserRole[] { + return roles.includes(role) ? roles.filter((r) => r !== role) : [...roles, role]; +} + +interface UsersFiltersSheetProps { + open: boolean; + onClose: () => void; + filters: UsersFilters; + onApply: (filters: UsersFilters) => void; +} + +// Mobile bottom-sheet equivalent of the webapp's CsmUsersPage filter row (role multi-select + +// status select), mirroring the microapp's own support/FiltersSheet.tsx bottom-sheet pattern. +export function UsersFiltersSheet({ open, onClose, filters, onApply }: UsersFiltersSheetProps) { + const [draft, setDraft] = useState(filters); + + // Re-seed the draft from the last-applied filters each time the sheet opens, so reopening it + // doesn't show stale in-progress edits from a previous open that was dismissed without applying. + useEffect(() => { + if (open) setDraft(filters); + // eslint-disable-next-line react-hooks/exhaustive-deps -- only re-seed on open, not on every filters identity change + }, [open]); + + return ( + + + Filters + + + + + + + + + + + Roles + + {ALL_USER_ROLES.map((role) => { + const isSelected = draft.roles.includes(role); + return ( + setDraft({ ...draft, roles: toggleRole(draft.roles, role) })} + /> + ); + })} + + + + + Status + + {STATUS_OPTIONS.map((option) => { + const isSelected = draft.active === option.value; + return ( + setDraft({ ...draft, active: option.value })} + /> + ); + })} + + + + + + + + + + + + + ); +} diff --git a/apps/csm-portal/microapp/src/components/settings/config.ts b/apps/csm-portal/microapp/src/components/settings/config.ts new file mode 100644 index 0000000000..d30331e580 --- /dev/null +++ b/apps/csm-portal/microapp/src/components/settings/config.ts @@ -0,0 +1,79 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import type { AdminUserRole } from "@src/types"; + +// Mirrors the webapp's ALL_ROLES/INTERNAL_USER_ROLES (apps/csm-portal/webapp/src/features/csm-users/pages/CsmUsersPage.tsx). +export const INTERNAL_USER_ROLES: AdminUserRole[] = ["internal", "agent", "admin"]; + +export const ALL_USER_ROLES: AdminUserRole[] = [ + ...INTERNAL_USER_ROLES, + "commenter", + "external", + "customer", + "customer_admin", + "partner", + "partner_admin", +]; + +export const USER_ROLE_LABELS: Record = { + internal: "Internal", + agent: "Agent", + admin: "Admin", + commenter: "Commenter", + external: "External", + customer: "Customer", + customer_admin: "Customer admin", + partner: "Partner", + partner_admin: "Partner admin", +}; + +export type AdminTabId = "users" | "roles" | "groups" | "permissions"; + +export interface AdminTabConfig { + id: AdminTabId; + label: string; + wip?: boolean; + description?: string; + blockedOn?: string; +} + +// Mirrors the webapp's ADMIN_TABS (apps/csm-portal/webapp/src/features/csm-admin/pages/CsmAdminLayout.tsx) +// and the CsmComingSoonPage copy each WIP tab renders (App.tsx's /admin/* routes). +export const ADMIN_TABS: AdminTabConfig[] = [ + { id: "users", label: "Users" }, + { + id: "roles", + label: "Roles", + wip: true, + description: "Role-based access control: define roles and their permission sets.", + blockedOn: "csm-portal/backend roles endpoints", + }, + { + id: "groups", + label: "Groups", + wip: true, + description: "User groups for bulk role assignment and access control.", + blockedOn: "csm-portal/backend groups endpoints", + }, + { + id: "permissions", + label: "Permissions", + wip: true, + description: "Fine-grained permission catalog and assignment view.", + blockedOn: "csm-portal/backend permissions endpoints", + }, +]; diff --git a/apps/csm-portal/microapp/src/components/settings/filters.ts b/apps/csm-portal/microapp/src/components/settings/filters.ts new file mode 100644 index 0000000000..f6363dc18a --- /dev/null +++ b/apps/csm-portal/microapp/src/components/settings/filters.ts @@ -0,0 +1,36 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import type { AdminUserRole, UserSearchFiltersDto } from "@src/types"; + +export interface UsersFilters { + roles: AdminUserRole[]; + active: "all" | "active" | "inactive"; +} + +export const EMPTY_USERS_FILTERS: UsersFilters = { roles: [], active: "all" }; + +export function countActiveUsersFilters(filters: UsersFilters): number { + return filters.roles.length + (filters.active !== "all" ? 1 : 0); +} + +export function toUserSearchFilters(search: string, filters: UsersFilters): UserSearchFiltersDto { + return { + ...(search.length > 0 && { searchQuery: search }), + ...(filters.roles.length > 0 && { roles: filters.roles }), + ...(filters.active !== "all" && { active: filters.active === "active" }), + }; +} diff --git a/apps/csm-portal/microapp/src/config/endpoints.ts b/apps/csm-portal/microapp/src/config/endpoints.ts index 51bd08b058..31606dbf71 100644 --- a/apps/csm-portal/microapp/src/config/endpoints.ts +++ b/apps/csm-portal/microapp/src/config/endpoints.ts @@ -21,6 +21,7 @@ if (!BACKEND_URL) { } export const USERS_ME_ENDPOINT = "/users/me"; +export const USERS_SEARCH_ENDPOINT = "/users/search"; export const CASES_ENDPOINT = "/cases"; export const CASES_SEARCH_ENDPOINT = "/cases/search"; diff --git a/apps/csm-portal/microapp/src/pages/MorePage.tsx b/apps/csm-portal/microapp/src/pages/MorePage.tsx index 8d1c38d1ad..7380b646b3 100644 --- a/apps/csm-portal/microapp/src/pages/MorePage.tsx +++ b/apps/csm-portal/microapp/src/pages/MorePage.tsx @@ -16,7 +16,15 @@ import { Link } from "react-router-dom"; import { List, ListItemButton, ListItemIcon, ListItemText, Stack, Typography } from "@wso2/oxygen-ui"; -import { Briefcase, ChevronRight, Clock, RefreshCw, Shield, type LucideIcon } from "@wso2/oxygen-ui-icons-react"; +import { + Briefcase, + ChevronRight, + Clock, + RefreshCw, + Settings, + Shield, + type LucideIcon, +} from "@wso2/oxygen-ui-icons-react"; interface MoreItem { label: string; @@ -25,13 +33,14 @@ interface MoreItem { } // Secondary sections that don't get their own tab, mirroring a subset of the webapp's -// CSM_NAV_ITEMS (apps/csm-portal/webapp/src/config/csmNavItems.ts) — Customers and Settings are -// deliberately left out here. +// CSM_NAV_ITEMS (apps/csm-portal/webapp/src/config/csmNavItems.ts) — Customers is deliberately +// left out here. Settings is last, same position it has in CSM_NAV_ITEMS. const MORE_ITEMS: MoreItem[] = [ { label: "Time Cards", path: "/more/time-cards", icon: Clock }, { label: "Security Center", path: "/more/security-center", icon: Shield }, { label: "Updates", path: "/more/updates", icon: RefreshCw }, { label: "Engagements", path: "/more/engagements", icon: Briefcase }, + { label: "Settings", path: "/more/settings", icon: Settings }, ]; export default function MorePage() { diff --git a/apps/csm-portal/microapp/src/pages/ProfilePage.tsx b/apps/csm-portal/microapp/src/pages/ProfilePage.tsx index 167db52cb9..3831f50abc 100644 --- a/apps/csm-portal/microapp/src/pages/ProfilePage.tsx +++ b/apps/csm-portal/microapp/src/pages/ProfilePage.tsx @@ -14,27 +14,14 @@ // specific language governing permissions and limitations // under the License. -import { Suspense, useEffect, useMemo, useState, type ReactNode } from "react"; -import { - Avatar, - Button, - Divider, - FormControl, - InputLabel, - MenuItem, - Select, - Skeleton, - Stack, - TextField, - Typography, -} from "@wso2/oxygen-ui"; -import { useMutation, useQueryClient, useQueryErrorResetBoundary, useSuspenseQuery } from "@tanstack/react-query"; +import { Suspense, type ReactNode } from "react"; +import { Avatar, Divider, Skeleton, Stack, TextField, Typography } from "@wso2/oxygen-ui"; +import { useQueryErrorResetBoundary, useSuspenseQuery } from "@tanstack/react-query"; import { users } from "@src/services/users"; -import type { UserMeUpdateDto, UserProfile } from "@src/types"; +import type { UserProfile } from "@src/types"; import { useUserStore } from "@src/store/user"; import { ErrorBoundary } from "@components/common/ErrorBoundary"; import { ErrorState } from "@components/support/ErrorState"; -import { listSupportedTimeZones } from "@utils/dateTime"; import { initialsOf } from "@utils/initials"; export default function ProfilePage() { @@ -53,99 +40,13 @@ export default function ProfilePage() { function ProfileContent() { const { data: profile } = useSuspenseQuery(users.me()); - const queryClient = useQueryClient(); - const timeZoneOptions = useMemo(() => listSupportedTimeZones(), []); - - const [phoneNumber, setPhoneNumber] = useState(profile.phoneNumber ?? ""); - const [timeZone, setTimeZone] = useState(profile.timeZone ?? ""); - - const isDirty = phoneNumber !== (profile.phoneNumber ?? "") || timeZone !== (profile.timeZone ?? ""); - - // A background refetch (window refocus, cache invalidation elsewhere) must not clobber an - // in-progress edit. Only re-seed from the server once the local draft matches it again, e.g. - // right after this page's own save invalidates the query. - useEffect(() => { - if (isDirty) return; - setPhoneNumber(profile.phoneNumber ?? ""); - setTimeZone(profile.timeZone ?? ""); - }, [profile, isDirty]); - - const mutation = useMutation({ - mutationFn: users.updateMe, - onSuccess: () => { - void queryClient.invalidateQueries({ queryKey: ["users", "me"] }); - }, - }); - - const handleSave = () => { - const payload: UserMeUpdateDto = {}; - if (phoneNumber !== (profile.phoneNumber ?? "")) payload.phoneNumber = phoneNumber; - if (timeZone !== (profile.timeZone ?? "")) payload.timeZone = timeZone; - if (Object.keys(payload).length === 0) return; - mutation.mutate(payload); - }; return ( - - - - { - if (mutation.isSuccess || mutation.isError) mutation.reset(); - setPhoneNumber(event.target.value); - }} - size="small" - fullWidth - disabled={mutation.isPending} - /> - - - - Time Zone - - - - - - - {mutation.isSuccess && ( - - Profile updated. - - )} - {mutation.isError && ( - - Failed to update profile. Please try again. - - )} - + ); } diff --git a/apps/csm-portal/microapp/src/pages/SettingsPage.tsx b/apps/csm-portal/microapp/src/pages/SettingsPage.tsx new file mode 100644 index 0000000000..6903d971c3 --- /dev/null +++ b/apps/csm-portal/microapp/src/pages/SettingsPage.tsx @@ -0,0 +1,24 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import Settings from "@components/settings/Settings"; + +// Reached from More > Settings, mirroring the webapp's /admin route. Settings itself is +// self-contained (components/settings/Settings.tsx) — this page is just its mount point, so it +// stays trivial to move elsewhere again later. +export default function SettingsPage() { + return ; +} diff --git a/apps/csm-portal/microapp/src/services/adminUsers.ts b/apps/csm-portal/microapp/src/services/adminUsers.ts new file mode 100644 index 0000000000..627a9010cf --- /dev/null +++ b/apps/csm-portal/microapp/src/services/adminUsers.ts @@ -0,0 +1,57 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import { infiniteQueryOptions } from "@tanstack/react-query"; +import { USERS_SEARCH_ENDPOINT } from "@config/endpoints"; +import type { UserSearchFiltersDto, UserSearchPayloadDto, UserSearchResponseDto } from "@src/types"; +import { toAdminUser, type AdminUser } from "@src/types"; +import apiClient from "./apiClient"; + +export interface AdminUserSearchResult { + users: AdminUser[]; + total: number; + limit: number; + offset: number; + hasMore: boolean; +} + +const searchUsers = async (payload: UserSearchPayloadDto = {}): Promise => { + const { data } = await apiClient.post(USERS_SEARCH_ENDPOINT, payload); + const users = data.users.map(toAdminUser); + // The ServiceNow envelope omits `hasMore`; derive it the same way the webapp's + // normalizeUserSearchResponse does (csmUsers.ts). + const hasMore = data.hasMore ?? data.offset + users.length < data.total; + return { users, total: data.total, limit: data.limit, offset: data.offset, hasMore }; +}; + +const ADMIN_USERS_PAGE_LIMIT = 20; + +export const adminUsers = { + // Mirrors the webapp's useSearchUsers.ts (POST /users/search), paged via infinite scroll — + // the mobile equivalent of CsmUsersPage's TablePagination. + infinite: (filters: UserSearchFiltersDto) => + infiniteQueryOptions({ + queryKey: ["admin-users", "infinite", filters], + queryFn: ({ pageParam }) => + searchUsers({ + filters, + sortBy: { field: "name", order: "asc" }, + pagination: { offset: pageParam, limit: ADMIN_USERS_PAGE_LIMIT }, + }), + initialPageParam: 0, + getNextPageParam: (lastPage) => (lastPage.hasMore ? lastPage.offset + lastPage.limit : undefined), + }), +}; diff --git a/apps/csm-portal/microapp/src/types/adminUser.dto.ts b/apps/csm-portal/microapp/src/types/adminUser.dto.ts new file mode 100644 index 0000000000..1d1d16a347 --- /dev/null +++ b/apps/csm-portal/microapp/src/types/adminUser.dto.ts @@ -0,0 +1,92 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +export type AdminUserType = "internal" | "customer"; + +// Mirrors the webapp's SnUserRole (apps/csm-portal/webapp/src/features/csm-users/types/csmUsers.ts). +export type AdminUserRole = + | "internal" + | "agent" + | "admin" + | "commenter" + | "external" + | "customer" + | "customer_admin" + | "partner" + | "partner_admin"; + +export type AdminUserSortField = "name" | "createdOn" | "updatedOn"; +export type AdminUserSortOrder = "asc" | "desc"; + +/** User shape returned by the postgres data source. */ +export interface UserDto { + id: string; + userName: string; + firstName: string; + lastName: string; + email: string; + phone?: string | null; + timezone?: string | null; + userType: AdminUserType; + createdAt: string; + updatedAt: string; +} + +/** + * User shape returned by the ServiceNow data source. No `firstName`/`lastName` + * (use `name`), no `userType` (use `roles`), no `hasMore` on the envelope. + */ +export interface SnUserDto { + id: string; + userName: string; + name: string; + email: string; + timeZone?: string | null; + active: boolean; + createdOn: string; + updatedOn: string; + roles: string[]; +} + +export interface UserSearchFiltersDto { + searchQuery?: string; + /** ServiceNow data source only. */ + roles?: AdminUserRole[]; + /** ServiceNow data source only. */ + active?: boolean; +} + +export interface UserSearchPayloadDto { + pagination?: { + limit?: number; + offset?: number; + }; + filters?: UserSearchFiltersDto; + sortBy?: { + field: AdminUserSortField; + order?: AdminUserSortOrder; + }; +} + +/** `/users/search` returns a `oneOf` (postgres `UserDto` vs ServiceNow `SnUserDto`). */ +export interface UserSearchResponseDto { + users: (UserDto | SnUserDto)[]; + total: number; + limit: number; + offset: number; + /** Absent from the ServiceNow envelope; derived from `offset`/`total` when missing. */ + hasMore?: boolean; +} diff --git a/apps/csm-portal/microapp/src/types/adminUser.model.ts b/apps/csm-portal/microapp/src/types/adminUser.model.ts new file mode 100644 index 0000000000..9b699da3fa --- /dev/null +++ b/apps/csm-portal/microapp/src/types/adminUser.model.ts @@ -0,0 +1,62 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import type { AdminUserType, SnUserDto, UserDto } from "./adminUser.dto"; + +/** + * Source-agnostic row the UI renders. Both {@link UserDto} and {@link SnUserDto} + * normalize into this so the list doesn't branch on the live data source — + * mirrors the webapp's NormalizedUser (csmUsers.ts). + */ +export interface AdminUser { + id: string; + userName: string; + name: string; + email: string; + timezone: string | null; + /** Present only from the postgres source. */ + userType?: AdminUserType; + /** Present only from the ServiceNow source. */ + active?: boolean; + /** Present only from the ServiceNow source. */ + roles?: string[]; +} + +function isSnUser(u: UserDto | SnUserDto): u is SnUserDto { + return "name" in u || "active" in u || "roles" in u; +} + +export function toAdminUser(u: UserDto | SnUserDto): AdminUser { + if (isSnUser(u)) { + return { + id: u.id, + userName: u.userName, + name: u.name?.trim() || "", + email: u.email, + timezone: u.timeZone ?? null, + active: u.active, + roles: u.roles, + }; + } + return { + id: u.id, + userName: u.userName, + name: `${u.firstName ?? ""} ${u.lastName ?? ""}`.trim(), + email: u.email, + timezone: u.timezone ?? null, + userType: u.userType, + }; +} diff --git a/apps/csm-portal/microapp/src/types/index.ts b/apps/csm-portal/microapp/src/types/index.ts index 346492d30a..5d6e0005b4 100644 --- a/apps/csm-portal/microapp/src/types/index.ts +++ b/apps/csm-portal/microapp/src/types/index.ts @@ -23,5 +23,7 @@ export * from "./deployment.dto"; export * from "./deployment.model"; export * from "./user.dto"; export * from "./user.model"; +export * from "./adminUser.dto"; +export * from "./adminUser.model"; export * from "./timecard.dto"; export * from "./timecard.model"; From efd70115ddf89e6132df4ff5eaa6b1d36754bd28 Mon Sep 17 00:00:00 2001 From: 2003dinijay Date: Mon, 13 Jul 2026 11:13:23 +0530 Subject: [PATCH 2/4] [CSM Portal Microapp] Add ARIA state to Settings role/status filter chips Role chips get aria-pressed (multi-select toggle semantics); status chips are grouped under role="radiogroup" with role="radio" and aria-checked per option (mutually-exclusive selection). No behavior change. --- .../microapp/src/components/settings/UsersFiltersSheet.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/csm-portal/microapp/src/components/settings/UsersFiltersSheet.tsx b/apps/csm-portal/microapp/src/components/settings/UsersFiltersSheet.tsx index e9a391f724..e04da32338 100644 --- a/apps/csm-portal/microapp/src/components/settings/UsersFiltersSheet.tsx +++ b/apps/csm-portal/microapp/src/components/settings/UsersFiltersSheet.tsx @@ -86,6 +86,7 @@ export function UsersFiltersSheet({ open, onClose, filters, onApply }: UsersFilt size="small" variant={isSelected ? "filled" : "outlined"} color={isSelected ? "primary" : "default"} + aria-pressed={isSelected} onClick={() => setDraft({ ...draft, roles: toggleRole(draft.roles, role) })} /> ); @@ -95,7 +96,7 @@ export function UsersFiltersSheet({ open, onClose, filters, onApply }: UsersFilt Status - + {STATUS_OPTIONS.map((option) => { const isSelected = draft.active === option.value; return ( @@ -105,6 +106,8 @@ export function UsersFiltersSheet({ open, onClose, filters, onApply }: UsersFilt size="small" variant={isSelected ? "filled" : "outlined"} color={isSelected ? "primary" : "default"} + role="radio" + aria-checked={isSelected} onClick={() => setDraft({ ...draft, active: option.value })} /> ); From b1bfa30f3c9e700157994bd2fc703ed398962cb4 Mon Sep 17 00:00:00 2001 From: 2003dinijay Date: Mon, 13 Jul 2026 12:18:04 +0530 Subject: [PATCH 3/4] [CSM Portal Microapp] Add Home page, mirroring the webapp's Dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two live widgets: "Assigned to me" (the signed-in user's non-closed cases, capped to a 5-item preview) and case composition donuts (severity + state breakdown of active cases), both ported from the webapp's csm-dashboard feature. Donut styling/behavior mirrors the webapp's CompositionDonut directly. The severity×state matrix table and the ABT-scope header are left out: the matrix costs 25 more fan-out requests (no aggregation endpoint exists) on top of the donuts' 11, and doesn't fit a mobile screen well; the header is feature-flagged off in the webapp itself and only ever shows a static fallback. getAllCases is now exported from cases.ts so the composition query can fan out count-only searches directly, same as the webapp's useCaseComposition bypasses its own query-options wrapper for the same reason. --- .../components/home/AssignedToMeSection.tsx | 63 ++++++++ .../home/CaseCompositionSection.tsx | 90 +++++++++++ .../src/components/home/CompositionDonut.tsx | 153 ++++++++++++++++++ .../microapp/src/components/home/config.ts | 55 +++++++ .../microapp/src/pages/HomePage.tsx | 19 ++- .../csm-portal/microapp/src/services/cases.ts | 6 +- .../microapp/src/services/dashboard.ts | 91 +++++++++++ 7 files changed, 471 insertions(+), 6 deletions(-) create mode 100644 apps/csm-portal/microapp/src/components/home/AssignedToMeSection.tsx create mode 100644 apps/csm-portal/microapp/src/components/home/CaseCompositionSection.tsx create mode 100644 apps/csm-portal/microapp/src/components/home/CompositionDonut.tsx create mode 100644 apps/csm-portal/microapp/src/components/home/config.ts create mode 100644 apps/csm-portal/microapp/src/services/dashboard.ts diff --git a/apps/csm-portal/microapp/src/components/home/AssignedToMeSection.tsx b/apps/csm-portal/microapp/src/components/home/AssignedToMeSection.tsx new file mode 100644 index 0000000000..b9cad18e17 --- /dev/null +++ b/apps/csm-portal/microapp/src/components/home/AssignedToMeSection.tsx @@ -0,0 +1,63 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import { Button, Stack, Typography } from "@wso2/oxygen-ui"; +import { useQuery } from "@tanstack/react-query"; +import { Link } from "react-router-dom"; +import { currentUser } from "@src/services/currentUser"; +import { dashboard } from "@src/services/dashboard"; +import { CaseCard, CaseCardSkeleton } from "@components/support/CaseCard"; +import { EmptyState } from "@components/support/EmptyState"; +import { ErrorState } from "@components/support/ErrorState"; + +// The signed-in user's own non-closed cases — mirrors the webapp's "Assigned to me" widget +// (apps/csm-portal/webapp/src/features/csm-dashboard/components/MyAssignedCases.tsx), capped to a +// short 5-item preview with a "View all" link out to Support, rather than paginated in place. +export function AssignedToMeSection() { + const { data: currentUserId } = useQuery(currentUser.id()); + const { data, isLoading, isError, refetch } = useQuery(dashboard.assignedToMe(currentUserId ?? null)); + + const items = data?.items ?? []; + + return ( + + + Assigned to me + + + + {isLoading ? ( + + {Array.from({ length: 3 }).map((_, index) => ( + + ))} + + ) : isError ? ( + void refetch()} /> + ) : items.length === 0 ? ( + + ) : ( + + {items.map((item) => ( + + ))} + + )} + + ); +} diff --git a/apps/csm-portal/microapp/src/components/home/CaseCompositionSection.tsx b/apps/csm-portal/microapp/src/components/home/CaseCompositionSection.tsx new file mode 100644 index 0000000000..62349b10b2 --- /dev/null +++ b/apps/csm-portal/microapp/src/components/home/CaseCompositionSection.tsx @@ -0,0 +1,90 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import { useMemo } from "react"; +import { Stack, Typography } from "@wso2/oxygen-ui"; +import { useQuery } from "@tanstack/react-query"; +import { dashboard } from "@src/services/dashboard"; +import { ALL_SEVERITIES, SEVERITY_LABELS, STATE_LABELS } from "@components/support/config"; +import { COMPOSITION_STATES, SEVERITY_SLICE_COLOR, STATE_SLICE_COLOR } from "./config"; +import { CompositionDonut, type CompositionSlice } from "./CompositionDonut"; + +// Two donuts — severity composition and state composition of active cases — mirrors the webapp's +// CaseCompositionCharts (apps/csm-portal/webapp/src/features/csm-dashboard/components/CaseCompositionCharts.tsx), +// stacked instead of side-by-side (the webapp's own grid already collapses to one column below its +// "md" breakpoint, which is every phone width anyway). Self-contained plain useQuery rather than +// Suspense, matching how TimeCardsPage.tsx already handles independent, non-blocking widgets in +// this app — one failed/slow widget shouldn't hold up the rest of the Home page. +export function CaseCompositionSection() { + const { data, isLoading, isError } = useQuery(dashboard.composition()); + + const severitySlices = useMemo( + () => + ALL_SEVERITIES.map((severity) => ({ + id: severity, + name: SEVERITY_LABELS[severity], + value: data?.bySeverity[severity] ?? 0, + color: SEVERITY_SLICE_COLOR[severity], + })), + [data], + ); + + const stateSlices = useMemo( + () => + COMPOSITION_STATES.map((state) => ({ + id: state, + name: STATE_LABELS[state], + value: data?.byState[state] ?? 0, + color: STATE_SLICE_COLOR[state], + })), + [data], + ); + + const closedTotal = data?.closedTotal ?? 0; + + return ( + + Case composition + + + + + + + {/* Reconciles with the donuts: both show active cases only, so the closed count is called + out here rather than mixed into a slice — same as the webapp. */} + {!isLoading && !isError && closedTotal > 0 && ( + + Excludes {closedTotal} closed {closedTotal === 1 ? "case" : "cases"}. + + )} + + ); +} diff --git a/apps/csm-portal/microapp/src/components/home/CompositionDonut.tsx b/apps/csm-portal/microapp/src/components/home/CompositionDonut.tsx new file mode 100644 index 0000000000..9e6eb053a6 --- /dev/null +++ b/apps/csm-portal/microapp/src/components/home/CompositionDonut.tsx @@ -0,0 +1,153 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import { Box, Card, Skeleton, Typography } from "@wso2/oxygen-ui"; +import { PieChart } from "@wso2/oxygen-ui-charts-react"; + +// Donut sits in a fixed square; the legend fills the rest of the card width. Smaller than the +// webapp's 200px version (CompositionDonut.tsx) to fit a phone-width card comfortably. +const DONUT_SIZE = 160; + +export interface CompositionSlice { + id: string; + name: string; + value: number; + color: string; +} + +interface CompositionDonutProps { + title: string; + description: string; + slices: CompositionSlice[]; + total: number; + isLoading: boolean; + isError: boolean; + /** Noun for the empty state, e.g. "cases". */ + emptyNoun?: string; +} + +// A donut chart with a value/percentage legend and a centred total — mirrors the webapp's +// CompositionDonut (apps/csm-portal/webapp/src/features/csm-dashboard/components/CompositionDonut.tsx). +// Zero-value slices drop from the ring but stay in the legend so every category remains visible. +// No slice-click drill-down here (unlike the webapp): the microapp's Support page doesn't support +// seeding filters from the URL, so there's nowhere to deep-link a click into yet. +export function CompositionDonut({ + title, + description, + slices, + total, + isLoading, + isError, + emptyNoun = "cases", +}: CompositionDonutProps) { + const pieData = slices.filter((s) => s.value > 0); + const isEmpty = !isLoading && !isError && total === 0; + + return ( + + + {title} + + + {description} + + + {isLoading ? ( + + + + {slices.map((s) => ( + + ))} + + + ) : isError ? ( + + + Could not load {title.toLowerCase()}. + + + ) : isEmpty ? ( + + + No {emptyNoun} to show. + + + ) : ( + + + s.color)} + legend={{ show: false }} + tooltip={{ show: true }} + width="100%" + height={DONUT_SIZE} + pies={[ + { + dataKey: "value", + nameKey: "name", + innerRadius: "62%", + outerRadius: "100%", + paddingAngle: 1, + startAngle: 90, + endAngle: -270, + label: false, + labelLine: false, + }, + ]} + /> + + {total} + + Total + + + + + {/* Legend: every category, with its count and share. */} + + {slices.map((s) => { + const pct = total > 0 ? Math.round((s.value / total) * 100) : 0; + return ( + + + + + {s.name} + + + + {s.value} ({pct}%) + + + ); + })} + + + )} + + ); +} diff --git a/apps/csm-portal/microapp/src/components/home/config.ts b/apps/csm-portal/microapp/src/components/home/config.ts new file mode 100644 index 0000000000..1b35e58127 --- /dev/null +++ b/apps/csm-portal/microapp/src/components/home/config.ts @@ -0,0 +1,55 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import { colors } from "@wso2/oxygen-ui"; +import type { CaseSeverity, CaseState } from "@src/types"; + +// The active states the composition donuts track — mirrors the webapp's MATRIX_STATES +// (apps/csm-portal/webapp/src/features/csm-dashboard/api/useCaseCountsMatrix.ts): closed is +// excluded (the dashboard tracks active work) and so is reopened (not a normal lifecycle state). +export const COMPOSITION_STATES: CaseState[] = [ + "open", + "work_in_progress", + "waiting_on_wso2", + "awaiting_info", + "solution_proposed", +]; + +// Non-closed states for "Assigned to me" — the same set the webapp's MyAssignedCases widget uses +// (apps/csm-portal/webapp/src/features/csm-dashboard/components/MyAssignedCases.tsx), which +// includes reopened unlike the composition set above. +export const ASSIGNED_TO_ME_STATES: CaseState[] = [...COMPOSITION_STATES, "reopened"]; + +// Distinct hue per slice — mirrors the webapp's SEVERITY_SLICE_COLOR/STATE_SLICE_COLOR +// (CaseCompositionCharts.tsx). The support/config.tsx chip color configs reuse the same role +// color for several keys (e.g. every "info" state), which would merge pie slices together. +export const SEVERITY_SLICE_COLOR: Record = { + catastrophic: colors.red[600], + critical: colors.deepOrange[500], + high: colors.amber[700], + medium: colors.blue[500], + low: colors.green[500], +}; + +export const STATE_SLICE_COLOR: Record = { + open: colors.blue[500], + work_in_progress: colors.indigo[400], + waiting_on_wso2: colors.amber[700], + awaiting_info: colors.cyan[500], + solution_proposed: colors.teal[500], + closed: colors.grey[500], + reopened: colors.purple[500], +}; diff --git a/apps/csm-portal/microapp/src/pages/HomePage.tsx b/apps/csm-portal/microapp/src/pages/HomePage.tsx index 4e4c8bbe93..bcf442eab7 100644 --- a/apps/csm-portal/microapp/src/pages/HomePage.tsx +++ b/apps/csm-portal/microapp/src/pages/HomePage.tsx @@ -14,13 +14,22 @@ // specific language governing permissions and limitations // under the License. -import { ComingSoonPage } from "@components/common/ComingSoonPage"; +import { Stack, Typography } from "@wso2/oxygen-ui"; +import { AssignedToMeSection } from "@components/home/AssignedToMeSection"; +import { CaseCompositionSection } from "@components/home/CaseCompositionSection"; +// Mirrors the webapp's Dashboard (apps/csm-portal/webapp/src/features/csm-dashboard/pages/CsmDashboardPage.tsx): +// "Assigned to me" and the case composition donuts, its two widgets with real data. The +// severity×state matrix table is deliberately left out — it costs 25 extra fan-out requests on +// top of the donuts' 11, with no aggregation endpoint to make it cheap, and doesn't fit a mobile +// screen well anyway. The ABT-scope header is skipped too since it's feature-flagged off +// (CSM_DASHBOARD_API_IMPLEMENTED = false) and only ever shows a static fallback in the webapp. export default function HomePage() { return ( - + + Home + + + ); } diff --git a/apps/csm-portal/microapp/src/services/cases.ts b/apps/csm-portal/microapp/src/services/cases.ts index 09c88a1c8a..37bed95318 100644 --- a/apps/csm-portal/microapp/src/services/cases.ts +++ b/apps/csm-portal/microapp/src/services/cases.ts @@ -41,7 +41,11 @@ export interface CaseSearchResult { hasMore: boolean; } -const getAllCases = async (payload: CaseSearchPayloadDto = {}): Promise => { +// Exported (not just used internally) so the Home dashboard's composition query can fan out +// count-only searches (`pagination: { limit: 1 }`, read `.total`) without going through the +// `cases.all` query-options wrapper — mirrors the webapp's useCaseComposition.ts, which calls its +// api client directly for the same reason. +export const getAllCases = async (payload: CaseSearchPayloadDto = {}): Promise => { const { data } = await apiClient.post(CASES_SEARCH_ENDPOINT, payload); return { items: data.cases.map(toCaseSummary), diff --git a/apps/csm-portal/microapp/src/services/dashboard.ts b/apps/csm-portal/microapp/src/services/dashboard.ts new file mode 100644 index 0000000000..deab553d40 --- /dev/null +++ b/apps/csm-portal/microapp/src/services/dashboard.ts @@ -0,0 +1,91 @@ +// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import { queryOptions } from "@tanstack/react-query"; +import type { CaseSearchFiltersDto, CaseSeverity, CaseState } from "@src/types"; +import { ALL_SEVERITIES } from "@components/support/config"; +import { ASSIGNED_TO_ME_STATES, COMPOSITION_STATES } from "@components/home/config"; +import { getAllCases, type CaseSearchResult } from "./cases"; + +// Mirrors the webapp's CaseComposition (useCaseComposition.ts): a 1-D breakdown by severity and a +// 1-D breakdown by state, each over active cases only (closed excluded). The closed count is +// returned separately so a large closed backlog can't skew the active totals. +export interface CaseComposition { + bySeverity: Record; + byState: Record; + severityTotal: number; + stateTotal: number; + closedTotal: number; +} + +const EMPTY_RESULT: CaseSearchResult = { items: [], total: 0, limit: 0, offset: 0, hasMore: false }; + +// The backend has no count/aggregation endpoint, so — like the webapp — this fans out +// count-only searches (`limit: 1`, read `.total`): one per severity (scoped to active states) and +// one per active state (scoped to every severity), plus one for the closed total. 11 requests, +// fired in parallel. +async function fetchComposition(): Promise { + const countOf = (filters: CaseSearchFiltersDto): Promise => + getAllCases({ filters: { types: ["case"], ...filters }, pagination: { limit: 1 } }).then((r) => r.total); + + const [severityCounts, stateCounts, closedTotal] = await Promise.all([ + Promise.all( + ALL_SEVERITIES.map((severity) => + countOf({ severities: [severity], states: COMPOSITION_STATES }).then((n) => [severity, n] as const), + ), + ), + Promise.all( + COMPOSITION_STATES.map((state) => + countOf({ states: [state], severities: ALL_SEVERITIES }).then((n) => [state, n] as const), + ), + ), + countOf({ states: ["closed"], severities: ALL_SEVERITIES }), + ]); + + const bySeverity = Object.fromEntries(severityCounts) as Record; + const byState = Object.fromEntries(stateCounts) as Record; + const severityTotal = severityCounts.reduce((sum, [, n]) => sum + n, 0); + const stateTotal = stateCounts.reduce((sum, [, n]) => sum + n, 0); + + return { bySeverity, byState, severityTotal, stateTotal, closedTotal }; +} + +export const dashboard = { + // Same active-vs-closed split the webapp's dashboard donuts show; staleTime keeps a page + // revisit from re-firing all 11 requests immediately. + composition: () => + queryOptions({ + queryKey: ["dashboard", "composition"], + queryFn: fetchComposition, + staleTime: 60_000, + }), + + // The signed-in user's own non-closed cases, newest-updated first — mirrors the webapp's + // MyAssignedCases widget, capped to a short preview (5) rather than paginated. + assignedToMe: (userId: string | null) => + queryOptions({ + queryKey: ["dashboard", "assigned-to-me", userId], + queryFn: () => + userId + ? getAllCases({ + filters: { types: ["case"], assignedUserIds: [userId], states: ASSIGNED_TO_ME_STATES }, + sortBy: { field: "updatedOn", order: "desc" }, + pagination: { limit: 5 }, + }) + : Promise.resolve(EMPTY_RESULT), + enabled: !!userId, + }), +}; From 79cadd0c9b82d7bf8e352fb1b534b92a5ce03b4f Mon Sep 17 00:00:00 2001 From: Dinithi Nanayakkara <166215353+2003dinijay@users.noreply.github.com> Date: Mon, 13 Jul 2026 12:31:36 +0530 Subject: [PATCH 4/4] Update apps/csm-portal/microapp/src/components/home/AssignedToMeSection.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../microapp/src/components/home/AssignedToMeSection.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/csm-portal/microapp/src/components/home/AssignedToMeSection.tsx b/apps/csm-portal/microapp/src/components/home/AssignedToMeSection.tsx index b9cad18e17..99bb2a6e17 100644 --- a/apps/csm-portal/microapp/src/components/home/AssignedToMeSection.tsx +++ b/apps/csm-portal/microapp/src/components/home/AssignedToMeSection.tsx @@ -28,7 +28,7 @@ import { ErrorState } from "@components/support/ErrorState"; // short 5-item preview with a "View all" link out to Support, rather than paginated in place. export function AssignedToMeSection() { const { data: currentUserId } = useQuery(currentUser.id()); - const { data, isLoading, isError, refetch } = useQuery(dashboard.assignedToMe(currentUserId ?? null)); + const { data, isPending, isError, refetch } = useQuery(dashboard.assignedToMe(currentUserId ?? null)); const items = data?.items ?? [];