Skip to content
This repository was archived by the owner on Jun 12, 2025. It is now read-only.

Commit 91555a7

Browse files
authored
Merge pull request #14 from EVOGD-Project:dev
Dev
2 parents 1cb8634 + 84ec203 commit 91555a7

8 files changed

Lines changed: 34 additions & 17 deletions

File tree

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const withBundleAnalyzer = nextBundleAnalyzer({
2828

2929
let configExport = nextConfig;
3030

31-
if (process.env.NODE_ENV === 'production') {
31+
if (process.env['NODE_ENV'] === 'production') {
3232
console.log('Loaded production config');
3333
configExport = million.next(nextConfig, { auto: true });
3434
}

src/api/api.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ export const api = {
3939
}
4040
});
4141

42-
if (!res.ok) throw new Error('Failed to fetch classroom');
42+
if (!res.ok) throw new Error('Failed to fetch classroom members');
4343
return res.json();
4444
},
4545

46+
getProfessor: async (id: string): Promise<IUser> => {
47+
const res = await fetch(`${API_URL}/classrooms/${encodeURIComponent(id)}/professor`, {
48+
headers: {
49+
...getAuthHeaders()
50+
}
51+
});
52+
53+
if (!res.ok) throw new Error('Failed to fetch classroom professor');
54+
return res.json();
55+
},
4656

