Skip to content
Closed
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
68 changes: 35 additions & 33 deletions src/components/profile/v2/CreatedChallenges.jsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
import React, { useEffect, useState } from 'react';
import request from '@/utils/request';
import ChallengeCard from '@/components/profile/ChallengeCard';
import React, { useEffect, useState } from 'react'
import request from '@/utils/request'
import ChallengeCard from '@/components/profile/ChallengeCard'

const CreatedChallenges = ({ user }) => {
const [createdChallenges, setCreatedChallenges] = useState([]);
console.log("cc user", user);
const [createdChallenges, setCreatedChallenges] = useState([])
console.log('cc user', user)
useEffect(() => {
if (!user) {
return;
return
}

const fetchData = async () => {
try {
const challengeEndPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${user}/challenges`;
const challengeResult = await request(challengeEndPoint, 'GET', null);
const challengeEndPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${user}/challenges`
const challengeResult = await request(challengeEndPoint, 'GET', null)
if (!challengeResult) {
setCreatedChallenges([]);
return;
setCreatedChallenges([])
return
}
const publicChallenges = challengeResult.filter(
(challenge) => challenge.private === false
);
setCreatedChallenges(publicChallenges);
)
setCreatedChallenges(publicChallenges)
} catch (err) {
console.log(err);
console.log(err)
}
};
}

fetchData();
}, [user]);
fetchData()
}, [user])

return (
<div className="mt-4 rounded-sm">
{createdChallenges.length > 0 ? (
createdChallenges.map((challenge) => (
<ChallengeCard
challenge={challenge}
key={challenge.challengeId}
/>
))
) : (
<div className="align-center duration-4000 col-span-5 mx-auto min-h-[190px] w-full min-w-[200px] rounded-sm border border-2 border-neutral-700 bg-neutral-800 px-4 py-4 text-center transition ease-in-out hover:bg-neutral-700/40">
<img src={'../../CuteKana.png'} width="100" className="mx-auto mt-2 px-1" />
<h1 className="mx-auto mt-2 text-center text-xl text-white">No Challenges Created Yet...</h1>
<div className='mt-4 rounded-sm'>
{createdChallenges.length > 0
? (
createdChallenges.map((challenge) => (
<ChallengeCard
challenge={challenge}
key={challenge.challengeId}
/>
))
)
: (
<div className='align-center duration-4000 col-span-5 mx-auto min-h-[190px] w-full min-w-[200px] rounded-sm border border-2 border-neutral-700 bg-neutral-800 px-4 py-4 text-center transition ease-in-out hover:bg-neutral-700/40'>
<img src='../../CuteKana.png' width='100' className='mx-auto mt-2 px-1' />
<h1 className='mx-auto mt-2 text-center text-xl text-white'>No Challenges Created Yet...</h1>
</div>
)}
</div>
)}
</div>

);
};
)
}

export default CreatedChallenges;
export default CreatedChallenges
Loading