import { Button, Select, SectionMessage, Modal, useToast, ToastType, TextInput, ButtonLink, ClipboardButton, Tabs, } from "@pantheon-systems/pds-toolkit-react"; import { useMemo, useState } from "react"; import { useForm, Controller } from "react-hook-form"; import { useMutation } from "@tanstack/react-query"; import { apiClient } from "../api/client"; import { getErrorMessage } from "../lib/errors"; import { SRC_ACTIONS } from "../lib/constants"; import { useCollectionData } from "../hooks/useCollectionData"; import { usePostTypeOptions } from "../hooks/usePostTypeOptions"; import CollectionInfo from "../components/CollectionInfo"; import AcfMappings from "./AcfMappings"; export default function Dashboard() { const { publish_as, webhook } = window.CPUB_BOOTSTRAP.configured; const { collectionName, collectionUrl, collectionId } = useCollectionData(); const postTypeOptions = usePostTypeOptions(); const [showConfirmModal, setShowConfirmModal] = useState(false); const [showDisconnectModal, setShowDisconnectModal] = useState(false); const [disconnectConfirmText, setDisconnectConfirmText] = useState(""); const [addToast] = useToast(); const [showDismissConfirmModal, setShowDismissConfirmModal] = useState(false); const [hideWebhookNotice, setHideWebhookNotice] = useState(false); const shouldShowWebhookNotice = useMemo(() => { // Show when not dismissed server-side AND we have a valid webhook url return ( Boolean(webhook?.url) && webhook?.notice_dismissed === false && !hideWebhookNotice ); }, [webhook, hideWebhookNotice]); const dismissNoticeMutation = useMutation({ mutationFn: async () => apiClient.put("/webhook-notice", { dismissed: true }), onSuccess: () => { // Optimistically hide without extra fetch if (window.CPUB_BOOTSTRAP.configured.webhook) { window.CPUB_BOOTSTRAP.configured.webhook.notice_dismissed = true; } setShowDismissConfirmModal(false); }, onMutate: () => { setHideWebhookNotice(true); }, onError: () => { setHideWebhookNotice(false); addToast( ToastType.Critical, "Failed to hide the notice. Please try again." ); }, }); const { control, handleSubmit, formState: { isDirty }, reset, getValues, } = useForm<{ publishAs: string; }>({ mode: "onChange", defaultValues: { publishAs: publish_as ?? "post", }, }); const updateMutation = useMutation({ mutationFn: async (publishAs: string) => { return apiClient.put("/collection", { post_type: publishAs, }); }, onSuccess: () => { setShowConfirmModal(false); addToast(ToastType.Success, "Changes saved successfully"); reset({ publishAs: getValues("publishAs"), }); }, onError: () => { setShowConfirmModal(false); }, }); const disconnectMutation = useMutation({ mutationFn: async () => { return apiClient.delete("/disconnect"); }, onSuccess: () => { setShowDisconnectModal(false); const baseUrl = window.CPUB_BOOTSTRAP.plugin_main_page; const separator = baseUrl.includes("?") ? "&" : "?"; window.location.href = `${baseUrl}${separator}src=${SRC_ACTIONS.DISCONNECTED}`; }, onError: () => { addToast( ToastType.Critical, "Failed to disconnect collection. Please try again or contact support if the issue persists." ); }, }); const onSubmit = (values: { publishAs: string }) => { updateMutation.mutate(values.publishAs); }; const handleDisconnect = () => { setShowDisconnectModal(true); }; const handleConfirmDisconnect = () => { disconnectMutation.mutate(); }; const isConfirmEnabled = disconnectConfirmText.trim().toUpperCase() === "DISCONNECT"; return (
Complete your setup by configuring webhooks for this collection
Keep your site content automatically updated when this
collection changes.
Note: Webhook secrets are not supported at this time. Please
do not set one in the ‘Secret’ field.
Copy the webhook URL below and add it to your Content Publisher dashboard.
This notice will not be shown again until this collection is disconnected.
Disconnecting {collectionName} will:
Disconnect all Google Docs in the collection from your site and prevent you from updating site content through Google Docs.
The content will remain on the site, manageable using the WordPress admin interface.