Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth and icons #895

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions src/components/Auth/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Button, Flex, Text, useToast } from '@chakra-ui/react'
import { Button, Flex, Link, Text, useToast } from '@chakra-ui/react'
import { useMutation } from '@tanstack/react-query'
import { useState } from 'react'
import { useEffect, useState } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { NavLink, useNavigate } from 'react-router-dom'
import { NavLink, useNavigate, useOutletContext } from 'react-router-dom'
import { api, ApiEndpoints, UnverifiedApiError } from '~components/Auth/api'
import { ILoginParams } from '~components/Auth/authQueries'
import { useAuth } from '~components/Auth/useAuth'
import { VerificationPending } from '~components/Auth/Verify'
import FormSubmitMessage from '~components/Layout/FormSubmitMessage'
import InputPassword from '~components/Layout/InputPassword'
import { AuthOutletContextType } from '~elements/LayoutAuth'
import { Routes } from '~src/router/routes'
import CustomCheckbox from '../Layout/CheckboxCustom'
import InputBasic from '../Layout/InputBasic'
Expand Down Expand Up @@ -42,9 +43,12 @@ const SignIn = ({ email: emailProp }: { email?: string }) => {
const { t } = useTranslation()
const toast = useToast()
const navigate = useNavigate()
const { setTitle, setSubTitle } = useOutletContext<AuthOutletContextType>()
const methods = useForm<FormData>({
defaultValues: { email: emailProp },
})
const [isErrorA, setIsErrorA] = useState(false)
Copy link
Member

Choose a reason for hiding this comment

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

What? What are you trying with this state? Also, terrible naming.

const [isComponentMounted, setIsComponentMounted] = useState(false)
const { handleSubmit, watch } = methods
const email = watch('email', emailProp)

Expand All @@ -55,6 +59,20 @@ const SignIn = ({ email: emailProp }: { email?: string }) => {
const { mutateAsync: checkVerificationCodeStatus } = useVerificationCodeStatus()
const { mutateAsync: resendVerificationCode } = useResendVerificationCode()

useEffect(() => {
setTitle(t('signin_title'))
setSubTitle(t('signin_subtitle'))
setIsComponentMounted(true)
}, [])

useEffect(() => {
if (isComponentMounted && isError) {
setIsErrorA(true)
}

return () => setIsErrorA(false)
}, [isError])

const onSubmit = async (data: FormData) => {
await login(data)
.then(() => navigate(Routes.dashboard.base))
Expand Down Expand Up @@ -111,7 +129,6 @@ const SignIn = ({ email: emailProp }: { email?: string }) => {
label={t('email')}
placeholder={t('email_placeholder', { defaultValue: '[email protected]' })}
type='email'
required
/>
<InputPassword
formValue='password'
Expand All @@ -123,7 +140,7 @@ const SignIn = ({ email: emailProp }: { email?: string }) => {
<CustomCheckbox formValue='keepLogedIn' label={t('keep_me_logged', { defaultValue: 'Keep me logged' })} />

<NavLink to={Routes.auth.recovery}>
<Text color={'account.link'} fontSize='sm' fontWeight='500' whiteSpace='nowrap'>
<Text fontSize='sm' fontWeight='500' whiteSpace='nowrap'>
{t('forgot_password')}
</Text>
</NavLink>
Expand All @@ -137,14 +154,12 @@ const SignIn = ({ email: emailProp }: { email?: string }) => {
<Flex flexDirection='column' justifyContent='center' alignItems='start' maxW='100%' mt={0}>
<Text fontWeight='400' fontSize='sm'>
{t('not_registred_yet')}
<NavLink to={Routes.auth.signUp}>
<Text color={'account.link'} as='span' ms={1} fontWeight='500'>
{t('create_account')}
</Text>
</NavLink>
<Link as={NavLink} to={Routes.auth.signUp} ml={1} fontWeight={500}>
{t('create_account')}
</Link>
</Text>
</Flex>
<FormSubmitMessage isError={isError} error={error} />
<FormSubmitMessage isError={isErrorA} error={error} />
</>
)
}
Expand Down
29 changes: 20 additions & 9 deletions src/components/Auth/SignUp.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Button, Flex, Link, Text } from '@chakra-ui/react'
import { useEffect } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { Trans, useTranslation } from 'react-i18next'
import { Navigate, NavLink, Link as ReactRouterLink } from 'react-router-dom'
import { Navigate, NavLink, Link as ReactRouterLink, useOutletContext } from 'react-router-dom'
import { IRegisterParams } from '~components/Auth/authQueries'
import { useAuth } from '~components/Auth/useAuth'
import { VerificationPending } from '~components/Auth/Verify'
import FormSubmitMessage from '~components/Layout/FormSubmitMessage'
import InputPassword from '~components/Layout/InputPassword'
import { AuthOutletContextType } from '~elements/LayoutAuth'
import { useSignupFromInvite } from '~src/queries/account'
import { Routes } from '~src/router/routes'
import CustomCheckbox from '../Layout/CheckboxCustom'
Expand All @@ -32,6 +34,8 @@ const SignUp = ({ invite }: SignupProps) => {
const { t } = useTranslation()
const { register } = useAuth()
const inviteSignup = useSignupFromInvite(invite?.address)
const { setTitle, setSubTitle } = useOutletContext<AuthOutletContextType>()

const methods = useForm<FormData>({
defaultValues: {
terms: false,
Expand All @@ -45,6 +49,11 @@ const SignUp = ({ invite }: SignupProps) => {
const isError = register.isError || inviteSignup.isError
const error = register.error || inviteSignup.error

useEffect(() => {
setTitle(t('signup_title'))
setSubTitle(t('signup_subtitle'))
}, [])

const onSubmit = (user: FormData) => {
if (!invite) {
return register.mutate(user)
Expand Down Expand Up @@ -87,16 +96,20 @@ const SignUp = ({ invite }: SignupProps) => {
formValue='email'
label={t('email')}
placeholder={t('email_placeholder', { defaultValue: '[email protected]' })}
type='email'
required
validation={{
required: t('form.error.field_is_required'),
pattern: {
value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, // Regex para validar emails
message: t('form.error.email_invalid', { defaultValue: 'Invalid email address' }),
},
}}
isDisabled={!!invite}
/>
<InputPassword
formValue='password'
label={t('password')}
placeholder={t('password_placeholder')}
type='password'
required
validation={{
required: t('form.error.field_is_required'),
minLength: {
Expand Down Expand Up @@ -129,11 +142,9 @@ const SignUp = ({ invite }: SignupProps) => {
<Flex flexDirection='column' justifyContent='center' alignItems='start' maxW='100%'>
<Text color='account.description' fontWeight='400' fontSize='sm'>
{t('already_member')}
<NavLink to={Routes.auth.signIn}>
<Text color={'account.link'} as='span' ms={1} fontWeight='500'>
{t('signin')}
</Text>
</NavLink>
<Link as={NavLink} to={Routes.auth.signIn} ml={1} fontWeight={500}>
{t('signin')}
</Link>
</Text>
</Flex>
{isError && <FormSubmitMessage isError={isError} error={error} />}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Home/Benefits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Benefits = () => {
right='9%'
/>
</Box>
<Box as='section' id='benefits' mt={{ base: '50px' }}>
<Box as='section' id='benefits'>
<Box
width='full'
m='0 auto'
Expand Down
27 changes: 14 additions & 13 deletions src/components/Home/Clients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Clients = () => {
>
{t('home.clients_title')}
</Text>
<ClientsGrid />
</>
)
}
Expand All @@ -40,89 +41,89 @@ export const ClientsGrid = (props: GridProps) => (
sm: '20px',
md: '80px',
}}
maxW={{ base: '100%', sm: '70%', sm2: '80%', lg: '900px' }}
maxW={{ base: '100%', sm: '80%', lg: '900px' }}
flexDirection={{ base: 'column', sm: 'row' }}
justifyContent='center'
mb={{ base: '60px' }}
mb={{ lg: '60px' }}
gridTemplateColumns='repeat(5, 1fr)'
gridRowGap='50px'
gridRowGap={{ base: '0px', sm: '30px', lg: '50px' }}
{...props}
>
<Card variant='client'>
<CardHeader>
<Image src={barca} h={{ base: '32.5px', sm2: '65px', lg: '70px' }} />
<Image src={barca} h={{ base: '45.5px', sm2: '65px', lg: '70px' }} />
</CardHeader>
<CardBody>
<Text as='span'>F.C. Barcelona</Text>
</CardBody>
</Card>
<Card variant='client'>
<CardHeader>
<Image src={omnium} h={{ base: '27.5px', sm2: '75px', lg: '87px' }} />
<Image src={omnium} h={{ base: '52.5px', sm2: '75px', lg: '87px' }} />
</CardHeader>
<CardBody>
<Text as='span'>Omnium Cultural</Text>
</CardBody>
</Card>
<Card variant='client'>
<CardHeader>
<Image src={berga} h={{ base: '35px', sm2: '70px', lg: '81px' }} />
<Image src={berga} h={{ base: '49px', sm2: '70px', lg: '81px' }} />
</CardHeader>
<CardBody>
<Text as='span'>Ajuntament Berga</Text>
</CardBody>
</Card>
<Card variant='client'>
<CardHeader>
<Image src={bisbal} h={{ base: '36px', sm2: '72px', lg: '83px' }} />
<Image src={bisbal} h={{ base: '50px', sm2: '72px', lg: '83px' }} />
</CardHeader>
<CardBody>
<Text as='span'>Ajuntament la Bisbal</Text>
</CardBody>
</Card>
<Card variant='client'>
<CardHeader>
<Image src={coec} h={{ base: '17.5px', sm2: '35px', lg: '45px' }} />
<Image src={coec} h={{ base: '24.5px', sm2: '35px', lg: '45px' }} />
</CardHeader>
<CardBody>
<Text as='span'>COEC</Text>
</CardBody>
</Card>
<Card variant='client'>
<CardHeader>
<Image src={erc} h={{ base: '19px', sm2: '38px', lg: '52px' }} />
<Image src={erc} h={{ base: '26.5px', sm2: '38px', lg: '52px' }} />
</CardHeader>
<CardBody>
<Text as='span'>Esquerra Republicana</Text>
</CardBody>
</Card>
<Card variant='client'>
<CardHeader>
<Image src={bellpuig} h={{ base: '36px', sm2: '72px', lg: '83px' }} />
<Image src={bellpuig} h={{ base: '50px', sm2: '72px', lg: '83px' }} />
</CardHeader>
<CardBody>
<Text as='span'>Ajuntament Bellpuig</Text>
</CardBody>
</Card>
<Card variant='client'>
<CardHeader>
<Image src={ticanoia} h={{ base: '13px', sm2: '26px', lg: '32px' }} />
<Image src={ticanoia} h={{ base: '18px', sm2: '26px', lg: '32px' }} />
</CardHeader>
<CardBody>
<Text as='span'>TIC Anoia</Text>
</CardBody>
</Card>
<Card variant='client'>
<CardHeader>
<Image src={decidim} h={{ base: '31px', sm2: '62px', lg: '70px' }} />
<Image src={decidim} h={{ base: '43.5px', sm2: '62px', lg: '70px' }} />
</CardHeader>
<CardBody>
<Text as='span'>Decidim</Text>
</CardBody>
</Card>
<Card variant='client'>
<CardHeader>
<Image src={bloock} h={{ base: '17.5px', sm2: '35px', lg: '33px' }} />
<Image src={bloock} h={{ base: '24.5px', sm2: '35px', lg: '33px' }} />
</CardHeader>
<CardBody>
<Text as='span'>Bloock</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout/CheckboxCustom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface CheckboxCustomProps {
colorScheme?: string
}

const CheckboxCustom = ({ formValue, label, required = false, colorScheme = 'brandScheme' }: CheckboxCustomProps) => {
const CheckboxCustom = ({ formValue, label, required = false, colorScheme = 'brand' }: CheckboxCustomProps) => {
const { t } = useTranslation()
const {
register,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout/InputBasic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const InputBasic = ({ formValue, label, required = false, validation = {}, ...pr
const errorMessage = errors[formValue]?.message?.toString() || ''

return (
<FormControl isInvalid={!!errors[formValue]} isRequired={required}>
<FormControl isInvalid={!!errors[formValue]}>
{label && <FormLabel>{label}</FormLabel>}
<Input {...register(formValue, validationRules)} {...props} />
<FormErrorMessage mt={2}>{errorMessage || 'Error performing the operation'}</FormErrorMessage>
Expand Down
1 change: 0 additions & 1 deletion src/components/Organization/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export const OrganizationCreate = ({
id='process-create-form'
direction='column'
gap={6}
maxW='90%'
mx='auto'
{...props}
onSubmit={(e) => {
Expand Down
17 changes: 11 additions & 6 deletions src/components/Organization/Dashboard/AuthBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AuthBanner = ({ children, ...props }: AuthBannerProps) => {
flex={{ base: '1 1 100%', xl: '1 1 50%' }}
background='linear-gradient(to bottom, #B5F492, #338B93)'
borderBottomLeftRadius={{ xl: '200px' }}
pt={14}
pt={{ base: 20, xl: 0 }}
pb={{ xl: 5 }}
>
<ColorModeSwitcher position='absolute' top={3.5} right={2.5} />
Expand All @@ -29,25 +29,30 @@ const AuthBanner = ({ children, ...props }: AuthBannerProps) => {
}}
textAlign='center'
h='100%'
maxW='600px'
mx='auto'
{...props}
>
{children}
<Flex mt='auto' flexDirection='column' alignItems='center' justifyContent='center' color='white'>
<Flex mt='auto' flexDirection='column' alignItems='center' justifyContent='center'>
<List display='flex' gap={5}>
<ListItem>
<Link as={ReactRouterLink} fontWeight='500' to='mailto:[email protected]'>
<Link as={ReactRouterLink} fontWeight='500' to='mailto:[email protected]' color={'banner_link'}>
{t('support', { defaultValue: 'Support' })}
</Link>
</ListItem>
<ListItem>
<Link as={ReactRouterLink} fontWeight='500' to={Routes.terms}>
<Link as={ReactRouterLink} fontWeight='500' to={Routes.terms} isExternal color={'banner_link'}>
{t('terms_of_use', { defaultValue: 'Terms of use' })}
</Link>
</ListItem>
<ListItem>
<Link as={ReactRouterLink} fontWeight='500' to='https://blog.vocdoni.io/' isExternal>
<Link
as={ReactRouterLink}
fontWeight='500'
to='https://blog.vocdoni.io/'
isExternal
color={'banner_link'}
>
{t('blog', { defaultValue: 'Blog' })}
</Link>
</ListItem>
Expand Down
Loading