|
1 | | -import { useState } from "react"; |
2 | | -import { useTranslations } from "next-intl"; |
| 1 | +// import { useState } from "react"; |
| 2 | +// import { useTranslations } from "next-intl"; |
3 | 3 | import { toast } from "sonner"; |
4 | | -import { uploadsService } from "@/services/uploads"; |
5 | 4 | import { eventsService } from "@/services/events"; |
6 | | -import { EventType, RegistrationForm } from "@/domains/Events"; |
| 5 | +// import { EventType } from "@/domains/Events"; |
7 | 6 | import { useMutation, useQueryClient } from "@tanstack/react-query"; |
8 | 7 | import { useDialog } from "@/contexts"; |
9 | 8 | import EventCheckStatusModal from "../components/EventCheckStatusModal"; |
10 | 9 |
|
11 | | -export const useRegistEvent = (data?: EventType) => { |
12 | | - const t = useTranslations("EventsPage"); |
| 10 | +export const useRegistEvent = () => { |
| 11 | + // const t = useTranslations("EventsPage"); |
13 | 12 | const { openDialog, closeDialog } = useDialog(); |
14 | 13 | const queryClient = useQueryClient(); |
15 | | - const [isLoading, setIsLoading] = useState<boolean>(false); |
16 | | - const [nameImage, setNameImage] = useState<string | null>(""); |
| 14 | + // const [isLoading, setIsLoading] = useState<boolean>(false); |
| 15 | + // const [nameImage, setNameImage] = useState<string | null>(""); |
17 | 16 | // const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false); |
18 | 17 |
|
19 | | - const registEvent = async (formData: RegistrationForm) => { |
20 | | - setIsLoading(true); |
| 18 | + // const registEvent = async (formData: RegistrationForm) => { |
| 19 | + // setIsLoading(true); |
21 | 20 |
|
22 | | - try { |
23 | | - const { image_proof_payment, ...registDetails } = formData; |
| 21 | + // try { |
| 22 | + // const { image_proof_payment, ...registDetails } = formData; |
24 | 23 |
|
25 | | - interface NewPayload extends RegistrationForm { |
26 | | - event_id: number; |
27 | | - } |
| 24 | + // interface NewPayload extends RegistrationForm { |
| 25 | + // event_id: number; |
| 26 | + // } |
28 | 27 |
|
29 | | - let registPayload: NewPayload = { |
30 | | - event_id: 0, |
31 | | - image_proof_payment: "", |
32 | | - ...registDetails, |
33 | | - }; |
| 28 | + // let registPayload: NewPayload = { |
| 29 | + // event_id: 0, |
| 30 | + // image_proof_payment: "", |
| 31 | + // ...registDetails, |
| 32 | + // }; |
34 | 33 |
|
35 | | - if (!nameImage) { |
36 | | - console.log("image proof payment", image_proof_payment); |
37 | | - const { |
38 | | - data: { file_name: uploadedImageFileName }, |
39 | | - } = await uploadsService.uploadImage(image_proof_payment as File, "event"); |
| 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"); |
40 | 39 |
|
41 | | - setNameImage(uploadedImageFileName); |
42 | | - registPayload = { |
43 | | - ...registDetails, |
44 | | - image_proof_payment: uploadedImageFileName as string, |
45 | | - event_id: data?.id as number, |
46 | | - }; |
47 | | - } else { |
48 | | - registPayload = { |
49 | | - ...registDetails, |
50 | | - image_proof_payment: nameImage as string, |
51 | | - event_id: data?.id as number, |
52 | | - }; |
53 | | - } |
| 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 | + // } |
54 | 53 |
|
55 | | - const res = await eventsService.registerEvent(registPayload); |
| 54 | + // const res = await eventsService.registerEvent(registPayload); |
56 | 55 |
|
57 | | - toast.success(`${t("EventRegistration.success.title")}`, { |
58 | | - description: `${t("EventRegistration.success.description")} ${res.data.order_no}`, |
59 | | - }); |
60 | | - setNameImage(""); |
61 | | - setIsLoading(false); |
62 | | - } catch (error) { |
63 | | - // console.log(error); |
64 | | - toast.error(t("EventRegistration.failure.title"), { |
65 | | - description: error instanceof Error ? error.message : t("EventRegistration.failure.description"), |
66 | | - }); |
67 | | - setIsLoading(false); |
68 | | - } |
69 | | - }; |
| 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 | + // }; |
| 69 | + const { mutate: registerEvent, isPending: isPendingRegister } = useMutation({ |
| 70 | + mutationKey: ["registerEvent"], |
| 71 | + mutationFn: ({ event_id }: { event_id: number }) => eventsService.registerEvent(event_id), |
| 72 | + onSuccess: (data) => { |
| 73 | + toast.success(data?.message); |
| 74 | + }, |
| 75 | + onError: (error) => { |
| 76 | + toast.error(error?.message); |
| 77 | + }, |
| 78 | + }); |
70 | 79 |
|
71 | 80 | const { mutate: checkPaymentStatus, isPending: isCheckingPayment } = useMutation({ |
72 | 81 | mutationKey: ["checkPaymentStatus"], |
@@ -108,5 +117,5 @@ export const useRegistEvent = (data?: EventType) => { |
108 | 117 | }, |
109 | 118 | }); |
110 | 119 |
|
111 | | - return { registEvent, isLoading, checkPaymentStatus, isCheckingPayment }; |
| 120 | + return { checkPaymentStatus, isCheckingPayment, registerEvent, isPendingRegister }; |
112 | 121 | }; |
0 commit comments