Skip to content

Commit 1565ef9

Browse files
committed
refactor: modularize types
1 parent ecb2d1f commit 1565ef9

File tree

16 files changed

+81
-372
lines changed

16 files changed

+81
-372
lines changed

app/allprojects/page.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,7 @@ import ProjectList from "@/components/team/ProjectList";
77
import Link from "next/link";
88
import api from "@/api";
99
import axios from "axios";
10-
11-
interface Evaluation {
12-
id: string;
13-
createdAt: string;
14-
updatedAt: string;
15-
projectId: string;
16-
score: number;
17-
}
18-
19-
interface Project {
20-
id: string;
21-
createdAt: string;
22-
updatedAt: string;
23-
name: string;
24-
description: string;
25-
imageId: string;
26-
teamId: string;
27-
evaluations: Evaluation[];
28-
}
10+
import { Project } from "@/types";
2911

3012
const Page = () => {
3113
const [projects, setProjects] = useState<Project[]>([]);

app/allteams/page.tsx

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,7 @@ import SelectedTeamInfo from "@/components/allteams/SelectedTeamInfo";
77
import axios from "axios";
88
import React, { useEffect, useState } from "react";
99
import Link from "next/link";
10-
11-
interface Evaluation {
12-
id: string;
13-
createdAt: string;
14-
updatedAt: string;
15-
projectId: string;
16-
score: number;
17-
}
18-
19-
interface Project {
20-
id: string;
21-
createdAt: string;
22-
updatedAt: string;
23-
name: string;
24-
description: string;
25-
imageId: string;
26-
teamId: string;
27-
evaluations: Evaluation[];
28-
}
29-
30-
interface Member {
31-
id: string;
32-
createdAt: string;
33-
updatedAt: string;
34-
authId: string;
35-
name: string;
36-
role: string;
37-
regNum: string;
38-
phone: string;
39-
college: string;
40-
github: string;
41-
imageId: string;
42-
isLeader: boolean;
43-
teamId: string;
44-
}
45-
46-
interface Team {
47-
id: string;
48-
createdAt: string;
49-
updatedAt: string;
50-
name: string;
51-
imageId: string;
52-
members: Member[];
53-
project: Project;
54-
}
10+
import { Team } from "@/types";
5511

5612
export default function Page() {
5713
const [selectedTeamInfo, setSelectedTeamInfo] = useState<Team | null>(null);

app/allusers/page.tsx

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,7 @@ import React, { useEffect, useState } from "react";
88
import axios from "axios";
99
import Link from "next/link";
1010
import { useAuth } from "@/context/AuthContext";
11-
12-
interface Evaluation {
13-
id: string;
14-
createdAt: string;
15-
updatedAt: string;
16-
projectId: string;
17-
score: number;
18-
}
19-
20-
interface User {
21-
id: string;
22-
createdAt: string;
23-
updatedAt: string;
24-
authId: string;
25-
name: string;
26-
role: string;
27-
regNum: string;
28-
phone: string;
29-
college: string;
30-
github: string;
31-
imageId: string | null;
32-
isLeader: boolean;
33-
teamId: string | null;
34-
evaluations: Evaluation[];
35-
}
11+
import { User } from "@/types";
3612

3713
const Page = () => {
3814
const [users, setUsers] = useState<User[]>([]);

app/createproject/page.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,7 @@ import { useAuth } from "@/context/AuthContext";
99
import Link from "next/link";
1010
import api from "@/api";
1111
import axios from "axios";
12-
13-
interface Evaluation {
14-
id: string;
15-
createdAt: string;
16-
updatedAt: string;
17-
projectId: string;
18-
score: number;
19-
}
20-
21-
interface Project {
22-
id: string;
23-
createdAt: string;
24-
updatedAt: string;
25-
name: string;
26-
description: string;
27-
imageId: string;
28-
teamId: string;
29-
evaluations: Evaluation[];
30-
}
12+
import { Project } from "@/types";
3113

3214
const CreateProjectPage: React.FC = () => {
3315
const [name, setName] = useState("");

app/project/page.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,7 @@ import { useAuth } from "@/context/AuthContext";
1111
import Link from "next/link";
1212
import { useRouter } from "next/navigation";
1313
import React, { useState, useEffect } from "react";
14-
15-
interface Evaluation {
16-
id: string;
17-
createdAt: string;
18-
updatedAt: string;
19-
projectId: string;
20-
score: number;
21-
}
22-
23-
interface Project {
24-
id: string;
25-
createdAt: string;
26-
updatedAt: string;
27-
name: string;
28-
description: string;
29-
imageId: string;
30-
teamId: string;
31-
evaluations: Evaluation[];
32-
}
14+
import { Project } from "@/types";
3315

3416
const Profile = () => {
3517
const { user, loading, getUser } = useAuth();

app/team/[teamId]/page.tsx

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,10 @@ import TeamInformation from "@/components/team/TeamInformation";
1111
import TeamMemberList from "@/components/team/TeamMemberList";
1212
import axios from "axios";
1313
import React, { useEffect, useState } from "react";
14-
15-
interface TeamMember {
16-
id: string;
17-
createdAt: string;
18-
updatedAt: string;
19-
authId: string;
20-
name: string;
21-
role: string;
22-
regNum: string;
23-
phone: string;
24-
college: string;
25-
github: string | null;
26-
imageId: string | null;
27-
isLeader: boolean;
28-
teamId: string;
29-
}
30-
31-
interface Evaluation {
32-
id: string;
33-
createdAt: string;
34-
updatedAt: string;
35-
projectId: string;
36-
score: number;
37-
}
38-
39-
interface Project {
40-
id: string;
41-
createdAt: string;
42-
updatedAt: string;
43-
name: string;
44-
description: string;
45-
imageId: string;
46-
teamId: string;
47-
evaluations: Evaluation[];
48-
}
49-
50-
interface TeamResponse {
51-
id: string;
52-
createdAt: string;
53-
updatedAt: string;
54-
name: string;
55-
imageId: string;
56-
members: TeamMember[];
57-
project: Project;
58-
}
14+
import { Team, User } from "@/types";
5915

6016
const TeamPage = ({ params }: { params: Promise<{ teamId: string }> }) => {
61-
const [response, setResponse] = useState<TeamResponse | null>(null);
17+
const [response, setResponse] = useState<Team | null>(null);
6218
const [loading, setLoading] = useState(true);
6319
const [error, setError] = useState("");
6420

@@ -71,7 +27,7 @@ const TeamPage = ({ params }: { params: Promise<{ teamId: string }> }) => {
7127
return;
7228
}
7329

74-
const res = await api.get<TeamResponse>(`/team/${teamId}`);
30+
const res = await api.get<Team>(`/team/${teamId}`);
7531

7632
if (res.status === 200) {
7733
setResponse(res.data);
@@ -142,7 +98,7 @@ const TeamPage = ({ params }: { params: Promise<{ teamId: string }> }) => {
14298
<TeamInformation
14399
teamName={response.name}
144100
createdOn={new Date(response.createdAt)}
145-
teamLeader={(getLeader() as TeamMember).name || "Unknown Leader"}
101+
teamLeader={(getLeader() as User).name || "Unknown Leader"}
146102
teamId={response.id}
147103
/>
148104
<TeamMemberList

app/team/page.tsx

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,10 @@ import axios from "axios";
1212
import React, { useEffect, useState } from "react";
1313
import DangerButton from "@/components/ui/DangerButton";
1414
import { useRouter } from "next/navigation";
15-
16-
interface TeamMember {
17-
id: string;
18-
createdAt: string;
19-
updatedAt: string;
20-
authId: string;
21-
name: string;
22-
role: string;
23-
regNum: string;
24-
phone: string;
25-
college: string;
26-
github: string | null;
27-
imageId: string | null;
28-
isLeader: boolean;
29-
teamId: string;
30-
}
31-
32-
interface Evaluation {
33-
id: string;
34-
createdAt: string;
35-
updatedAt: string;
36-
projectId: string;
37-
score: number;
38-
}
39-
40-
interface Project {
41-
id: string;
42-
createdAt: string;
43-
updatedAt: string;
44-
name: string;
45-
description: string;
46-
imageId: string;
47-
teamId: string;
48-
evaluations: Evaluation[];
49-
}
50-
51-
interface TeamResponse {
52-
id: string;
53-
createdAt: string;
54-
updatedAt: string;
55-
name: string;
56-
imageId: string;
57-
members: TeamMember[];
58-
project: Project;
59-
}
15+
import { Team, Project } from "@/types";
6016

6117
const TeamPage = () => {
62-
const [response, setResponse] = useState<TeamResponse | null>(null);
18+
const [response, setResponse] = useState<Team | null>(null);
6319
const [loading, setLoading] = useState(true);
6420
const [project, setProject] = useState<Project | null>(null);
6521
const [error, setError] = useState("");
@@ -75,7 +31,7 @@ const TeamPage = () => {
7531
}
7632

7733
try {
78-
const res = await api.get<TeamResponse>(`/team/${user.teamId}`);
34+
const res = await api.get<Team>(`/team/${user.teamId}`);
7935

8036
if (res.status === 200 && res.data) {
8137
setResponse(res.data);

components/allteams/SelectedTeamInfo.tsx

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,7 @@ import DangerButton from "../ui/DangerButton";
66
import Button from "../ui/Button";
77
import Link from "next/link";
88
import DialogBox from "../ui/DialogBox";
9-
10-
interface Evaluation {
11-
id: string;
12-
createdAt: string;
13-
updatedAt: string;
14-
projectId: string;
15-
score: number;
16-
}
17-
18-
interface Project {
19-
id: string;
20-
createdAt: string;
21-
updatedAt: string;
22-
name: string;
23-
description: string;
24-
imageId: string;
25-
teamId: string;
26-
evaluations: Evaluation[];
27-
}
28-
29-
interface Member {
30-
id: string;
31-
createdAt: string;
32-
updatedAt: string;
33-
authId: string;
34-
name: string;
35-
role: string;
36-
regNum: string;
37-
phone: string;
38-
college: string;
39-
github: string;
40-
imageId: string;
41-
isLeader: boolean;
42-
teamId: string;
43-
}
44-
45-
interface Team {
46-
id: string;
47-
createdAt: string;
48-
updatedAt: string;
49-
name: string;
50-
imageId: string;
51-
members: Member[];
52-
project: Project;
53-
}
9+
import { Team } from "@/types";
5410

5511
interface SelectedTeamInfoProps {
5612
selectedTeamInfo: Team;

components/home/CardList.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import React, { useEffect, useState } from "react";
22
import Card from "../ui/Card";
33
import api from "@/api";
4-
5-
interface Project {
6-
id: string;
7-
name: string;
8-
description: string;
9-
createdAt: string;
10-
updatedAt: string;
11-
imageId: string | null;
12-
teamId: string;
13-
}
4+
import { Project } from "@/types";
145

156
const CardList: React.FC = () => {
167
const [projects, setProjects] = useState<Project[]>([]);

components/project/ProjectCard.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1+
import { Evaluation } from "@/types";
12
import { HistoryIcon, ZapIcon } from "lucide-react";
23
import Image from "next/image";
34
import React from "react";
45
import { Calendar } from "react-feather";
56

6-
interface Evaluation {
7-
id: string;
8-
createdAt: string;
9-
updatedAt: string;
10-
projectId: string;
11-
score: number;
12-
}
13-
147
interface ProjectCardProps {
158
createdAt: string;
169
updatedAt: string;

0 commit comments

Comments
 (0)