import { Breadcrumb, Button, ButtonLink, FlowSteps, LinkNewWindow, Spinner, TextInput, SectionMessage, } from "@pantheon-systems/pds-toolkit-react"; import { Link, useNavigate } from "react-router-dom"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { useMutation } from "@tanstack/react-query"; import CollectionReady from "../../components/collections/CollectionReady"; import { apiClient } from "../../api/client"; import { getErrorMessage } from "../../lib/errors"; export default function ConnectCollection() { const navigate = useNavigate(); const [view, setView] = useState<"form" | "loading" | "ready">("form"); const { control, handleSubmit, formState: { isValid }, } = useForm<{ collectionId: string; accessToken: string; }>({ mode: "onChange", defaultValues: { collectionId: "", accessToken: "" }, }); const connectMutation = useMutation({ mutationFn: async ({ collectionId, accessToken, }: { collectionId: string; accessToken: string; }) => { return apiClient.post("/collection/connect", { collection_id: collectionId, access_token: accessToken, }); }, onMutate: () => { setView("loading"); }, onSuccess: () => { setView("ready"); }, onError: () => { setView("form"); }, }); const onSubmit = (data: { collectionId: string; accessToken: string }) => { connectMutation.mutate(data); }; const steps = [ { header: "Enter your Collection ID", content: (
Copy and paste the Collection ID for the collection you'd like to connect.
Generate an access token in the Content Publisher dashboard.
This setup is for those who have already created a collection.{" "}