From f91a5adfa546fe8312c23891bc3f6e9f3eb7fc43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Mon, 16 Dec 2024 12:29:41 -0300 Subject: [PATCH] feat: add rich text editor --- .../featured-items-form/FeaturedItemsForm.tsx | 2 +- .../featured-item/FeaturedItem.module.scss | 11 ++++ .../featured-item/FeaturedItem.tsx | 50 ++++++++++++------- .../models/CollectionFeaturedItemMother.ts | 10 ++-- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/sections/collection-featured-items/featured-items-form/FeaturedItemsForm.tsx b/src/sections/collection-featured-items/featured-items-form/FeaturedItemsForm.tsx index 14b3fccb3..01669ebd7 100644 --- a/src/sections/collection-featured-items/featured-items-form/FeaturedItemsForm.tsx +++ b/src/sections/collection-featured-items/featured-items-form/FeaturedItemsForm.tsx @@ -59,7 +59,7 @@ export const FeaturedItemsForm = ({ defaultValues }: FeaturedItemsFormProps) => } const submitForm = (data: FeaturedItemsFormData) => { - console.log(data) + console.log({ data }) } // const formFieldsToFeaturedItems: CollectionFeaturedItem[] = form diff --git a/src/sections/collection-featured-items/featured-items-form/featured-item/FeaturedItem.module.scss b/src/sections/collection-featured-items/featured-items-form/featured-item/FeaturedItem.module.scss index 097be6da6..06092addb 100644 --- a/src/sections/collection-featured-items/featured-items-form/featured-item/FeaturedItem.module.scss +++ b/src/sections/collection-featured-items/featured-items-form/featured-item/FeaturedItem.module.scss @@ -46,6 +46,10 @@ } } + .form-group-content { + cursor: auto; + } + .image-dropzone { display: grid; place-items: center; @@ -67,4 +71,11 @@ margin: 0; } } + + .error-msg { + width: 100%; + margin-top: 0.25rem; + color: $dv-danger-color; + font-size: 0.875em; + } } diff --git a/src/sections/collection-featured-items/featured-items-form/featured-item/FeaturedItem.tsx b/src/sections/collection-featured-items/featured-items-form/featured-item/FeaturedItem.tsx index fdc6f619d..34bebb0b0 100644 --- a/src/sections/collection-featured-items/featured-items-form/featured-item/FeaturedItem.tsx +++ b/src/sections/collection-featured-items/featured-items-form/featured-item/FeaturedItem.tsx @@ -1,7 +1,7 @@ import { Controller, useFormContext } from 'react-hook-form' import { useSortable } from '@dnd-kit/sortable' import { CSS } from '@dnd-kit/utilities' -import { Col, Form, Row } from '@iqss/dataverse-design-system' +import { Col, Form, RichTextEditor, Row } from '@iqss/dataverse-design-system' import cn from 'classnames' import { DynamicFieldsButtons } from '@/sections/shared/form/DynamicFieldsButtons/DynamicFieldsButtons' import styles from './FeaturedItem.module.scss' @@ -14,6 +14,9 @@ interface FeaturedItemProps { disableDragWhenOnlyOneItem: boolean } +// TODO:ME - Image just an input image field, no dropzone as it is too small +// TODO:ME - Logic to show the image thumbnail on top of the image input field, if an image is uploaded (use the image field from the form). Add button to remove the image. how that logic could be? + export const FeaturedItem = ({ id, itemIndex, @@ -113,26 +116,39 @@ export const FeaturedItem = ({ - - Content + + + Content + ( - - - {error?.message} - - )} + rules={{ + required: 'Content is required', + validate: (value: string) => { + if (value === '

