saleor-apps-redis_apl/apps/cms-v2/src/pages/bulk-sync/[connection-id].tsx
Lukasz Ostrowski 5d41af93e1
CMS v2 quality improvements (#782)
* Add required validation for forms

* Add logs

* [skip-ci] handle form errors

* Improve notifications after form created

* add notification when bulk sync finishes

* Add skeletons

* Validation for channel connection form

* cr fixes
2023-07-19 10:22:00 +02:00

58 lines
1.4 KiB
TypeScript

import { BulkSyncView } from "@/modules/bulk-sync/bulk-sync-view";
import { trpcClient } from "@/modules/trpc/trpc-client";
import { NextPage } from "next";
import { useRouter } from "next/router";
import { z } from "zod";
import { Text } from "@saleor/macaw-ui/next";
import { Skeleton } from "@/modules/ui/skeleton";
const BulkSyncPage: NextPage = () => {
const { query } = useRouter();
const id = query["connection-id"] as string | undefined;
const { push } = useRouter();
const parsedID = z.string().optional().parse(id);
const {
data: connection,
isLoading: connectionLoading,
isSuccess: connectionFetched,
} = trpcClient.channelsProvidersConnection.fetchConnection.useQuery(
{
id: parsedID ?? "",
},
{
enabled: !!parsedID,
}
);
const {
data: provider,
isLoading: providerLoading,
isSuccess: providerFetched,
} = trpcClient.providersConfigs.getOne.useQuery(
{
id: connection?.providerId ?? "",
},
{
enabled: !!connection,
}
);
if ((providerFetched && !provider) || (connectionFetched && !connection)) {
push("/404");
return null;
}
if (connectionLoading || providerLoading) {
return <Skeleton.Section />;
}
if (!(provider && connection)) {
return null;
}
return <BulkSyncView configuration={provider} connection={connection} />;
};
export default BulkSyncPage;