Skip to content

Commit 4d1ec04

Browse files
committed
chore(qol): add loading and error component to maintain modularity
1 parent 2c39820 commit 4d1ec04

File tree

9 files changed

+31
-45
lines changed

9 files changed

+31
-45
lines changed

app/allusers/page.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Link from "next/link";
1010
import { useAuth } from "@/context/AuthContext";
1111
import { User } from "@/types";
1212
import Error from "@/components/ui/Error";
13+
import Loading from "@/components/ui/Loading";
1314

1415
const Page = () => {
1516
const [users, setUsers] = useState<User[]>([]);
@@ -96,11 +97,7 @@ const Page = () => {
9697
};
9798

9899
if (isLoading) {
99-
return (
100-
<div className="flex justify-center items-center h-screen bg-[#09090b]">
101-
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-400" />
102-
</div>
103-
);
100+
return <Loading />;
104101
}
105102

106103
if (error) {

app/createTeam/page.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import { useRouter } from "next/navigation";
99
import api from "@/api";
1010
import { useAuth } from "@/context/AuthContext";
1111
import axios from "axios";
12+
import Loading from "@/components/ui/Loading";
1213

1314
const CreateTeamPage: React.FC = () => {
1415
const [name, setName] = useState("");
1516
const [imageId, setImageID] = useState("");
1617
const [error, setError] = useState("");
1718

1819
const router = useRouter();
19-
const { user, getUser } = useAuth();
20+
const { user, loading, getUser } = useAuth();
2021

2122
useEffect(() => {
2223
if (user?.teamId) {
@@ -53,6 +54,10 @@ const CreateTeamPage: React.FC = () => {
5354
}
5455
};
5556

57+
if (loading) {
58+
return <Loading />;
59+
}
60+
5661
return (
5762
<div className="bg-[#09090b] w-full h-screen flex flex-col text-white">
5863
<header className="w-full bg-[#121212] flex items-center justify-between px-6 py-3 border-b border-gray-700">

app/createproject/page.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Link from "next/link";
1010
import api from "@/api";
1111
import axios from "axios";
1212
import { Project } from "@/types";
13+
import Loading from "@/components/ui/Loading";
1314

1415
const CreateProjectPage: React.FC = () => {
1516
const [name, setName] = useState("");
@@ -105,11 +106,7 @@ const CreateProjectPage: React.FC = () => {
105106
};
106107

107108
if (isLoading) {
108-
return (
109-
<div className="bg-[#09090b] w-full h-screen flex items-center justify-center">
110-
<p className="text-white">Loading...</p>
111-
</div>
112-
);
109+
return <Loading />;
113110
}
114111

115112
return (

app/project/page.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Link from "next/link";
1212
import { useRouter } from "next/navigation";
1313
import React, { useState, useEffect } from "react";
1414
import { Project } from "@/types";
15+
import Loading from "@/components/ui/Loading";
1516

1617
const Profile = () => {
1718
const { user, loading, getUser } = useAuth();
@@ -55,11 +56,7 @@ const Profile = () => {
5556
};
5657

5758
if (loading) {
58-
return (
59-
<div className="flex justify-center items-center h-screen bg-[#121212]">
60-
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-400" />
61-
</div>
62-
);
59+
return <Loading />;
6360
}
6461

6562
return (

app/promoteUser/[userId]/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Button from "@/components/ui/Button";
55
import DangerButton from "@/components/ui/DangerButton";
66
import DialogBox from "@/components/ui/DialogBox";
77
import InputField from "@/components/ui/InputField";
8+
import Loading from "@/components/ui/Loading";
89
import { useAuth } from "@/context/AuthContext";
910
import axios from "axios";
1011
import Link from "next/link";
@@ -97,6 +98,10 @@ const DynamicPromoteUser = ({
9798
}
9899
};
99100

101+
if (loading) {
102+
return <Loading />;
103+
}
104+
100105
return (
101106
<div className="bg-[#09090b] w-full h-screen flex flex-col">
102107
<header className="w-full bg-[#121212] text-white flex items-center justify-between px-6 py-3 border-b border-gray-700">

app/team/page.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import React, { useEffect, useState } from "react";
1313
import DangerButton from "@/components/ui/DangerButton";
1414
import { useRouter } from "next/navigation";
1515
import { Team, Project } from "@/types";
16+
import Loading from "@/components/ui/Loading";
1617

1718
const TeamPage = () => {
1819
const [response, setResponse] = useState<Team | null>(null);
@@ -115,11 +116,7 @@ const TeamPage = () => {
115116
};
116117

117118
if (loading) {
118-
return (
119-
<div className="flex justify-center items-center h-screen bg-[#09090b]">
120-
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-300" />
121-
</div>
122-
);
119+
return <Loading />;
123120
}
124121

125122
if (error || !response) {

app/updateProject/page.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import api from "@/api";
99
import axios from "axios";
1010
import DangerButton from "@/components/ui/DangerButton";
1111
import DialogBox from "@/components/ui/DialogBox";
12+
import Loading from "@/components/ui/Loading";
13+
import Error from "@/components/ui/Error";
1214

1315
const UpdateProject = () => {
1416
const [projectId, setProjectId] = useState("");
@@ -64,18 +66,12 @@ const UpdateProject = () => {
6466
}, [router, user?.teamId]);
6567

6668
if (loading || !user) {
67-
return (
68-
<div className="flex justify-center items-center h-screen bg-[#121212]">
69-
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-400" />
70-
</div>
71-
);
69+
return <Loading />;
7270
}
7371

7472
if (user && !user.isLeader) {
7573
return (
76-
<div className="flex justify-center items-center h-screen bg-[#09090b] text-red-400">
77-
You are not allowed to do this action.
78-
</div>
74+
<Error error="You are not allowed to update projects. Only team leaders can update projects." />
7975
);
8076
}
8177

app/user/[id]/page.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import DialogBox from "@/components/ui/DialogBox";
1414
import { useRouter } from "next/navigation";
1515
import { User } from "@/types";
1616
import { useAuth } from "@/context/AuthContext";
17+
import Loading from "@/components/ui/Loading";
18+
import Error from "@/components/ui/Error";
1719

1820
type ProfileProps = {
1921
params: Promise<{
@@ -142,18 +144,12 @@ const Profile = ({ params }: ProfileProps) => {
142144
}, [visitedUser]);
143145

144146
if (loading) {
145-
return (
146-
<div className="flex justify-center items-center h-screen bg-[#121212]">
147-
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-400" />
148-
</div>
149-
);
147+
return <Loading />;
150148
}
151149

152150
if (!visitedUser) {
153151
return (
154-
<div className="flex justify-center items-center h-screen bg-[#121212] text-white text-lg font-semibold">
155-
User not found
156-
</div>
152+
<Error error="User not found. Please check the URL and try again." />
157153
);
158154
}
159155

app/user/page.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
import api from "@/api";
55
import DangerButton from "@/components/ui/DangerButton";
6+
import Error from "@/components/ui/Error";
67
import FooterSection from "@/components/ui/FooterSection";
8+
import Loading from "@/components/ui/Loading";
79
import UserCard from "@/components/user/UserCard";
810
import UserInformation from "@/components/user/UserInformation";
911
import { useAuth } from "@/context/AuthContext";
@@ -33,18 +35,12 @@ const Profile = () => {
3335
}, [user]);
3436

3537
if (loading) {
36-
return (
37-
<div className="flex justify-center items-center h-screen bg-[#121212]">
38-
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-400" />
39-
</div>
40-
);
38+
return <Loading />;
4139
}
4240

4341
if (!user) {
4442
return (
45-
<div className="flex justify-center items-center h-screen bg-[#121212] text-white">
46-
User not found
47-
</div>
43+
<Error error="You are not logged in. Please log in to view your profile." />
4844
);
4945
}
5046

0 commit comments

Comments
 (0)