import { RenderConfigScreenCtx } from 'datocms-plugin-sdk'; import { Canvas, TextField, Form, FieldGroup, Button } from 'datocms-react-ui'; import { Controller, useForm } from 'react-hook-form'; type Props = { ctx: RenderConfigScreenCtx; }; export type Parameters = { siteUrl: string; previewPath: string; previewSecret?: string; }; const getDefaultState = (params: Partial): Parameters => ({ siteUrl: params.siteUrl || '', previewPath: params.previewPath || '', previewSecret: params.previewSecret || '', }); export default function ConfigScreen({ ctx }: Props) { const parameters = ctx.plugin.attributes.parameters as Parameters; const { handleSubmit, control } = useForm({ defaultValues: getDefaultState(parameters), }); const savePluginSettings = async (values: Parameters) => { await ctx.updatePluginParameters(values); ctx.notice('Settings updated successfully!'); }; return (
{ return ( ); }} /> { return ( ); }} /> { return ( ); }} />
); }