2023-02-07 19:25:36 +00:00
|
|
|
import { NextPage } from "next";
|
|
|
|
import React, { useEffect } from "react";
|
|
|
|
import { ChannelsConfiguration } from "../modules/app-configuration/ui/channels-configuration";
|
|
|
|
import { trpcClient } from "../modules/trpc/trpc-client";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { actions, useAppBridge } from "@saleor/app-sdk/app-bridge";
|
|
|
|
|
|
|
|
const ConfigurationPage: NextPage = () => {
|
|
|
|
const channels = trpcClient.channels.fetch.useQuery();
|
|
|
|
const router = useRouter();
|
|
|
|
|
2023-03-09 12:06:45 +00:00
|
|
|
const { appBridge, appBridgeState } = useAppBridge();
|
2023-02-07 19:25:36 +00:00
|
|
|
|
2023-03-09 12:06:45 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (channels.isFetched && appBridge && !appBridgeState?.ready) {
|
|
|
|
if (appBridge && channels.isFetched) {
|
|
|
|
appBridge.dispatch(actions.NotifyReady());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [channels.isFetched, appBridge, appBridgeState?.ready]);
|
2023-02-07 19:25:36 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (channels.isSuccess && channels.data.length === 0) {
|
|
|
|
router.push("/not-ready");
|
|
|
|
}
|
|
|
|
}, [channels.data, channels.isSuccess]);
|
|
|
|
|
2023-02-28 19:18:34 +00:00
|
|
|
return <ChannelsConfiguration />;
|
2023-02-07 19:25:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ConfigurationPage;
|