Skip to content

Commit 108a5c4

Browse files
committed
feat: create detail event page, my-events page
1 parent cc996fb commit 108a5c4

File tree

7 files changed

+82
-79
lines changed

7 files changed

+82
-79
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { UserEventDetailPage } from "@/features/events/pages";
2+
3+
export default async function MyEventDetailPage() {
4+
return <UserEventDetailPage />;
5+
}

src/features/events/components/EventFormRegistration.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const EventFormRegistration = ({ data }: { data: EventType }) => {
2828
defaultValues: {
2929
name: "",
3030
email: "",
31-
// phone_number: "",
3231
},
3332
});
3433

src/features/events/hooks/useRegistEvent.tsx

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,21 @@
1-
// import { useState } from "react";
2-
// import { useTranslations } from "next-intl";
31
import { toast } from "sonner";
42
import { eventsService } from "@/services/events";
5-
// import { EventType } from "@/domains/Events";
63
import { useMutation, useQueryClient } from "@tanstack/react-query";
74
import { useDialog } from "@/contexts";
85
import EventCheckStatusModal from "../components/EventCheckStatusModal";
6+
import { useRouter } from "@/lib/navigation";
97

108
export const useRegistEvent = () => {
11-
// const t = useTranslations("EventsPage");
9+
const router = useRouter();
1210
const { openDialog, closeDialog } = useDialog();
1311
const queryClient = useQueryClient();
14-
// const [isLoading, setIsLoading] = useState<boolean>(false);
15-
// const [nameImage, setNameImage] = useState<string | null>("");
16-
// const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false);
1712

18-
// const registEvent = async (formData: RegistrationForm) => {
19-
// setIsLoading(true);
20-
21-
// try {
22-
// const { image_proof_payment, ...registDetails } = formData;
23-
24-
// interface NewPayload extends RegistrationForm {
25-
// event_id: number;
26-
// }
27-
28-
// let registPayload: NewPayload = {
29-
// event_id: 0,
30-
// image_proof_payment: "",
31-
// ...registDetails,
32-
// };
33-
34-
// if (!nameImage) {
35-
// console.log("image proof payment", image_proof_payment);
36-
// const {
37-
// data: { file_name: uploadedImageFileName },
38-
// } = await uploadsService.uploadImage(image_proof_payment as File, "event");
39-
40-
// setNameImage(uploadedImageFileName);
41-
// registPayload = {
42-
// ...registDetails,
43-
// image_proof_payment: uploadedImageFileName as string,
44-
// event_id: data?.id as number,
45-
// };
46-
// } else {
47-
// registPayload = {
48-
// ...registDetails,
49-
// image_proof_payment: nameImage as string,
50-
// event_id: data?.id as number,
51-
// };
52-
// }
53-
54-
// const res = await eventsService.registerEvent(registPayload);
55-
56-
// toast.success(`${t("EventRegistration.success.title")}`, {
57-
// description: `${t("EventRegistration.success.description")} ${res.data.order_no}`,
58-
// });
59-
// setNameImage("");
60-
// setIsLoading(false);
61-
// } catch (error) {
62-
// // console.log(error);
63-
// toast.error(t("EventRegistration.failure.title"), {
64-
// description: error instanceof Error ? error.message : t("EventRegistration.failure.description"),
65-
// });
66-
// setIsLoading(false);
67-
// }
68-
// };
6913
const { mutate: registerEvent, isPending: isPendingRegister } = useMutation({
7014
mutationKey: ["registerEvent"],
7115
mutationFn: ({ event_id }: { event_id: number }) => eventsService.registerEvent(event_id),
7216
onSuccess: (data) => {
7317
toast.success(data?.message);
18+
router.push(`/my-events/${data.data.order_no}`);
7419
},
7520
onError: (error) => {
7621
toast.error(error?.message);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use client";
2+
3+
import { useParams, useRouter } from "next/navigation";
4+
import { ArrowLeft } from "lucide-react";
5+
import { Button } from "@/components/ui/Button";
6+
import { EventDetailModal } from "../components/EventDetailModal";
7+
import { useGetPaymentDetail } from "../hooks/useEvent";
8+
import Loader from "@/components/common/Loader";
9+
10+
const UserEventDetailPage = () => {
11+
const router = useRouter();
12+
const params = useParams();
13+
14+
const transactionId = params?.transactionId as string;
15+
const { data: paymentData, isLoading } = useGetPaymentDetail(transactionId);
16+
17+
if (isLoading) {
18+
return (
19+
<div className="flex min-h-screen items-center justify-center">
20+
<Loader />
21+
</div>
22+
);
23+
}
24+
25+
if (!paymentData?.data) {
26+
return (
27+
<div className="container mx-auto max-w-3xl px-4 py-8">
28+
<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+
</p>
33+
<Button onClick={() => router.push("/my-events")}>
34+
<ArrowLeft className="mr-2 h-4 w-4" />
35+
Back to My Events
36+
</Button>
37+
</div>
38+
</div>
39+
);
40+
}
41+
const eventData = paymentData.data;
42+
return (
43+
<div className="container mx-auto max-w-4xl px-4 py-8">
44+
<div className="mb-6">
45+
<Button variant="outline" onClick={() => router.push("/my-events")}>
46+
<ArrowLeft className="mr-2 h-4 w-4" />
47+
Back to My Events
48+
</Button>
49+
</div>
50+
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>
53+
<EventDetailModal event={eventData} />
54+
</div>
55+
</div>
56+
);
57+
};
58+
59+
export default UserEventDetailPage;

src/features/events/pages/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export { default as AdminEventUpdatePage } from "./AdminEventUpdatePage";
44
export { default as PublicEventListPage } from "./PublicEventListPage";
55
export { default as PublicEventDetailPage } from "./PublicEventDetailPage";
66
export { default as UserEventPage } from "./UserEventPage";
7+
export { default as UserEventDetailPage } from "./UserEventDetailPage";

src/features/events/types.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { EventDetailForUser, UserDetail } from "./types/userEvent";
2+
13
type EventTypes = "Workshop" | "TechTalk" | "dll";
24
type EventStatus = "open" | "soon" | "closed";
35

@@ -27,22 +29,15 @@ export type EventInfoType = {
2729
};
2830

2931
export type PaymentDetailResponse = {
32+
id?: number;
33+
event_id?: number;
34+
user_id?: string;
3035
order_no: string;
3136
transaction_no: string;
3237
payment_date: string;
3338
status: string;
34-
event_detail: {
35-
title: string;
36-
date: Date;
37-
type: string;
38-
location: string;
39-
duration: string;
40-
price: number;
41-
session_type: string;
42-
};
43-
user_detail: {
44-
fullname: string;
45-
email: string;
46-
phone_number: string;
47-
};
39+
payment_url: string;
40+
created_at: string;
41+
event_detail: EventDetailForUser;
42+
user_detail: UserDetail;
4843
};

src/features/events/types/userEvent.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,14 @@ export interface EventDetailForUser {
6060
}
6161

6262
export interface UserEventResponse {
63-
id: number;
64-
order_no: string;
65-
event_id: number;
66-
user_id: string;
67-
image_proof_payment: string;
63+
id?: number;
64+
order_no?: string;
65+
event_id?: number;
66+
user_id?: string;
6867
payment_url: string;
6968
transaction_no: string;
7069
payment_date: string | null;
71-
status: "PENDING" | "SUCCESS" | "FAILED" | "EXPIRED";
70+
status: string;
7271
created_at: string;
7372
event_detail: EventDetailForUser;
7473
user_detail: UserDetail;

0 commit comments

Comments
 (0)