import { useOnChange } from "@prismicio/editor-support/React"; import { Box, Dialog, DialogActionButton, DialogActions, DialogCancelButton, DialogContent, DialogHeader, Form, FormInput, ScrollArea, Select, SelectItem, Text, } from "@prismicio/editor-ui"; import { type FC, useState } from "react"; import { useSelector } from "react-redux"; import { SliceModalValuesValidity, validateSliceModalValues as validateAsNewSliceValues, } from "@/legacy/components/Forms/formsValidator"; import { pascalize } from "@/legacy/lib/utils/str"; import { getRemoteSlices } from "@/modules/slices"; import { SliceMachineStoreType } from "@/redux/type"; import styles from "./ConvertLegacySliceButton.module.css"; import { DialogProps } from "./types"; type FormValues = { from: string; sliceName: string; }; export const ConvertLegacySliceAsNewSliceDialog: FC = ({ isOpen, close, onSubmit, isLoading, slice, libraries, }) => { const { remoteSlices } = useSelector((store: SliceMachineStoreType) => ({ remoteSlices: getRemoteSlices(store), })); const defaultValues = { from: libraries[0]?.name, sliceName: pascalize(slice.key), }; const [values, setValues] = useState(defaultValues); const [errors, setErrors] = useState(); useOnChange(isOpen, () => { if (!isOpen) { setValues(defaultValues); setErrors(undefined); } }); function handleValueChange(values: FormValues) { setValues(values); setErrors(validateAsNewSliceValues(values, libraries, remoteSlices)); } function handleSubmit() { if (errors && Object.keys(errors).length > 0) { return; } onSubmit({ libraryID: values.from, sliceID: values.sliceName }); } return ( !open && close()} size={{ width: 448, height: "auto" }} >
This will create a new slice with the same fields. The new slice will replace the legacy slice in all of your types, and the existing slice content will be re-mapped to the new slice. This will not migrate your component. You will need to do that manually. handleValueChange({ ...values, sliceName: value.slice(0, 30), }) } data-testid="slice-name-input" /> A display name for the slice The library where we'll store your slice 0} > Upgrade
); };