diff --git a/src/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx b/src/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx index a86fb1c05..49c1a2834 100644 --- a/src/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx +++ b/src/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx @@ -103,7 +103,7 @@ const CollectionDetailsPage: React.FC = ({ publicationDate: maybe(() => collection.publicationDate, ""), seoDescription: maybe(() => collection.seoDescription, ""), seoTitle: maybe(() => collection.seoTitle, ""), - slug: collection.slug || "" + slug: collection?.slug || "" }} onSubmit={handleSubmit} confirmLeave diff --git a/src/components/SeoForm/SeoForm.tsx b/src/components/SeoForm/SeoForm.tsx index 9217a9cdd..89883d326 100644 --- a/src/components/SeoForm/SeoForm.tsx +++ b/src/components/SeoForm/SeoForm.tsx @@ -78,14 +78,14 @@ interface SeoFormProps { const SeoForm: React.FC = props => { const { - description = "", + description, descriptionPlaceholder, disabled, helperText, loading, - title = "", + title, slug, - slugPlaceholder = "", + slugPlaceholder, titlePlaceholder, onChange } = props; @@ -95,6 +95,39 @@ const SeoForm: React.FC = props => { const [expanded, setExpansionStatus] = React.useState(false); const toggleExpansion = () => setExpansionStatus(!expanded); const shouldDisplayHelperText = () => helperText && !expanded; + // const getParsedProps = () => { + // const keysToParse: Array = [ + // "slug", + // "slugPlaceholder", + // "description", + // "descriptionPlaceholder", + // "title", + // "titlePlaceholder" + // ]; + + // return reduce( + // props, + // (result, value, key: keyof SeoFormProps) => { + // console.log({ result, value, key }); + // if (keysToParse.includes(key)) { + // return { ...result, [key]: !!value ? "" : value }; + // } + // return result; + // }, + // {} as Partial + // ); + // }; + + // const { + // title, + // titlePlaceholder, + // slug, + // slugPlaceholder, + // description, + // descriptionPlaceholder + // } = getParsedProps(); + + // console.log({ ...getParsedProps() }); return ( @@ -146,7 +179,7 @@ const SeoForm: React.FC = props => { defaultMessage: "If empty, the preview shows what will be autogenerated." })} - value={slug.slice(0, 69)} + value={slug?.slice(0, 69)} disabled={loading || disabled} placeholder={slug || slugify(slugPlaceholder)} onChange={onChange} @@ -160,7 +193,7 @@ const SeoForm: React.FC = props => {
- {title.length > 0 && ( + {title?.length > 0 && ( = props => { defaultMessage: "If empty, the preview shows what will be autogenerated." })} - value={title.slice(0, 69)} + value={title?.slice(0, 69)} disabled={loading || disabled} placeholder={titlePlaceholder} onChange={onChange} @@ -192,7 +225,7 @@ const SeoForm: React.FC = props => {
- {description.length > 0 && ( + {description?.length > 0 && ( = props => { defaultMessage: "If empty, the preview shows what will be autogenerated." })} - value={description ? description.slice(0, 299) : undefined} + value={description?.slice(0, 299)} onChange={onChange} disabled={loading || disabled} fullWidth