4757
create: async (data: {
4858
name: string;

src/components/general/ClassroomCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function ClassroomCard({ item }: Readonly<{ item: IClassroom }>)
4848
<Flex justify='space-between' align='center'>
4949
<Flex align='center' gap={2}>
5050
<FiUsers />
51-
<Text fontSize='sm'>24 estudiantes</Text>
51+
<Text fontSize='sm'>{item.memberCount} estudiantes</Text>
5252
</Flex>
5353
<Button
5454
size='sm'

src/components/modals/CreateActivityModal.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

33
import { api } from '@/api/api';
4+
import { authAtom } from '@/store/auth';
45
import type { IActivity } from '@/types/IActivity';
56
import {
67
Button,
@@ -21,6 +22,7 @@ import {
2122
VStack,
2223
useToast
2324
} from '@chakra-ui/react';
25+
import { useAtom } from 'jotai';
2426
import { useState } from 'react';
2527
import { FiPlus, FiTrash } from 'react-icons/fi';
2628

@@ -37,6 +39,7 @@ export default function CreateActivityModal({
3739
classroomId,
3840
onActivityCreated
3941
}: Readonly<CreateActivityModalProps>) {
42+
const [auth] = useAtom(authAtom);
4043
const [isLoading, setIsLoading] = useState(false);
4144
const [formData, setFormData] = useState({
4245
title: '',
@@ -71,7 +74,7 @@ export default function CreateActivityModal({
7174
id,
7275
...formData,
7376
classroomId,
74-
owner: 'Ángel',
77+
owner: auth.user?.id ?? '',
7578
createdAt: new Date().toISOString()
7679
};
7780

src/components/modals/CreateClassModal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

33
import { api } from '@/api/api';
4+
import { authAtom } from '@/store/auth';
45
import type { IClassroom } from '@/types/IClassroomCard';
56
import {
67
Button,
@@ -19,6 +20,7 @@ import {
1920
VStack,
2021
useToast
2122
} from '@chakra-ui/react';
23+
import { useAtom } from 'jotai';
2224
import { useEffect, useState } from 'react';
2325

2426
interface CreateClassModalProps {
@@ -34,6 +36,8 @@ export default function CreateClassModal({ isOpen, onClose, onClassroomCreated }
3436
description: '',
3537
thumbnailId: 1
3638
});
39+
const [auth] = useAtom(authAtom);
40+
3741
const toast = useToast();
3842

3943
useEffect(() => {
@@ -67,7 +71,8 @@ export default function CreateClassModal({ isOpen, onClose, onClassroomCreated }
6771
id,
6872
...formData,
6973
code: id.slice(0, 6).toUpperCase(),
70-
owner: 'Ángel'
74+
owner: auth.user?.id ?? '',
75+
memberCount: 1
7176
};
7277

7378
onClassroomCreated?.([newClassroom]);

src/components/screens/ClassScreen.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { api } from '@/api/api';
44
import { CDN_URL } from '@/constants/constants';
55
import type { IActivity } from '@/types/IActivity';
66
import type { IClassroom } from '@/types/IClassroomCard';
7+
import type { IUser } from '@/types/IUser';
78
import {
89
Avatar,
910
Box,
@@ -31,28 +32,30 @@ import { useEffect, useState } from 'react';
3132
import { FiCode, FiFileText, FiPlus, FiUsers } from 'react-icons/fi';
3233
import ActivityCard from '../general/ActivityCard';
3334
import CreateActivityModal from '../modals/CreateActivityModal';
34-
import type { IUser } from '@/types/IUser';
3535

3636
export default function ClassScreen({ id }: Readonly<{ id: string }>) {
3737
const [classroom, setClassroom] = useState<IClassroom | null>(null);
3838
const [isLoading, setIsLoading] = useState(true);
3939
const router = useRouter();
4040
const [classActivities, setClassActivities] = useState<IActivity[]>([]);
4141
const [classMembers, setClassMembers] = useState<IUser[]>([]);
42+
const [professor, setProfessor] = useState<IUser | null>(null);
4243
const [isMembersLoading, setIsMembersLoading] = useState(false);
4344
const { isOpen, onOpen, onClose } = useDisclosure();
4445
const toast = useToast();
4546

4647
useEffect(() => {
4748
const fetchData = async () => {
4849
try {
49-
const [classroomData, activitiesData] = await Promise.all([
50+
const [classroomData, activitiesData, professorData] = await Promise.all([
5051
api.classroom.getById(id),
51-
api.activities.getByClassroom(id)
52+
api.activities.getByClassroom(id),
53+
api.classroom.getProfessor(id)
5254
]);
5355

5456
setClassroom(classroomData);
5557
setClassActivities(activitiesData);
58+
setProfessor(professorData);
5659
} catch (error) {
5760
toast({
5861
title: 'Error',
@@ -76,7 +79,6 @@ export default function ClassScreen({ id }: Readonly<{ id: string }>) {
7679
};
7780

7881
const handleTabChange = async (index: number) => {
79-
// Index 1 is the "Estudiantes" tab
8082
if (index === 1 && classMembers.length === 0) {
8183
setIsMembersLoading(true);
8284
try {
@@ -150,7 +152,7 @@ export default function ClassScreen({ id }: Readonly<{ id: string }>) {
150152
<Flex gap={6} color='gray.400'>
151153
<Flex align='center' gap={2}>
152154
<Icon as={FiUsers} />
153-
<Text>{classMembers.length || '...'} estudiantes</Text>
155+
<Text>{classroom.memberCount} estudiantes</Text>
154156
</Flex>
155157
<Flex align='center' gap={2}>
156158
<Icon as={FiCode} />
@@ -160,12 +162,8 @@ export default function ClassScreen({ id }: Readonly<{ id: string }>) {
160162
</Stack>
161163

162164
<VStack spacing={2} align='center'>
163-
<Avatar
164-
size='xl'
165-
name={classroom.owner}
166-
src='https://avatars.githubusercontent.com/u/57068341?v=4'
167-
/>
168-
<Text color='gray.300'>Ángel</Text>
165+
<Avatar size='xl' name={professor?.username} src={professor?.avatar ?? ''} />
166+
<Text color='gray.300'>{professor?.username}</Text>
169167
</VStack>
170168
</Grid>
171169
</Container>

src/constants/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const CDN_URL = 'https://evogd-cdn.tnfangel.com';
22
export const API_URL =
3-
process.env.NODE_ENV === 'development' ? 'http://localhost:4000' : 'https://evogd-api.tnfangel.com';
3+
process.env['NODE_ENV'] === 'development' ? 'http://localhost:4000' : 'https://evogd-api.tnfangel.com';

src/types/IClassroomCard.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export interface IClassroom {
55
thumbnailId: number;
66
code: string;
77
owner: string;
8+
memberCount: number;
89
}

0 commit comments

Comments
 (0)