Skip to content

Commit 8e05041

Browse files
Copilotmorizkay
andauthored
fix: address PR review comments - i18n, routing, error handling, type safety
Agent-Logs-Url: https://github.com/hammercode-dev/hammercode-web/sessions/3d9c5db3-7c5a-4dde-8b64-6d63b5002423 Co-authored-by: morizkay <26421928+morizkay@users.noreply.github.com>
1 parent fbe3ee7 commit 8e05041

6 files changed

Lines changed: 51 additions & 18 deletions

File tree

src/features/events/components/ColumnsUserEventList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ function ViewEventButton({ event }: { event: UserEventResponse }) {
5252
const router = useRouter();
5353

5454
const handleViewDetails = () => {
55-
router.push(`/my-events/${event.order_no}`);
55+
if (event.order_no) {
56+
router.push(`/my-events/${event.order_no}`);
57+
}
5658
};
5759

5860
return (

src/features/events/hooks/useRegistEvent.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
44
import { useDialog } from "@/contexts";
55
import EventCheckStatusModal from "../components/EventCheckStatusModal";
66
import { useRouter } from "@/lib/navigation";
7+
import { useTranslations } from "next-intl";
78

89
export const useRegistEvent = () => {
10+
const t = useTranslations("EventsPage.Hook");
911
const router = useRouter();
1012
const { openDialog, closeDialog } = useDialog();
1113
const queryClient = useQueryClient();
@@ -15,10 +17,16 @@ export const useRegistEvent = () => {
1517
mutationFn: ({ event_id }: { event_id: number }) => eventsService.registerEvent(event_id),
1618
onSuccess: (data) => {
1719
toast.success(data?.message);
18-
router.push(`/my-events/${data.data.order_no}`);
20+
const orderNo = data?.data?.order_no;
21+
if (orderNo) {
22+
router.push(`/my-events/${orderNo}`);
23+
} else {
24+
router.push("/my-events");
25+
}
1926
},
2027
onError: (error) => {
21-
toast.error(error?.message);
28+
const message = error?.message || t("register-error");
29+
toast.error(message);
2230
},
2331
});
2432

src/features/events/pages/UserEventDetailPage.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
"use client";
22

3-
import { useParams, useRouter } from "next/navigation";
3+
import { useParams } from "next/navigation";
4+
import { useRouter } from "@/lib/navigation";
45
import { ArrowLeft } from "lucide-react";
6+
import { useTranslations } from "next-intl";
57
import { Button } from "@/components/ui/Button";
68
import { EventDetailModal } from "../components/EventDetailModal";
79
import { useGetPaymentDetail } from "../hooks/useEvent";
810
import Loader from "@/components/common/Loader";
911

1012
const UserEventDetailPage = () => {
13+
const t = useTranslations("MyEventDetailPage");
1114
const router = useRouter();
1215
const params = useParams();
1316

14-
const transactionId = params?.transactionId as string;
15-
const { data: paymentData, isLoading } = useGetPaymentDetail(transactionId);
17+
const order_no = params?.transactionId as string;
18+
const { data: paymentData, isLoading, isError } = useGetPaymentDetail(order_no);
1619

1720
if (isLoading) {
1821
return (
@@ -22,17 +25,17 @@ const UserEventDetailPage = () => {
2225
);
2326
}
2427

25-
if (!paymentData?.data) {
28+
if (isError || !paymentData?.data) {
2629
return (
2730
<div className="container mx-auto max-w-3xl px-4 py-8">
2831
<div className="text-center">
29-
<h1 className="mb-4 text-2xl font-bold">Transaction Not Found</h1>
30-
<p className="mb-8 text-gray-600 dark:text-gray-400">
31-
The transaction you are looking for does not exist or has been removed.
32+
<h1 className="mb-4 text-2xl font-bold">{t("not-found-title")}</h1>
33+
<p className="mb-8 text-gray-600">
34+
{t("not-found-description")}
3235
</p>
3336
<Button onClick={() => router.push("/my-events")}>
3437
<ArrowLeft className="mr-2 h-4 w-4" />
35-
Back to My Events
38+
{t("back-to-my-events")}
3639
</Button>
3740
</div>
3841
</div>
@@ -44,12 +47,12 @@ const UserEventDetailPage = () => {
4447
<div className="mb-6">
4548
<Button variant="outline" onClick={() => router.push("/my-events")}>
4649
<ArrowLeft className="mr-2 h-4 w-4" />
47-
Back to My Events
50+
{t("back-to-my-events")}
4851
</Button>
4952
</div>
5053

51-
<div className="rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-800 dark:bg-gray-900">
52-
<h1 className="mb-6 text-2xl font-bold">Event Details</h1>
54+
<div className="rounded-lg border border-gray-200 bg-white p-6">
55+
<h1 className="mb-6 text-2xl font-bold">{t("event-details")}</h1>
5356
<EventDetailModal event={eventData} />
5457
</div>
5558
</div>

src/features/events/types/userEvent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ export interface EventDetailForUser {
6060
}
6161

6262
export interface UserEventResponse {
63-
id?: number;
64-
order_no?: string;
65-
event_id?: number;
66-
user_id?: string;
63+
id: number;
64+
order_no: string;
65+
event_id: number;
66+
user_id: string;
6767
payment_url: string;
6868
transaction_no: string;
6969
payment_date: string | null;

src/locales/en.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
"EventsPage": {
148148
"title": "Events",
149149
"description": "Join the fun events and have an unforgettable experience!",
150+
"Hook": {
151+
"register-error": "Failed to register event"
152+
},
150153
"EventDetail": {
151154
"organized-by": "Organized By:",
152155
"desc-title": "Description",
@@ -229,6 +232,13 @@
229232
"title": "My Events",
230233
"description": "List of registered events"
231234
},
235+
"MyEventDetailPage": {
236+
"not-found-title": "Transaction Not Found",
237+
"not-found-description": "The transaction you are looking for does not exist or has been removed.",
238+
"back-to-my-events": "Back to My Events",
239+
"event-details": "Event Details",
240+
"load-error": "Failed to load transaction details"
241+
},
232242
"MyBlogPage": {
233243
"title": "My Blogs",
234244
"description": "List of post and blog article",

src/locales/id.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
"EventsPage": {
148148
"title": "Acara",
149149
"description": "Ayo ikuti berbagai acara seru dan dapatkan pengalaman tak terlupakan!",
150+
"Hook": {
151+
"register-error": "Gagal mendaftar event"
152+
},
150153
"EventDetail": {
151154
"organized-by": "Diselenggarakan Oleh:",
152155
"desc-title": "Deskripsi",
@@ -229,6 +232,13 @@
229232
"title": "Event Saya",
230233
"description": "Daftar event yang sudah diregistrasi"
231234
},
235+
"MyEventDetailPage": {
236+
"not-found-title": "Transaksi Tidak Ditemukan",
237+
"not-found-description": "Transaksi yang Anda cari tidak ada atau telah dihapus.",
238+
"back-to-my-events": "Kembali ke Event Saya",
239+
"event-details": "Detail Event",
240+
"load-error": "Gagal memuat detail transaksi"
241+
},
232242
"MyBlogPage": {
233243
"title": "Blog Saya",
234244
"description": "Daftar postingan dan artikel blog",

0 commit comments

Comments
 (0)