feat(templates): add loading state and error handling for template fetching

- Implement loading spinner during template retrieval
- Add error alert for template fetching failures
- Enhance user experience with informative loading and error messages
- Import Loader2 icon for loading state visualization
This commit is contained in:
Mauricio Siu 2025-03-09 18:53:13 -06:00
parent 58f4d3561e
commit 19827fce84

View File

@ -62,6 +62,7 @@ import {
HelpCircle, HelpCircle,
LayoutGrid, LayoutGrid,
List, List,
Loader2,
PuzzleIcon, PuzzleIcon,
SearchIcon, SearchIcon,
} from "lucide-react"; } from "lucide-react";
@ -99,7 +100,12 @@ export const AddTemplate = ({ projectId, baseUrl }: Props) => {
} }
}, [customBaseUrl]); }, [customBaseUrl]);
const { data } = api.compose.templates.useQuery( const {
data,
isLoading: isLoadingTemplates,
error: errorTemplates,
isError: isErrorTemplates,
} = api.compose.templates.useQuery(
{ baseUrl: customBaseUrl }, { baseUrl: customBaseUrl },
{ {
enabled: open, enabled: open,
@ -270,7 +276,20 @@ export const AddTemplate = ({ projectId, baseUrl }: Props) => {
</AlertBlock> </AlertBlock>
)} )}
{templates.length === 0 ? ( {isErrorTemplates && (
<AlertBlock type="error" className="mb-4">
{errorTemplates?.message}
</AlertBlock>
)}
{isLoadingTemplates ? (
<div className="flex justify-center items-center w-full h-full flex-row gap-4">
<Loader2 className="size-8 text-muted-foreground animate-spin min-h-[60vh]" />
<div className="text-lg font-medium text-muted-foreground">
Loading templates...
</div>
</div>
) : templates.length === 0 ? (
<div className="flex justify-center items-center w-full gap-2 min-h-[50vh]"> <div className="flex justify-center items-center w-full gap-2 min-h-[50vh]">
<SearchIcon className="text-muted-foreground size-6" /> <SearchIcon className="text-muted-foreground size-6" />
<div className="text-xl font-medium text-muted-foreground"> <div className="text-xl font-medium text-muted-foreground">