Skip to content

Commit

Permalink
update contest
Browse files Browse the repository at this point in the history
  • Loading branch information
imhson committed Aug 8, 2024
1 parent f0c7e9b commit 7e3d1d1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
37 changes: 23 additions & 14 deletions src/components/pages/artist/Contests.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Pagination, Skeleton } from '@mui/material'
import Mc from 'assets/images/mascot-empty.png'
import moment from 'moment'
import Image from 'next/image'
import Link from 'next/link'
import { useRouter } from 'next/router'
Expand All @@ -26,16 +27,16 @@ export default function Contests({ id }) {
<Skeleton className='w-full aspect-[343/256]' />
</div>
)
console.log(data)
console.log(data)
return (
<div>
{data?.contest?.length ? (
<div className='grid grid-cols-1 gap-4'>
{data?.contest?.map((event, index) => (
<Link key={event.url} href={event.url} className='rounded-mlg p-4 bg-white relative'>
{data?.contests?.length ? (
<div className='grid grid-cols-[repeat(auto-fill,minmax(330px,1fr))] gap-4'>
{data?.contests?.map((contest, index) => (
<div key={contest.slug} className='rounded-mlg p-4 bg-white relative'>
<div className='relative'>
<Image src={event[locale].image} alt='' className='w-full aspect-[310/166] object-cover' />
{event.isLive && (
<Image src={contest[locale].image} width={400} height={400} alt='' className='w-full aspect-[310/166] object-cover' />
{moment().isAfter(contest.start_date) && moment().isBefore(contest.end_date) && (
<div className='absolute top-2.5 right-2.5 text-xxs font-semibold leading-[15px] bg-error-100 text-text-error-primary-3 flex items-center gap-1 rounded px-2.5 py-0.5'>
<svg xmlns='http://www.w3.org/2000/svg' width='4' height='4' viewBox='0 0 4 4' fill='none'>
<circle cx='2' cy='2' r='2' fill='#F73B3B' />
Expand All @@ -45,24 +46,32 @@ export default function Contests({ id }) {
)}
</div>
<div className='mt-4'>
<div className='text-sm font-medium'>{event[locale].title}</div>
<div className='mt-1 text-xs text-text-teriary font-medium'>{event[locale].subtitle}</div>
<div className='text-sm font-medium'>{contest[locale].title}</div>
<div className='mt-1 text-xs text-text-teriary font-medium'>
{locale == 'vn'
? `${moment(contest.start_date).format('DD/MM/yyyy')} - ${moment(contest.end_date).format(
'DD/MM/yyyy'
)}`
: `${moment(contest.start_date).format('MM/DD/yyyy')} - ${moment(contest.end_date).format(
'MM/DD/yyyy'
)}`}
</div>
</div>
</Link>
</div>
))}
<div></div>
</div>
) : (
<div className='flex flex-col items-center gap-4 py-8'>
<Image src={Mc} alt='' className='w-[160px] h-[160px]' />
<div className='font-medium'>{t('No artwork found')}</div>
<div className='font-medium'>{t('No contest applied')}</div>
</div>
)}
{!!data?.contest_aggregate?.aggregate?.count && (
<div className='w-full flex justify-center -mt-8'>
{!!data?.count && (
<div className='w-full flex justify-center mt-4'>
<Pagination
shape='rounded'
count={Math.ceil(data?.contest_aggregate?.aggregate?.count / 4)}
count={Math.ceil(data?.count / 4)}
page={page}
onChange={(event: React.ChangeEvent<unknown>, value: number) => {
setPage(value)
Expand Down
18 changes: 16 additions & 2 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,20 @@ export const getArtistCollections = async (id: string) => {
return { launchpads: launchpads as Launchpad[], count }
}
export const getContests = async (id: string) => {
const res = await axios.get(`${getConfig().API_URL}/api/rest/public/creators/${id}/contests`)
return res?.data
const {data} = await axios.get(`${getConfig().API_URL}/api/rest/public/creators/${id}/contests`)
const contestData = data.contest
const count = data.contest_aggregate.aggregate.count
const contests = contestData?.map((contest: any) => {
LANGUAGE.forEach((l) => {
const contestLanguage =
contest.contest_i18ns.find((ml) => ml.i18n_language.id == l.id) ||
contest.contest_i18ns.find((ml) => ml.i18n_language.is_main)
contest[l.shortLang] = {
title: contestLanguage?.data?.title,
image: contestLanguage?.data?.image,
}
})
return contest
})
return { contests: contests, count }
}

0 comments on commit 7e3d1d1

Please sign in to comment.