Skip to content

Commit

Permalink
chore: enhancing NewBook.tsx functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Sep 19, 2023
1 parent c0c42aa commit c6264db
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 212 deletions.
42 changes: 25 additions & 17 deletions src/components/forms/NewBook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,19 @@ export function FormNewBook() {
}
}

function handleFieldChange(fieldName, newValue) {
setBooks((books) => ({
...books,
[fieldName]: newValue,
}));
}

useEffect(() => {
// Genera el pathUrl basado en el título cada vez que se actualiza
const generatedPathUrl = generatePathUrl(books.title);
setBooks((books) => ({ ...books, pathUrl: generatedPathUrl }));
}, [books.title]);

function handleFormatChange(format) {
setBooks((books) => ({ ...books, format }));
}

function handleLanguageChange(language) {
setBooks((books) => ({ ...books, language }));
}

const fileInputRef = useRef<HTMLInputElement>(null);

function handleButtonClick() {
Expand Down Expand Up @@ -363,13 +362,21 @@ export function FormNewBook() {
</Flex>
</Button>
<Input
// {...register('image.url', {
// required: 'imagen',
// })}
accept='image/png, image/jpeg, image/jpg, image/webp'
display='none'
ref={fileInputRef}
type='file'
size='lg'
onChange={handleImageChange}
/>
{/* {errors.image?.url && (
<FormErrorMessage>
{errors.image?.url.message}
</FormErrorMessage>
)} */}
</FormControl>
<Box my='5' mb='5'>
<ModalCropper
Expand Down Expand Up @@ -449,12 +456,12 @@ export function FormNewBook() {
</Box>
</FormLabel>
<Select
id='lenguaje'
id='languaje'
name='language'
size={{ base: 'md', md: 'lg' }}
variant='filled'
onChange={(selectedOption) =>
handleLanguageChange(selectedOption?.value)
handleFieldChange('language', selectedOption?.value)
}
options={sortedLanguage}
noOptionsMessage={({ inputValue }) =>
Expand Down Expand Up @@ -504,12 +511,13 @@ export function FormNewBook() {
<Input
{...register('year', {
required: 'Año es obligatorio',
validate: {
value: (value) => {
return (
value.length === 4 || 'Año debe tener 4 caracteres'
);
},
min: {
value: 1800,
message: 'Año no valido',
},
max: {
value: 2050,
message: 'Año no valido',
},
})}
id='año'
Expand Down Expand Up @@ -567,7 +575,7 @@ export function FormNewBook() {
size={{ base: 'md', md: 'lg' }}
variant='filled'
onChange={(selectedOption) =>
handleFormatChange(selectedOption?.value)
handleFieldChange('format', selectedOption?.value)
}
options={sortedFormat}
noOptionsMessage={({ inputValue }) =>
Expand Down
245 changes: 50 additions & 195 deletions src/data/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,14 @@ import { AiOutlineCloudUpload } from 'react-icons/ai';
import { LinkType, SelectBooksType } from '../components/types';

const navLink: Array<LinkType> = [
{
name: 'Inicio',
href: '/',
icon: FiHome,
},
{
name: 'Explorar',
href: 'explore',
icon: MdOutlineExplore,
},
{
name: 'Publicar',
href: 'new-post',
icon: AiOutlineCloudUpload,
},
{ name: 'Inicio', href: '/', icon: FiHome },
{ name: 'Explorar', href: 'explore', icon: MdOutlineExplore },
{ name: 'Publicar', href: 'new-post', icon: AiOutlineCloudUpload },
];

const accountLinks: Array<LinkType> = [
{
name: 'Ingresar',
href: 'login',
},
{
name: 'Crear cuenta',
href: 'register',
},
{ name: 'Ingresar', href: 'login' },
{ name: 'Crear cuenta', href: 'register' },
];

const languages: Array<SelectBooksType> = [
Expand Down Expand Up @@ -87,181 +69,54 @@ const languages: Array<SelectBooksType> = [
];

const categories: Array<SelectBooksType> = [
{
value: 'Aventura',
label: 'Aventura',
},
{
value: 'Ciencia Ficción',
label: 'Ciencia Ficción',
},
{
value: 'Clásicos',
label: 'Clásicos',
},
{
value: 'Terror',
label: 'Terror',
},
{
value: 'Suspenso',
label: 'Suspenso',
},
{
value: 'Economía',
label: 'Economía',
},
{
value: 'Romance',
label: 'Romance',
},
{
value: 'Fantasía',
label: 'Fantasía',
},
{
value: 'Filosofía',
label: 'Filosofía',
},
{
value: 'Poesía',
label: 'Poesía',
},
{
value: 'Politica',
label: 'Politica',
},
{
value: 'Psicoterapia',
label: 'Psicoterapia',
},
{
value: 'Medicina',
label: 'Medicina',
},
{
value: 'Policiales',
label: 'Policiales',
},
{
value: 'Ciencia',
label: 'Ciencia',
},
{
value: 'Programación',
label: 'Programación',
},
{
value: 'Tecnología',
label: 'Tecnología',
},
{
value: 'Física',
label: 'Física',
},
{
value: 'Ingenierías',
label: 'Ingenierías',
},
{
value: 'Cómics',
label: 'Cómics',
},
{
value: 'Cocina',
label: 'Cocina',
},
{
value: 'Bebidas',
label: 'Bebidas',
},
{
value: 'Literatura',
label: 'Literatura',
},
{
value: 'Literatura Infantil',
label: 'Literatura Infantil',
},
{
value: 'Deportes',
label: 'Deportes',
},
{
value: 'Novela Histórica',
label: 'Novela Histórica',
},
{
value: 'Novela',
label: 'Novela',
},
{
value: 'Música',
label: 'Música',
},
{
value: 'Historia',
label: 'Historia',
},
{
value: 'Misterio',
label: 'Misterio',
},
{
value: 'Thriller',
label: 'Thriller',
},
{
value: 'Adulto',
label: 'Adulto',
},
{
value: 'Ficción',
label: 'Ficción',
},
{
value: 'No Ficción',
label: 'No Ficción',
},
{
value: 'Prehistoria',
label: 'Prehistoria',
},
{
value: 'Enciclopedias',
label: 'Enciclopedias',
},
{
value: 'Ficción Histórica',
label: 'Ficción Histórica',
},
{
value: 'Histórico',
label: 'Histórico',
},
{
value: 'Humor',
label: 'Humor',
},
{
value: 'Horror',
label: 'Horror',
},
{ value: 'Aventura', label: 'Aventura' },
{ value: 'Ciencia Ficción', label: 'Ciencia Ficción' },
{ value: 'Clásicos', label: 'Clásicos' },
{ value: 'Terror', label: 'Terror' },
{ value: 'Suspenso', label: 'Suspenso' },
{ value: 'Economía', label: 'Economía' },
{ value: 'Romance', label: 'Romance' },
{ value: 'Fantasía', label: 'Fantasía' },
{ value: 'Filosofía', label: 'Filosofía' },
{ value: 'Poesía', label: 'Poesía' },
{ value: 'Politica', label: 'Politica' },
{ value: 'Psicoterapia', label: 'Psicoterapia' },
{ value: 'Medicina', label: 'Medicina' },
{ value: 'Policiales', label: 'Policiales' },
{ value: 'Ciencia', label: 'Ciencia' },
{ value: 'Programación', label: 'Programación' },
{ value: 'Informática', label: 'Informática' },
{ value: 'Desarrollo De Software', label: 'Desarrollo De Software' },
{ value: 'Tecnología', label: 'Tecnología' },
{ value: 'Física', label: 'Física' },
{ value: 'Ingenierías', label: 'Ingenierías' },
{ value: 'Cómics', label: 'Cómics' },
{ value: 'Cocina', label: 'Cocina' },
{ value: 'Bebidas', label: 'Bebidas' },
{ value: 'Literatura', label: 'Literatura' },
{ value: 'Literatura Infantil', label: 'Literatura Infantil' },
{ value: 'Deportes', label: 'Deportes' },
{ value: 'Novela Histórica', label: 'Novela Histórica' },
{ value: 'Novela', label: 'Novela' },
{ value: 'Música', label: 'Música' },
{ value: 'Historia', label: 'Historia' },
{ value: 'Misterio', label: 'Misterio' },
{ value: 'Thriller', label: 'Thriller' },
{ value: 'Adulto', label: 'Adulto' },
{ value: 'Ficción', label: 'Ficción' },
{ value: 'No Ficción', label: 'No Ficción' },
{ value: 'Prehistoria', label: 'Prehistoria' },
{ value: 'Enciclopedias', label: 'Enciclopedias' },
{ value: 'Ficción Histórica', label: 'Ficción Histórica' },
{ value: 'Histórico', label: 'Histórico' },
{ value: 'Humor', label: 'Humor' },
{ value: 'Horror', label: 'Horror' },
];

const format: Array<SelectBooksType> = [
{
value: 'Físico',
label: 'Físico',
},
{
value: 'Electrónico',
label: 'Electrónico',
},
{
value: 'AudioLibro',
label: 'AudioLibro',
},
{ value: 'Físico', label: 'Físico' },
{ value: 'Electrónico', label: 'Electrónico' },
{ value: 'AudioLibro', label: 'AudioLibro' },
];

export { navLink, accountLinks, languages, categories, format };

1 comment on commit c6264db

@vercel
Copy link

@vercel vercel bot commented on c6264db Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

xbu – ./

xbu.vercel.app
xbu-git-main-franqsanz.vercel.app
xbu-franqsanz.vercel.app

Please sign in to comment.