Skip to content

Commit

Permalink
🌐 Implementing i18n in events-page
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Arevalo committed Sep 24, 2023
1 parent 5965cb9 commit f10b946
Show file tree
Hide file tree
Showing 11 changed files with 328 additions and 2,164 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-i18next": "^13.2.2",
"react-loader-spinner": "^5.4.5",
"swiper": "^10.2.0",
"tailwindcss": "3.3.3",
"viem": "^1.12.1",
Expand All @@ -54,4 +55,4 @@
"url": "^0.11.0",
"webpack-bundle-analyzer": "^4.9.0"
}
}
}
10 changes: 10 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,15 @@
"not-found": "This page was not found",
"error-code": "Error code",
"home": "Go back home"
},
"toasts": {
"ticket-bought": {
"title": "Ticket was bought!",
"description": "The ticket was successfully bought."
},
"failed": {
"title": "Transaction failed.",
"description": "The transaction failed. Try again."
}
}
}
10 changes: 10 additions & 0 deletions src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,15 @@
"not-found": "Esta página no fue encontrada",
"error-code": "Código de error",
"home": "Volver al inicio"
},
"toasts": {
"ticket-bought": {
"title": "Tiquete comprado!",
"description": "El tiquete fue comprado exitosamente."
},
"failed": {
"title": "Transaction failed.",
"description": "La transacción falló. Intenta de nuevo"
}
}
}
4 changes: 2 additions & 2 deletions src/components/events/GetTicketCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const GetTicketCard = (props: Props) => {
justifyContent={'center'}
>
<Text
fontSize='1.563rem'
fontSize='lg'
fontFamily={'space'}
fontWeight='semibold'
color={'#00001C'}
textAlign={'center'}
>
¡GRATIS!
GRATIS • Quedan 7 cupos
</Text>
{hasTicket ? (
<Button
Expand Down
7 changes: 3 additions & 4 deletions src/components/home/Events.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Flex, Grid, GridItem, Heading } from '@chakra-ui/react'
import { Center, Flex, Grid, GridItem, Heading } from '@chakra-ui/react'
import { useTranslation } from 'react-i18next'
import EventCard from './EventCard'
import Link from 'next/link'
import { MeetdAppFactory } from '../../../@types/typechain-types/MeetdAppFactory'
import { ethers } from 'ethers'
import Loader from '../shared/Loader'

const first_event = {
id: 0,
Expand Down Expand Up @@ -34,7 +33,7 @@ export default function Events(props: Props): React.ReactNode {
{t('landing.top-events.title')} 🔥
</Heading>
{isLoading ? (
<p>Loading...</p>
<Loader width='full' height='300px' color='#00001C' />
) : (
<Grid
width={'full'}
Expand Down
2 changes: 0 additions & 2 deletions src/components/home/MiddleSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import Section from './Section'
import { useTranslation } from 'react-i18next'
import Events from './Events'
import FAQ from './FAQ'
import { MeetdAppFactory } from '../../../@types/typechain-types/MeetdAppFactory'
import { ethers } from 'ethers'

type Props = {
isLoading: boolean
Expand Down
1 change: 1 addition & 0 deletions src/components/shared/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function Footer(): React.ReactNode {
width={'100%'}
align={'center'}
justify={'center'}
fontFamily={'neue'}
background={'#00001C'}
py={{ base: '3rem', md: '6rem' }}
>
Expand Down
27 changes: 27 additions & 0 deletions src/components/shared/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Center } from '@chakra-ui/react'
import { TailSpin } from 'react-loader-spinner'

interface loaderProps {
width: string
height: string
color: string
}

export default function Loader(props: loaderProps): JSX.Element {
const { width, height, color } = props

return (
<Center w={width} h={height}>
<TailSpin
height='60'
width='60'
color={color}
ariaLabel='tail-spin-loading'
radius='1'
wrapperStyle={{}}
wrapperClass=''
visible={true}
/>
</Center>
)
}
191 changes: 108 additions & 83 deletions src/pages/events/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import EventLocation from '@/components/events/EventLocation'
import GetTicketCard from '@/components/events/GetTicketCard'
import PreviousEvents from '@/components/events/PreviousEvents'
import TagsSection from '@/components/events/TagsSection'
import { Box, Flex, Grid } from '@chakra-ui/react'
import { Flex, useToast } from '@chakra-ui/react'
import { useRouter } from 'next/router'
import MeetdAppFactoryJson from '../../../assets/contracts/MeetdAppFactory.json'
import MeetdAppFactoryEventJson from '../../../assets/contracts/MeetdAppEvent.json'
Expand All @@ -20,9 +20,8 @@ import Footer from '@/components/shared/Footer'
import '../../../config/i18n'
import { CHAINID, PROVIDER } from '@/constants/constants'
import { useAccount, useNetwork } from 'wagmi'
import { time } from 'console'
import { TimeIcon } from '@chakra-ui/icons'
import { t } from 'i18next'
import Loader from '@/components/shared/Loader'
import { useTranslation } from 'react-i18next'

interface Event {
id: string
Expand All @@ -36,17 +35,17 @@ type Props = {

function Event(props: Props): JSX.Element {
const { event } = props
const [isBuyTicketLoading, setIsBuyTicketLoading] = useState<boolean>(false)
const [hasTicket, setHasTicket] = useState<boolean>(false)
const [isBuyTicketLoading, setIsBuyTicketLoading] = useState<boolean>(false)
const [isLoading, setIsLoading] = useState<boolean>(true)
const [meetdAppEventContract, setMeetdAppEventContract] =
useState<MeetdAppEvent | null>(null)
const [owner, setOwner] = useState<string | undefined>(undefined)

const router = useRouter()

// TODO: generate nanoId
const slug: string | string[] | undefined = router.query?.id
const { t } = useTranslation()
const toast = useToast()

const { address } = useAccount()
const { chain } = useNetwork()
Expand Down Expand Up @@ -96,8 +95,14 @@ function Event(props: Props): JSX.Element {
setIsBuyTicketLoading(false)
setHasTicket(true)

// TODO: i18n
alert('Se ha comprado el ticket correctamente.')
toast({
title: t('toasts.ticket-bought.title'),
description: t('toasts.ticket-bought.description'),
status: 'success',
duration: 3000,
isClosable: false,
position: 'top-right'
})
}
} catch (error) {
setIsBuyTicketLoading(false)
Expand All @@ -106,16 +111,34 @@ function Event(props: Props): JSX.Element {
if (error.message.includes('user rejected transaction')) {
return
} else if (error.message.includes('transaction failed')) {
// TODO: i18n
alert('La transacción falló')
toast({
title: 'Could not create account',
description: '',
status: 'success',
duration: 3000,
isClosable: false,
position: 'top-right'
})
} else {
// TODO: i18n
console.error('error: ', error)
alert('Ocurrió un error inesperado. Por favor intenta de nuevo.')
toast({
title: 'Account created.',
description: "We've created your account for you.",
status: 'success',
duration: 3000,
isClosable: false,
position: 'top-right'
})
}
} else {
// TODO: i18n
alert('Ocurrió un error desconocido.')
toast({
title: 'Account created.',
description: "We've created your account for you.",
status: 'success',
duration: 3000,
isClosable: false,
position: 'top-right'
})
}
}
}
Expand Down Expand Up @@ -174,83 +197,85 @@ function Event(props: Props): JSX.Element {
<>
<Navbar />

{isLoading ? (
<p>Loading...</p>
) : (
<Flex
background={
'linear-gradient(180deg, #348793 -0.41%, #00001C -0.4%, #053763 73.8%)'
}
gap={6}
paddingBottom={6}
alignItems={'center'}
justifyContent={'center'}
>
<Flex
mt={'8em'}
mb={'3em'}
maxW={'1200px'}
width={'90%'}
display={{ base: 'none', lg: 'flex' }}
gap={'3em'}
direction={'row'}
justifyContent={'center'}
>
<Flex
background={
'linear-gradient(180deg, #348793 -0.41%, #00001C -0.4%, #053763 73.8%)'
}
gap={6}
paddingBottom={6}
alignItems={'center'}
justifyContent={'center'}
>
{isLoading ? (
<Loader width='full' height='100vh' color='#DDEBED' />
) : (
<>
<Flex
direction={'column'}
flex={7}
w={'full'}
mt={'8em'}
mb={'3em'}
maxW={'1200px'}
width={'90%'}
display={{ base: 'none', lg: 'flex' }}
gap={'3em'}
order={{ base: 1, lg: 0 }}
direction={'row'}
justifyContent={'center'}
>
<EventImage />
<EventDetails />
<PreviousEvents />
<Attendees />
<TagsSection />
<Flex
direction={'column'}
flex={7}
w={'full'}
gap={'3em'}
order={{ base: 1, lg: 0 }}
>
<EventImage />
<EventDetails />
<PreviousEvents />
<Attendees />
<TagsSection />
</Flex>

<Flex
direction={'column'}
flex={3}
w={'full'}
gap={'3em'}
order={{ base: 0, lg: 1 }}
>
<EventLocation />
<GetTicketCard
getTicket={onBuyTicket}
isBuyTicketLoading={isBuyTicketLoading}
hasTicket={hasTicket}
/>
</Flex>
</Flex>

<Flex
direction={'column'}
flex={3}
w={'full'}
mt={'8em'}
width={'90%'}
display={{ base: 'flex', lg: 'none' }}
gap={'3em'}
order={{ base: 0, lg: 1 }}
direction={'column'}
justifyContent={'center'}
mb={'3em'}
>
<EventLocation />
<GetTicketCard
getTicket={onBuyTicket}
isBuyTicketLoading={isBuyTicketLoading}
hasTicket={hasTicket}
/>
</Flex>
</Flex>

<Flex
mt={'8em'}
width={'90%'}
display={{ base: 'flex', lg: 'none' }}
gap={'3em'}
direction={'column'}
justifyContent={'center'}
mb={'3em'}
>
<Flex direction={'column'} w={'full'} gap={'3em'}>
<EventImage />
<EventLocation />
<EventDetails />
<PreviousEvents />
<Attendees />
<TagsSection />
<GetTicketCard
getTicket={onBuyTicket}
isBuyTicketLoading={isBuyTicketLoading}
hasTicket={hasTicket}
/>
<Flex direction={'column'} w={'full'} gap={'3em'}>
<EventImage />
<EventLocation />
<EventDetails />
<PreviousEvents />
<Attendees />
<TagsSection />
<GetTicketCard
getTicket={onBuyTicket}
isBuyTicketLoading={isBuyTicketLoading}
hasTicket={hasTicket}
/>
</Flex>
</Flex>
</Flex>
</Flex>
)}
</>
)}
</Flex>
<Footer />
</>
)
Expand Down
Loading

0 comments on commit f10b946

Please sign in to comment.