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

fix: can't join activity #267

Merged
merged 1 commit into from
Jul 19, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ function PageContent() {
const idActivity = Number(searchParams.get('id') || 1);

const [activity, setActivity] = useState<ActivityWithOccurences>();
const [sports, setSports] = useState<Sport[]>([]);
const [addresses, setAddresses] = useState<Address[]>([]);
const [sports, setSports] = useState<Sport[] | null>(null);
const [addresses, setAddresses] = useState<Address[] | null>(null);
const [usersSet1, setUsersSet1] = useState<User[]>([]);
const [usersSet2, setUsersSet2] = useState<User[]>([]);
const [usersSet3, setUsersSet3] = useState<User[]>([]);
Expand Down Expand Up @@ -170,7 +170,7 @@ function PageContent() {
fetchData();
}, [idActivity]);

if (!activity || sports.length === 0 || addresses.length === 0) {
if (!activity || !sports || !addresses) {
return <LoadingSkeleton />;
}

Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/handlers/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ activities.openapi(applyToActivity, async (c) => {
const { data: activity, error: errorActivity } = await supabase.from('ACTIVITIES').select('*').eq('id', id).single();

if (errorActivity || !activity) return c.json({ error: 'Activity not found' }, 404);
if (new Date(date) < new Date()) return c.json({ error: 'Activity has already ended' }, 400);
if (new Date(`${date}T${activity.start_time}`) < new Date())
return c.json({ error: 'Activity has already ended' }, 400);

const { count } = await supabase
.from('ACTIVITIES_USERS')
Expand Down
59 changes: 34 additions & 25 deletions apps/client/app/ui/components/activities/Occurences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,42 @@ function Occurences({
</div>
<div className="flex justify-center my-4">
<TabsContent value="activity1" className="w-6/12">
<div className="flex text-3xl mb-4 justify-center">
Places restantes : {activity.max_participants - validatedUser1.length}
</div>
<div className="flex justify-center">
{pendingJoin1 && (
<div className="flex justify-center text-lg">
<div>Vous avez déjà fait une demande</div>
{occurences[0] &&
new Date(`${occurences[0]?.date.split('T')[0]}T${activity.start_time}`).getTime() < new Date().getTime() ? (
<div className="flex text-xl mb-4 justify-center">
<div>L'activité de cette journée a déjà commencé</div>
</div>
) : (
<>
<div className="flex text-3xl mb-4 justify-center">
Places restantes : {activity.max_participants - validatedUser1.length}
</div>
)}
{joined1 && (
<div className="flex justify-center text-lg">
<div>Vous êtes inscrit</div>
<div className="flex justify-center">
{pendingJoin1 && (
<div className="flex justify-center text-lg">
<div>Vous avez déjà fait une demande</div>
</div>
)}
{joined1 && (
<div className="flex justify-center text-lg">
<div>Vous êtes inscrit</div>
</div>
)}
{activity.max_participants - validatedUser1.length > 0 &&
occurences[0] &&
pendingJoin1 === undefined &&
joined1 === undefined &&
userId !== 0 && (
<JoinActivity
id_activity={activity.id}
date={occurences[0].date}
user={userData}
setPendingJoin={setPendingJoin1}
/>
)}
</div>
)}
{activity.max_participants - validatedUser1.length > 0 &&
occurences[0] &&
pendingJoin1 === undefined &&
joined1 === undefined &&
userId !== 0 && (
<JoinActivity
id_activity={activity.id}
date={occurences[0].date}
user={userData}
setPendingJoin={setPendingJoin1}
/>
)}
</div>
</>
)}
</TabsContent>
<TabsContent value="activity2">
<div className="flex text-3xl mb-4 justify-center">
Expand Down
Loading