diff --git a/src/components/forms/NewBook.tsx b/src/components/forms/NewBook.tsx index a7c22b6..db3cfef 100644 --- a/src/components/forms/NewBook.tsx +++ b/src/components/forms/NewBook.tsx @@ -23,7 +23,7 @@ import 'cropperjs/dist/cropper.css'; import { AiOutlineCloudUpload } from 'react-icons/ai'; import { BiImageAdd } from 'react-icons/bi'; -import { categories, format } from '../../data/links'; +import { categories, format, languages } from '../../data/links'; import { BookType } from '../types'; import { useMutatePost } from '../../hooks/querys'; import { ModalCropper } from '../forms/ModalCropper'; @@ -32,6 +32,10 @@ import { MyPopover } from '../MyPopover'; const Cropper = lazy(() => import('react-cropper')); +function sortArrayByLabel(array: T[]): T[] { + return array.slice().sort((a, b) => a.label.localeCompare(b.label)); +} + export function FormNewBook() { const { handleSubmit, @@ -74,11 +78,9 @@ export function FormNewBook() { const disabled = !allFieldsBook(books); - const sortedCategories = categories.sort((a, b) => { - if (a.label < b.label) return -1; - if (a.label > b.label) return 1; - return 0; - }); + const sortedCategories = sortArrayByLabel(categories); + const sortedLanguage = sortArrayByLabel(languages); + const sortedFormat = sortArrayByLabel(format); function handleChange( e: React.ChangeEvent< @@ -121,6 +123,10 @@ export function FormNewBook() { setBooks((books) => ({ ...books, format })); } + function handleLanguageChange(language) { + setBooks((books) => ({ ...books, language })); + } + const fileInputRef = useRef(null); function handleButtonClick() { @@ -161,9 +167,7 @@ export function FormNewBook() { } } - // function onSubmit(e: React.ChangeEvent) { function onSubmit() { - // e.preventDefault(); mutate(books); } @@ -338,12 +342,9 @@ export function FormNewBook() { {errors.synopsis.message} )} - + - Subir Imagen{' '} - - * - + Subir Imagen