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

Commit cc022ff

Browse files
fix: display proper messages and remove uneeded toasts
1 parent 56bcb01 commit cc022ff

File tree

8 files changed

+40
-81
lines changed

8 files changed

+40
-81
lines changed

src/app/(app)/categories/[categoryId]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { fetchThreads } from '@/services/thread/threadService';
1010
import { Hash } from 'lucide-react';
1111
import { fetchCategories } from '@/services/thread/categoryService';
1212
import { useAuthLoading } from '@/hooks';
13+
import RetryAgain from '@/components/OnlyApp/RetryAgain';
1314

1415
export default function CategoryDiscussionsPage() {
1516
const { isAuthLoadingOrRedirecting } = useAuthLoading();
@@ -67,7 +68,7 @@ export default function CategoryDiscussionsPage() {
6768
}
6869

6970
if (error) {
70-
return <ErrorAlert message={error} />;
71+
return <RetryAgainerror={error} handleRetry={() => window.location.reload()} />;
7172
}
7273

7374
return (

src/app/(app)/discussions/new/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export default function NewDiscussionPage() {
139139

140140
if (error && !isSubmitting) {
141141
return (
142-
<RetryAgain
142+
<RetryAgain
143143
error={error}
144144
handleRetry={() => window.location.reload()}
145145
/>

src/app/(app)/profile-settings/page.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { AuthMethod } from '@/utils/api/signup/validateSignupForm';
1919
import Image from 'next/image';
2020
import { useAuth, useAuthRedirect } from '@/hooks';
2121
import { isSuperAdminByRole } from '@/utils/role';
22+
import RetryAgain from '@/components/OnlyApp/RetryAgain';
2223

2324
export default function ProfilePage() {
2425
const router = useRouter();
@@ -54,11 +55,9 @@ export default function ProfilePage() {
5455
});
5556
} else {
5657
setError(result.error?.message || RESPONSE_MESSAGES.profile.DEFAULT);
57-
toast.error(result.error?.message || RESPONSE_MESSAGES.profile.DEFAULT);
5858
}
5959
} catch {
6060
setError(RESPONSE_MESSAGES.profile.DEFAULT);
61-
toast.error(RESPONSE_MESSAGES.profile.DEFAULT);
6261
} finally {
6362
setIsLoadingProfile(false);
6463
}
@@ -85,7 +84,6 @@ export default function ProfilePage() {
8584
const validationErrors = validateProfileForm(formData);
8685
if (Object.keys(validationErrors).length > 0) {
8786
setError(Object.values(validationErrors)[0]);
88-
toast.error(Object.values(validationErrors)[0]);
8987
setIsSubmitting(false);
9088
return;
9189
}
@@ -200,19 +198,13 @@ export default function ProfilePage() {
200198

201199
if (error && !isSubmitting) {
202200
return (
203-
<div className="space-y-4">
204-
<ErrorAlert message={error} />
205-
<Button
206-
onClick={() => {
207-
window.location.reload();
208-
router.refresh();
209-
}}
210-
variant="outline"
211-
color="secondary"
212-
>
213-
تحديث حالة الحساب
214-
</Button>
215-
</div>
201+
<RetryAgain
202+
error={error}
203+
handleRetry={() => {
204+
window.location.reload();
205+
router.refresh();
206+
}}
207+
/>
216208
);
217209
}
218210

src/components/AdminsListing.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { useEffect, useState } from "react";
44
import toast from "react-hot-toast";
55
import LoadingSpinner from "@/components/LoadingSpinner";
6-
import ErrorAlert from "./Form/ErrorAlert";
76
import Button from "./Button";
87
import SearchField from "./OnlyApp/SearchField";
98
import Divider from "./Divider";
@@ -14,6 +13,7 @@ import { Admin } from "@/types";
1413
import { adminService } from "@/services/admin/adminService";
1514
import RESPONSE_MESSAGES from "@/utils/constants/RESPONSE_MESSAGES";
1615
import ItemNotFound from '@/components/OnlyApp/NotFound/ItemNotFound';
16+
import RetryAgain from "./OnlyApp/RetryAgain";
1717

1818
export default function AdminsListing() {
1919
const [isLoading, setIsLoading] = useState(true);
@@ -92,17 +92,10 @@ export default function AdminsListing() {
9292

9393
if (error) {
9494
return (
95-
<div className="space-y-4">
96-
<ErrorAlert message={error} />
97-
<Button
98-
onClick={handleRetry}
99-
variant="outline"
100-
icon={<RefreshCw className="w-4" />}
101-
color="secondary"
102-
>
103-
إعادة المحاولة
104-
</Button>
105-
</div>
95+
<RetryAgain
96+
error={error}
97+
handleRetry={handleRetry}
98+
/>
10699
);
107100
}
108101

src/components/OnlyApp/CategoriesListing.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import Input from "../Input";
99
import { updateCategory, deleteCategory } from "@/services/admin/categoryService";
1010
import { toast } from "react-hot-toast";
1111
import ConfirmModal from "../Modal/ConfirmModal";
12-
import ErrorAlert from "../Form/ErrorAlert";
1312
import Link from 'next/link';
13+
import RetryAgain from "./RetryAgain";
14+
import ItemNotFound from "./NotFound/ItemNotFound";
1415

1516
interface CategoriesListingProps {
1617
allowManagement?: boolean;
@@ -20,6 +21,7 @@ interface CategoriesListingProps {
2021
maxChars?: number;
2122
error?: string;
2223
}
24+
2325
function CategoriesListing({
2426
allowManagement = false,
2527
categories,
@@ -99,9 +101,9 @@ function CategoriesListing({
99101
<LoadingSpinner size="sm" color="primary" />
100102
</div>
101103
) : error ? (
102-
error && <ErrorAlert message={error} />
104+
<RetryAgain error={error} handleRetry={() => window.location.reload()} />
103105
) : categories.length === 0 ? (
104-
<p className="text-sm text-gray-500 px-3 py-2">لا توجد تصنيفات متاحة</p>
106+
<ItemNotFound description="لا توجد تصنيفات متاحة" />
105107
) : (
106108
categories.map((category) => (
107109
<div

src/components/OnlyApp/ThreadListing/ThreadListing.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import ThreadListingHeader from "./ThreadListingHeader";
55
import { useState, useEffect, useCallback } from "react";
66
import toast from "react-hot-toast";
77
import { Thread } from "@/types";
8-
import ErrorAlert from "@/components/Form/ErrorAlert";
9-
import { RefreshCw } from "lucide-react";
108
import LoadingSpinner from "@/components/LoadingSpinner";
11-
import Button from "@/components/Button";
129
import { useInfiniteScroll } from "@/hooks";
1310
import { deleteThread, fetchThreads } from "@/services/thread/threadService";
1411
import { userService } from "@/services/userService";
1512
import { ApiSuccess } from "@/types";
13+
import RetryAgain from "../RetryAgain";
1614

1715
interface ThreadListingProps {
1816
emptyMessage?: string;
@@ -81,7 +79,6 @@ const ThreadListing = ({
8179
} catch (err) {
8280
const errorMessage = err instanceof Error ? err.message : 'حدث خطأ أثناء تحميل المناقشات';
8381
setError(errorMessage);
84-
toast.error(errorMessage);
8582
} finally {
8683
if (isInitialLoad) {
8784
setIsLoading(false);
@@ -135,7 +132,6 @@ const ThreadListing = ({
135132
setPage((prev) => prev + 1);
136133
} catch (err) {
137134
const errorMessage = err instanceof Error ? err.message : 'حدث خطأ أثناء تحميل المزيد من المناقشات';
138-
toast.error(errorMessage);
139135
} finally {
140136
setIsFetchingMore(false);
141137
}
@@ -184,17 +180,10 @@ const ThreadListing = ({
184180

185181
if (error) {
186182
return (
187-
<div className="space-y-4">
188-
<ErrorAlert message={error} />
189-
<Button
190-
onClick={handleRetry}
191-
variant="outline"
192-
icon={<RefreshCw className="w-4" />}
193-
color="secondary"
194-
>
195-
إعادة المحاولة
196-
</Button>
197-
</div>
183+
<RetryAgain
184+
error={error}
185+
handleRetry={handleRetry}
186+
/>
198187
);
199188
}
200189

src/components/OnlyApp/pages/DiscussionPageContent.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import Button from "@/components/Button";
88
import { useState, ChangeEvent, useEffect, useCallback } from "react";
99
import { Thread } from "@/types";
1010
import { toast } from "react-hot-toast";
11-
import ErrorAlert from "@/components/Form/ErrorAlert";
1211
import LoadingSpinner from "@/components/LoadingSpinner";
1312
import CommentListing from "@/components/OnlyApp/Comment/CommentListing";
14-
import { RefreshCw } from "lucide-react";
1513
import RESPONSE_MESSAGES from "@/utils/constants/RESPONSE_MESSAGES";
1614
import ItemNotFound from "../NotFound/ItemNotFound";
1715
import { useAuth, useInfiniteScroll } from "@/hooks";
1816
import { deleteThread, fetchThreadById, fetchThreads } from "@/services/thread/threadService";
1917
import { createComment } from "@/services/thread/commentService";
18+
import { logger } from "@/utils/logger";
19+
import RetryAgain from "../RetryAgain";
2020

2121
function DiscussionPageContent({ discussionId }: { discussionId: string }) {
2222
const router = useRouter();
@@ -52,12 +52,10 @@ function DiscussionPageContent({ discussionId }: { discussionId: string }) {
5252
setThread(threadData);
5353
} else {
5454
setError(threadResult.error.message || 'حدث خطأ أثناء تحميل المناقشة');
55-
toast.error(threadResult.error.message || 'حدث خطأ أثناء تحميل المناقشة');
5655
}
5756
} catch {
5857
const errorMessage = 'حدث خطأ أثناء تحميل المناقشة';
5958
setError(errorMessage);
60-
toast.error(errorMessage);
6159
} finally {
6260
setIsLoading(false);
6361
}
@@ -82,7 +80,7 @@ function DiscussionPageContent({ discussionId }: { discussionId: string }) {
8280
setPage(2);
8381
}
8482
} catch {
85-
toast.error("حدث خطأ أثناء تحميل المناقشات المشابهة");
83+
logger().error("حدث خطأ أثناء تحميل المناقشات المشابهة");
8684
} finally {
8785
setIsLoadingSimilar(false);
8886
}
@@ -107,7 +105,6 @@ function DiscussionPageContent({ discussionId }: { discussionId: string }) {
107105
}
108106
} catch (err) {
109107
console.error("Error loading more threads:", err);
110-
toast.error("حدث خطأ أثناء تحميل المزيد من المناقشات");
111108
} finally {
112109
setIsLoadingSimilar(false);
113110
}
@@ -194,9 +191,7 @@ function DiscussionPageContent({ discussionId }: { discussionId: string }) {
194191
const result = await fetchThreadById(thread.thread_id);
195192
if (result.success) {
196193
setThread(result.data);
197-
} else {
198-
toast.error(result.error.message || RESPONSE_MESSAGES.thread.DEFAULT);
199-
}
194+
}
200195
};
201196

202197
useEffect(() => {
@@ -215,17 +210,10 @@ function DiscussionPageContent({ discussionId }: { discussionId: string }) {
215210

216211
if (error) {
217212
return (
218-
<div className="space-y-4">
219-
<ErrorAlert message={error} />
220-
<Button
221-
onClick={loadThread}
222-
variant="outline"
223-
icon={<RefreshCw className="w-4" />}
224-
color="secondary"
225-
>
226-
إعادة المحاولة
227-
</Button>
228-
</div>
213+
<RetryAgain
214+
error={error}
215+
handleRetry={loadThread}
216+
/>
229217
);
230218
}
231219

src/components/StudentsListing.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import { useEffect, useState } from "react";
44
import toast from "react-hot-toast";
55
import LoadingSpinner from "@/components/LoadingSpinner";
6-
import ErrorAlert from "./Form/ErrorAlert";
76
import Button from "./Button";
87
import SearchField from "./OnlyApp/SearchField";
98
import Select from "./Select";
109
import Divider from "./Divider";
1110
import UsersBadge from "./OnlyApp/Badge/UsersBadge";
1211
import UserCardItem from "./OnlyApp/UserCardItem";
13-
import { ArrowUpDown, RefreshCw } from "lucide-react";
12+
import { ArrowUpDown } from "lucide-react";
1413
import { Student, ApprovalStatus } from "@/types";
1514
import { fetchStudents, approveStudent, rejectStudent } from "@/services/admin/studentService";
15+
import RetryAgain from "./OnlyApp/RetryAgain";
1616

1717
const StudentsListing = () => {
1818
const [isLoading, setIsLoading] = useState(true);
@@ -46,7 +46,6 @@ const StudentsListing = () => {
4646

4747
const errorMessage = err instanceof Error ? err.message : 'حدث خطأ أثناء تحميل الطلاب';
4848
setError(`${errorMessage}. يرجى المحاولة مرة أخرى.`);
49-
toast.error(errorMessage);
5049
} finally {
5150
setIsLoading(false);
5251
setIsFiltering(false);
@@ -188,15 +187,10 @@ const StudentsListing = () => {
188187

189188
{error ? (
190189
<div className="space-y-4">
191-
<ErrorAlert message={error} />
192-
<Button
193-
onClick={handleRetry}
194-
variant="outline"
195-
icon={<RefreshCw className="w-4" />}
196-
color="secondary"
197-
>
198-
إعادة المحاولة
199-
</Button>
190+
<RetryAgain
191+
error={error}
192+
handleRetry={handleRetry}
193+
/>
200194
</div>
201195
) : isLoading || isFiltering ? (
202196
<div className="min-h-[200px] flex items-center justify-center">

0 commit comments

Comments
 (0)