saleor-apps-redis_apl/apps/cms-v2/src/modules/channel-provider-connection/add-connection-modal.tsx

67 lines
1.9 KiB
TypeScript
Raw Normal View History

CMS App v2 (#721) * initial setup * GRaphql setup * [skip ci] * Manifest and register endpoints * Add config schemas * contentful client * contentful client * [skip ci] trpc setup * metadata manager and contentful router * Configuration config * contentful config - adding providers * add provider page * wip contentful form * contentful form * list providrs * edit contentful form * [skip ci] * [skip ci] replace contentful sdk * replace contentful lib * Delete contetnful provider feature * variant created webhook draft * channel provider connection model * Channel connections ui * adding new connection * connections ui (adding) * [skip ci] wip edit conn * removing connection * rebuild modal * refactor providers * implement update product webhook * add deleting product * [skip ci] wip * refactor contentful router * refactor wip * refactor config * webhooks processor * webhook delegations * bulk sync section * bulk sync page * gql for imports * [skip ci] bulk import contentful * temp variant sync list with rate limiters * wip * wip * wip * new frontend for uploading * update zod * print config keys * wip * [skip ci] datocms init * dato add provdier page * dato form skeleton * dato display content type select * full dato form * ButtonsBox extraction * edit dato config form * update product in dato * [skip ci] * extract bulk sync processor * dato bulk update * [skip ci] product updated webhook * product webhook * crud operations router * update cruds * refactor webhook operations * refactors * refactors * helper texts * [skip ci] deps * Init * fix macaw icon * unify app skd * unify nextjs * strapi setup * fix strapi types * strapi upload product * strapi delete product * strapi product updated webhook * processor for bulk sync strapi * shared add provider page * refactors * refactors * wrap providers into folder * refactors * refactors * refactors * pnpm lock * add logs * name configuration mapping name * form configurable side notes * remove commentns * wip providers resolver working * central config for providers resolving * tests wip * remove vscode condig * cleanup * provider meta extract * some tests for contentufl * contentful client test * more tests for contentful * strapi helper texts * builderio setup * builderio form * builderio client draft * validate connection modal * Add sending product to builderio * rename builder field * add public api key for read access * update products * Builder.io - bulk sync * Fix manifest * cr fixes * Make strapi to work with multiple products * Github actions
2023-07-18 08:19:21 +00:00
import { Button, Text } from "@saleor/macaw-ui/next";
import { Modal } from "../ui/modal";
import {
AddConnectionForm,
AddConnectionFormID,
AddConnectionFormSchema,
} from "./add-connection-form";
import { trpcClient } from "../trpc/trpc-client";
import { ButtonsBox, SkeletonLayout } from "@saleor/apps-ui";
CMS App v2 (#721) * initial setup * GRaphql setup * [skip ci] * Manifest and register endpoints * Add config schemas * contentful client * contentful client * [skip ci] trpc setup * metadata manager and contentful router * Configuration config * contentful config - adding providers * add provider page * wip contentful form * contentful form * list providrs * edit contentful form * [skip ci] * [skip ci] replace contentful sdk * replace contentful lib * Delete contetnful provider feature * variant created webhook draft * channel provider connection model * Channel connections ui * adding new connection * connections ui (adding) * [skip ci] wip edit conn * removing connection * rebuild modal * refactor providers * implement update product webhook * add deleting product * [skip ci] wip * refactor contentful router * refactor wip * refactor config * webhooks processor * webhook delegations * bulk sync section * bulk sync page * gql for imports * [skip ci] bulk import contentful * temp variant sync list with rate limiters * wip * wip * wip * new frontend for uploading * update zod * print config keys * wip * [skip ci] datocms init * dato add provdier page * dato form skeleton * dato display content type select * full dato form * ButtonsBox extraction * edit dato config form * update product in dato * [skip ci] * extract bulk sync processor * dato bulk update * [skip ci] product updated webhook * product webhook * crud operations router * update cruds * refactor webhook operations * refactors * refactors * helper texts * [skip ci] deps * Init * fix macaw icon * unify app skd * unify nextjs * strapi setup * fix strapi types * strapi upload product * strapi delete product * strapi product updated webhook * processor for bulk sync strapi * shared add provider page * refactors * refactors * wrap providers into folder * refactors * refactors * refactors * pnpm lock * add logs * name configuration mapping name * form configurable side notes * remove commentns * wip providers resolver working * central config for providers resolving * tests wip * remove vscode condig * cleanup * provider meta extract * some tests for contentufl * contentful client test * more tests for contentful * strapi helper texts * builderio setup * builderio form * builderio client draft * validate connection modal * Add sending product to builderio * rename builder field * add public api key for read access * update products * Builder.io - bulk sync * Fix manifest * cr fixes * Make strapi to work with multiple products * Github actions
2023-07-18 08:19:21 +00:00
const defaultValues: AddConnectionFormSchema = { channelSlug: "", providerId: "" };
export const AddConnectionModal = (props: { onSuccess(): void; onClose(): void }) => {
const { data: providers } = trpcClient.providersConfigs.getAll.useQuery();
if (!providers) {
return <SkeletonLayout.Section />;
}
const { mutateAsync: addProviderMutate, isLoading } =
trpcClient.channelsProvidersConnection.addConnection.useMutation({
onSuccess() {
props.onSuccess();
},
});
const handleFormSubmit = async (values: AddConnectionFormSchema) => {
const providerType = providers.find((p) => p.id === values.providerId)?.type;
if (!providerType) {
throw new Error("Provider not found");
}
return addProviderMutate({
...values,
providerType,
});
};
return (
<Modal onClose={props.onClose}>
<Text as="h2" variant="heading">
Connect channel with Provider
</Text>
<Text as="p" marginBottom={6}>
Once connected, operations on product variants on this channel will be sent to selected CMS
platform.
</Text>
<AddConnectionForm onSubmit={handleFormSubmit} defaultValues={defaultValues} />
<ButtonsBox marginTop={8}>
<Button
disabled={isLoading}
variant="tertiary"
onClick={() => {
props.onClose();
}}
>
Close
</Button>
<Button variant="primary" type="submit" form={AddConnectionFormID}>
Add connection
</Button>
</ButtonsBox>
</Modal>
);
};