-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: a new feature to create collections
- Loading branch information
Showing
11 changed files
with
410 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import { Flex, Icon } from '@chakra-ui/react'; | ||
import { CgOptions } from 'react-icons/cg'; | ||
|
||
export function AsideFilter() { | ||
return ( | ||
<> | ||
<Flex | ||
display={{ base: 'none', md: 'flex' }} | ||
direction='column' | ||
mt='10' | ||
pb='10' | ||
position='sticky' | ||
top='16' | ||
> | ||
<Flex align='center' py='2' mb='2' fontSize='xl' fontWeight='bold'> | ||
<Icon as={CgOptions} boxSize='20px' mr='2' /> | ||
Filtrar por: | ||
</Flex> | ||
<Flex | ||
display={{ base: 'none', md: 'flex' }} | ||
direction='column' | ||
h='450px' | ||
overflowY='auto' | ||
pr='2' | ||
sx={{ | ||
'&::-webkit-scrollbar': { | ||
width: '5px', | ||
}, | ||
'&::-webkit-scrollbar-thumb': { | ||
background: '#a2aab3', | ||
borderRadius: '30px', | ||
}, | ||
}} | ||
></Flex> | ||
</Flex> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { | ||
Button, | ||
Flex, | ||
FormControl, | ||
FormLabel, | ||
Input, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalHeader, | ||
ModalOverlay, | ||
useColorModeValue, | ||
} from '@chakra-ui/react'; | ||
|
||
import { useCreateCollections } from '@hooks/queries'; | ||
import { useAuth } from '@contexts/AuthContext'; | ||
|
||
interface ModalCollectionType { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
refetch: () => void; | ||
} | ||
|
||
export function ModalCollection({ isOpen, onClose, refetch }: ModalCollectionType) { | ||
const [name, setName] = useState<string>(''); | ||
const bgColorBox = useColorModeValue('white', 'gray.900'); | ||
const bgColorInput = useColorModeValue('gray.100', 'gray.800'); | ||
const { currentUser } = useAuth(); | ||
const uid = currentUser?.uid; | ||
const navigate = useNavigate(); | ||
const { mutate, isPending, isSuccess } = useCreateCollections(uid); | ||
|
||
function handleNameCollection(e: React.ChangeEvent<HTMLInputElement>) { | ||
const { value } = e.target; | ||
|
||
setName(value); | ||
} | ||
|
||
function handleSubmit(e: React.FormEvent<HTMLFormElement>) { | ||
e.preventDefault(); | ||
mutate(name); | ||
} | ||
|
||
useEffect(() => { | ||
if (isSuccess) { | ||
onClose(); | ||
refetch(); | ||
setName(''); | ||
navigate('/my-collections'); | ||
} | ||
}, [isSuccess, navigate, onClose]); | ||
|
||
return ( | ||
<> | ||
<Modal isOpen={isOpen} onClose={onClose} size={{ base: 'xs', sm: 'md' }}> | ||
<ModalOverlay backdropFilter='blur(7px)' /> | ||
<ModalContent overflow='hidden'> | ||
<ModalHeader bg={bgColorBox}>Crear nueva colección</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody bg={bgColorBox}> | ||
<form onSubmit={handleSubmit}> | ||
<Flex direction='column' gap='5' pb='2'> | ||
<FormControl isRequired> | ||
<FormLabel htmlFor='nameCollection'>Nombre</FormLabel> | ||
<Input | ||
value={name} | ||
onChange={handleNameCollection} | ||
size='lg' | ||
fontSize='sm' | ||
name='name' | ||
bg={bgColorInput} | ||
/> | ||
</FormControl> | ||
<Button | ||
type='submit' | ||
size='lg' | ||
bg='green.500' | ||
color='black' | ||
p='5' | ||
fontWeight='normal' | ||
border='1px' | ||
rounded='lg' | ||
isDisabled={!name} | ||
isLoading={isPending} | ||
loadingText='Creando...' | ||
_hover={{ outline: 'none', bg: 'green.600' }} | ||
> | ||
Crear | ||
</Button> | ||
</Flex> | ||
</form> | ||
</ModalBody> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.