Refactor Support Views to Improve Loading State Handling
- Updated SupportCaseDetailView, SupportCasesView, and SupportHomeView to remove direct loading state checks and replace them with a unified `showLoading` variable, enhancing code clarity. - Adjusted loading prop in PageLayout components to reflect the new loading state logic, ensuring a smoother user experience during data fetching.
This commit is contained in:
parent
655d26da4f
commit
c37bdd2b9c
@ -90,7 +90,10 @@ interface SupportCaseDetailViewProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function SupportCaseDetailView({ caseId }: SupportCaseDetailViewProps) {
|
export function SupportCaseDetailView({ caseId }: SupportCaseDetailViewProps) {
|
||||||
const { data: supportCase, isLoading, error, refetch } = useSupportCase(caseId);
|
const { data: supportCase, error, refetch } = useSupportCase(caseId);
|
||||||
|
|
||||||
|
// Show loading until we have data or an error
|
||||||
|
const showLoading = !supportCase && !error;
|
||||||
const {
|
const {
|
||||||
data: messagesData,
|
data: messagesData,
|
||||||
isLoading: messagesLoading,
|
isLoading: messagesLoading,
|
||||||
@ -121,7 +124,8 @@ export function SupportCaseDetailView({ caseId }: SupportCaseDetailViewProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isLoading && !supportCase && !error) {
|
// Case not found - only show after loading is complete
|
||||||
|
if (!showLoading && !supportCase) {
|
||||||
return (
|
return (
|
||||||
<PageLayout
|
<PageLayout
|
||||||
icon={<TicketIconSolid />}
|
icon={<TicketIconSolid />}
|
||||||
@ -145,7 +149,7 @@ export function SupportCaseDetailView({ caseId }: SupportCaseDetailViewProps) {
|
|||||||
icon={<TicketIconSolid />}
|
icon={<TicketIconSolid />}
|
||||||
title={supportCase ? `Case #${supportCase.caseNumber}` : "Loading..."}
|
title={supportCase ? `Case #${supportCase.caseNumber}` : "Loading..."}
|
||||||
description={supportCase?.subject}
|
description={supportCase?.subject}
|
||||||
loading={isLoading}
|
loading={showLoading}
|
||||||
error={pageError}
|
error={pageError}
|
||||||
onRetry={() => void refetch()}
|
onRetry={() => void refetch()}
|
||||||
breadcrumbs={[
|
breadcrumbs={[
|
||||||
|
|||||||
@ -51,10 +51,13 @@ export function SupportCasesView() {
|
|||||||
return nextFilters;
|
return nextFilters;
|
||||||
}, [statusFilter, priorityFilter, deferredSearchTerm]);
|
}, [statusFilter, priorityFilter, deferredSearchTerm]);
|
||||||
|
|
||||||
const { data, isLoading, error, refetch } = useSupportCases(queryFilters);
|
const { data, error, refetch } = useSupportCases(queryFilters);
|
||||||
const cases = data?.cases ?? [];
|
const cases = data?.cases ?? [];
|
||||||
const summary = data?.summary ?? { total: 0, open: 0, highPriority: 0, resolved: 0 };
|
const summary = data?.summary ?? { total: 0, open: 0, highPriority: 0, resolved: 0 };
|
||||||
|
|
||||||
|
// Show loading until we have data or an error
|
||||||
|
const showLoading = !data && !error;
|
||||||
|
|
||||||
const hasActiveFilters = statusFilter !== "all" || priorityFilter !== "all" || searchTerm.trim();
|
const hasActiveFilters = statusFilter !== "all" || priorityFilter !== "all" || searchTerm.trim();
|
||||||
|
|
||||||
const statusFilterOptions = useMemo(
|
const statusFilterOptions = useMemo(
|
||||||
@ -87,7 +90,7 @@ export function SupportCasesView() {
|
|||||||
icon={<ChatBubbleLeftRightIconSolid />}
|
icon={<ChatBubbleLeftRightIconSolid />}
|
||||||
title="Support Cases"
|
title="Support Cases"
|
||||||
description="Track and manage your support requests"
|
description="Track and manage your support requests"
|
||||||
loading={isLoading}
|
loading={showLoading}
|
||||||
error={error}
|
error={error}
|
||||||
onRetry={() => void refetch()}
|
onRetry={() => void refetch()}
|
||||||
breadcrumbs={[{ label: "Support", href: "/account/support" }, { label: "Cases" }]}
|
breadcrumbs={[{ label: "Support", href: "/account/support" }, { label: "Cases" }]}
|
||||||
|
|||||||
@ -21,16 +21,19 @@ import { formatIsoRelative } from "@/shared/utils";
|
|||||||
|
|
||||||
export function SupportHomeView() {
|
export function SupportHomeView() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { data, isLoading, error, refetch } = useSupportCases();
|
const { data, error, refetch } = useSupportCases();
|
||||||
const recentCases = data?.cases?.slice(0, 5) ?? [];
|
const recentCases = data?.cases?.slice(0, 5) ?? [];
|
||||||
const summary = data?.summary ?? { total: 0, open: 0, highPriority: 0, resolved: 0 };
|
const summary = data?.summary ?? { total: 0, open: 0, highPriority: 0, resolved: 0 };
|
||||||
|
|
||||||
|
// Show loading until we have data or an error
|
||||||
|
const showLoading = !data && !error;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageLayout
|
<PageLayout
|
||||||
icon={<ChatBubbleLeftRightIconSolid />}
|
icon={<ChatBubbleLeftRightIconSolid />}
|
||||||
title="Support Center"
|
title="Support Center"
|
||||||
description="Get help with your account and services"
|
description="Get help with your account and services"
|
||||||
loading={isLoading}
|
loading={showLoading}
|
||||||
error={error}
|
error={error}
|
||||||
onRetry={() => void refetch()}
|
onRetry={() => void refetch()}
|
||||||
>
|
>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user