' || value === '') { + return 'Content is required' + } + return true + } + }} + render={({ field: { onChange, ref, value }, fieldState: { invalid, error } }) => { + // TODO:ME - Make ref work with RichTextEditor + // TODO:ME - Allow passing aria-required to RichTextEditor + return ( + + + + {invalid &&
{error?.message}
} + + ) + }} />
diff --git a/tests/component/collection/domain/models/CollectionFeaturedItemMother.ts b/tests/component/collection/domain/models/CollectionFeaturedItemMother.ts index e7c418e6f..dc748ad85 100644 --- a/tests/component/collection/domain/models/CollectionFeaturedItemMother.ts +++ b/tests/component/collection/domain/models/CollectionFeaturedItemMother.ts @@ -9,7 +9,7 @@ export class CollectionFeaturedItemMother { order: 1, title: 'Featured item 1', content: - 'Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut alias eos expedita quae quisquam ea nemo neque incidunt amet. Odit quos libero aliquam labore dicta eaque dolorum, consequuntur itaque corrupti, reiciendis quas ab. Voluptatem alias, quam, aliquid excepturi repudiandae ab ex pariatur, est id perspiciatis porro impedit adipisci beatae ipsam.' + '

Lorem 1 ipsum, dolor sit amet consectetur adipisicing elit. Aut alias eos expedita quae quisquam ea nemo neque incidunt amet. Odit quos libero aliquam labore dicta eaque dolorum, consequuntur itaque corrupti, reiciendis quas ab. Voluptatem alias, quam, aliquid excepturi repudiandae ab ex pariatur, est id perspiciatis porro impedit adipisci beatae ipsam.

' }, { id: 'item-2-id', @@ -17,7 +17,7 @@ export class CollectionFeaturedItemMother { order: 2, title: 'Featured item 2', content: - 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Autem assumenda nam repellendus adipisci doloremque fugit maiores. Repudiandae sequi illo eum quod id quisquam vero enim ipsa distinctio, quia, consequatur harum dolor non voluptatibus ipsum, rem vel quo voluptates magni eveniet velit hic! Repellendus, provident? Dolore maxime ullam ut est, delectus itaque beatae alias corporis doloremque architecto magni officiis tenetur reprehenderit.', + '

Lorem 2 ipsum, dolor sit amet consectetur adipisicing elit. Aut alias eos expedita quae quisquam ea nemo neque incidunt amet. Odit quos libero aliquam labore dicta eaque dolorum, consequuntur itaque corrupti, reiciendis quas ab. Voluptatem alias, quam, aliquid excepturi repudiandae ab ex pariatur, est id perspiciatis porro impedit adipisci beatae ipsam.

', imageUrl: 'https://via.placeholder.com/150x80' }, { @@ -26,7 +26,7 @@ export class CollectionFeaturedItemMother { order: 3, title: 'Featured item 3', content: - 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Autem assumenda nam repellendus adipisci doloremque fugit maiores. Repudiandae sequi illo eum quod id quisquam vero enim ipsa distinctio, quia, consequatur harum dolor non voluptatibus ipsum, rem vel quo voluptates magni eveniet velit hic! Repellendus, provident? Dolore maxime ullam ut est, delectus itaque beatae alias corporis doloremque architecto magni officiis tenetur reprehenderit.' + '

Lorem 3 ipsum, dolor sit amet consectetur adipisicing elit. Aut alias eos expedita quae quisquam ea nemo neque incidunt amet. Odit quos libero aliquam labore dicta eaque dolorum, consequuntur itaque corrupti, reiciendis quas ab. Voluptatem alias, quam, aliquid excepturi repudiandae ab ex pariatur, est id perspiciatis porro impedit adipisci beatae ipsam.

' }, { id: 'item-4-id', @@ -34,7 +34,7 @@ export class CollectionFeaturedItemMother { order: 4, title: 'Featured item 4', content: - 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere enim alias quibusdam debitis quaerat, consectetur velit aliquid ipsum! Iusto obcaecati quibusdam hic nam voluptate. Consequuntur laborum officia aliquid recusandae ut, numquam sequi explicabo voluptatum reprehenderit, minima nulla repudiandae at magni fugit quis. Numquam architecto voluptas repudiandae vel totam officia ut? Nobis ex natus optio. Laborum veniam inventore suscipit architecto consectetur minima commodi dolore ducimus ipsam sint vitae doloremque, dolorem ullam! Iusto corporis commodi, pariatur vel magni, dolorum vero non, exercitationem cumque in deserunt? Iste quia dolor aut ullam dolorem eum quidem id accusamus officiis dolore. Quia placeat sapiente aperiam vero distinctio quidem, fugiat recusandae quisquam saepe ut, nesciunt laborum. Aspernatur ea, quasi, facilis impedit optio repellendus quo dolorum velit officia nihil mollitia provident commodi, delectus vero sint porro modi dolores? Ipsam doloribus impedit iure nemo architecto minima explicabo, eligendi dolorem voluptatem sequi aperiam, quisquam placeat ullam facere ut, minus at sit inventore enim eveniet cum. Repellendus eius quam architecto vel cum quod, tenetur neque deserunt, hic a perferendis adipisci fuga quibusdam dignissimos accusantium autem. Quisquam, ipsum harum fugit voluptatum aperiam minus corrupti hic qui impedit eveniet facere ut iure omnis error dicta nobis eum. Repellendus quia, laboriosam laudantium voluptates expedita fuga nulla? Quia nobis labore possimus debitis temporibus minus neque molestiae quam! Repellat reiciendis culpa similique odit doloribus quas praesentium quasi. Voluptatem amet iusto dolore, id, ut eligendi soluta assumenda excepturi perferendis, reiciendis odit explicabo ipsam maiores. Aut corporis eveniet quia repudiandae dolorem nam, excepturi ipsam veniam amet perferendis ullam eaque suscipit unde consequuntur asperiores maiores vel. Adipisci, asperiores. Iure quasi natus repudiandae quod, placeat blanditiis earum tenetur at dolores? Laudantium nam aperiam architecto consequatur, quos molestiae, amet sit itaque debitis neque quo? Iste repellendus vero illo deleniti eum impedit perferendis odit earum, iusto in porro id itaque quasi voluptate.', + '

Lorem 4 ipsum, dolor sit amet consectetur adipisicing elit. Aut alias eos expedita quae quisquam ea nemo neque incidunt amet. Odit quos libero aliquam labore dicta eaque dolorum, consequuntur itaque corrupti, reiciendis quas ab. Voluptatem alias, quam, aliquid excepturi repudiandae ab ex pariatur, est id perspiciatis porro impedit adipisci beatae ipsam.

', imageUrl: 'https://via.placeholder.com/400x400' } ] @@ -47,7 +47,7 @@ export class CollectionFeaturedItemMother { order: 1, title: 'Featured item', content: - 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Autem assumenda nam repellendus adipisci doloremque fugit maiores. Repudiandae sequi illo eum quod id quisquam vero enim ipsa distinctio, quia, consequatur harum dolor non voluptatibus ipsum, rem vel quo voluptates magni eveniet velit hic! Repellendus, provident? Dolore maxime ullam ut est, delectus itaque beatae alias corporis doloremque architecto magni officiis tenetur reprehenderit.', + '

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut alias eos expedita quae quisquam ea nemo neque incidunt amet. Odit quos libero aliquam labore dicta eaque dolorum, consequuntur itaque corrupti, reiciendis quas ab. Voluptatem alias, quam, aliquid excepturi repudiandae ab ex pariatur, est id perspiciatis porro impedit adipisci beatae ipsam.

', imageUrl: 'https://via.placeholder.com/150x80', ...props }