Skip to content

Commit

Permalink
feat: add max limit of 10 items
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Feb 4, 2025
1 parent 10db4c9 commit 5e83f2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion public/locales/en/editCollectionFeaturedItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"submitStatus": {
"success": "Featured items have been updated successfully."
}
},
"maxItemsReached": "You can add up to {{maxFeaturedItems}} featured items."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { FormProvider, useFieldArray, useForm } from 'react-hook-form'
import { DndContext, DragEndEvent } from '@dnd-kit/core'
import { restrictToVerticalAxis } from '@dnd-kit/modifiers'
import { SortableContext } from '@dnd-kit/sortable'
import { useTranslation } from 'react-i18next'
import { toast } from 'react-toastify'
import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository'
import { CollectionFeaturedItem } from '@/collection/domain/models/CollectionFeaturedItem'
import { FeaturedItemField } from './featured-item-field/FeaturedItemField'
Expand All @@ -27,6 +29,7 @@ export const FeaturedItemsForm = ({
defaultValues,
collectionFeaturedItems
}: FeaturedItemsFormProps) => {
const { t } = useTranslation('editCollectionFeaturedItems')
const [showConfirmDeleteModal, setShowConfirmDeleteModal] = useState(false)
const hasInitialFeaturedItems = collectionFeaturedItems.length > 0

Expand Down Expand Up @@ -56,6 +59,11 @@ export const FeaturedItemsForm = ({
})

const handleOnAddField = (index: number) => {
if (fieldsArray.length === 10) {
toast.warning(t('form.maxItemsReached', { maxFeaturedItems: 10 }))
return
}

insert(
index + 1,
{ content: '', image: null },
Expand Down

0 comments on commit 5e83f2a

Please sign in to comment.