update query wait to use error message if one is available
This commit is contained in:
parent
8895fc31b4
commit
562ff8d2a6
@ -1,31 +1,38 @@
|
|||||||
import { type UseTRPCQueryResult } from "@trpc/react-query/shared";
|
import { type UseTRPCQueryResult } from "@trpc/react-query/shared";
|
||||||
import { LoadingBarChart } from "./LoadingBarChart";
|
import { LoadingBarChart } from "./LoadingBarChart";
|
||||||
import { ErrorNotice } from "./notice";
|
import { ErrorNotice } from "./notice";
|
||||||
|
import { type TRPCClientErrorLike } from "@trpc/client";
|
||||||
|
import { type TRPCErrorShape } from "@trpc/server/rpc";
|
||||||
|
import { type AnyProcedure, type AnyRouter } from "@trpc/server";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic query wrapper which handles the states of a query
|
* Generic query wrapper which handles the states of a query
|
||||||
* (loading, error, etc.). Will hydrate child with query.data
|
* (loading, error, etc.). Will hydrate child with query.data
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export function QueryWaitWrapper<TData, TError>({
|
export function QueryWaitWrapper<
|
||||||
|
TData,
|
||||||
|
TRouterOrProcedure extends AnyProcedure | AnyRouter | TRPCErrorShape<number>
|
||||||
|
>({
|
||||||
query,
|
query,
|
||||||
Render,
|
Render,
|
||||||
}: {
|
}: {
|
||||||
query: UseTRPCQueryResult<TData, TError>;
|
query: UseTRPCQueryResult<TData, TRPCClientErrorLike<TRouterOrProcedure>>;
|
||||||
Render: (data: TData) => JSX.Element;
|
Render: (data: TData) => JSX.Element;
|
||||||
}) {
|
}) {
|
||||||
if (query.isLoading) {
|
if (query.isLoading) {
|
||||||
return <LoadingBarChart width={200} height={200} />;
|
return <LoadingBarChart width={200} height={200} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(query.data);
|
|
||||||
|
|
||||||
if (!query.data || query.isError) {
|
if (!query.data || query.isError) {
|
||||||
return (
|
return (
|
||||||
<div className="my-10 sm:my-16 md:my-28">
|
<div className="my-10 sm:my-16 md:my-28">
|
||||||
<ErrorNotice
|
<ErrorNotice
|
||||||
icon
|
icon
|
||||||
header="Unable to retrieve page data. Please try again."
|
header={
|
||||||
|
query.error?.message ??
|
||||||
|
"Unable to retrieve page data. Please try again."
|
||||||
|
}
|
||||||
body="If this issue persists, please contact a site administrator"
|
body="If this issue persists, please contact a site administrator"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,9 +22,8 @@ const EditResourcePage = () => {
|
|||||||
{ id },
|
{ id },
|
||||||
{
|
{
|
||||||
enabled: router.isReady,
|
enabled: router.isReady,
|
||||||
onError(err) {
|
retry(_failureCount, error) {
|
||||||
console.log(err);
|
return error.data?.httpStatus !== 404;
|
||||||
throw err;
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -82,7 +82,14 @@ const ResourceViewPage = () => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const id = router.query["id"]?.toString() ?? "";
|
const id = router.query["id"]?.toString() ?? "";
|
||||||
|
|
||||||
const resourceQuery = api.auditoryResource.byId.useQuery({ id });
|
const resourceQuery = api.auditoryResource.byId.useQuery(
|
||||||
|
{ id },
|
||||||
|
{
|
||||||
|
retry(_failureCount, error) {
|
||||||
|
return error.data?.httpStatus !== 404;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const ConditionalView = (data: AuditoryResource) => {
|
const ConditionalView = (data: AuditoryResource) => {
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user