1+ "use client" ;
2+
3+ import React from "react" ;
14import { useQuery , useMutation } from "@tanstack/react-query" ;
25import { eventsService } from "@/services/events" ;
36import { uploadsService } from "@/services/uploads" ;
47import { EventFormType , CreateEventPayload } from "@/domains/Events" ;
5- import { toast } from "sonner " ;
8+ import DialogSuccess from "@/components/common/DialogGlobal/DialogSuccess " ;
69import { useRouter } from "@/lib/navigation" ;
10+ import { useDialog } from "@/contexts" ;
11+ import DialogError from "@/components/common/DialogGlobal/DialogError" ;
712
813export const useEventById = ( eventId : string ) => {
914 return useQuery ( {
@@ -48,13 +53,32 @@ export const useEventsAdmin = (page: number, limit: number, search?: string) =>
4853
4954export const useCreateEvent = ( t : ( key : string ) => string ) => {
5055 const router = useRouter ( ) ;
56+ const { openDialog, closeDialog } = useDialog ( ) ;
5157
5258 const submitMutation = useMutation ( {
5359 mutationKey : [ "createEvent" ] ,
5460 mutationFn : ( payload : CreateEventPayload ) => eventsService . createEventAdmin ( payload ) ,
5561 onSuccess : ( ) => {
56- toast . success ( t ( "EventForm.create-success" ) ) ;
57- router . push ( "/admin/events" ) ;
62+ openDialog ( {
63+ content : React . createElement ( DialogSuccess , {
64+ title : t ( "EventForm.create-success-title" ) ,
65+ description : t ( "EventForm.create-success-description" ) ,
66+ } ) ,
67+ confirmText : t ( "EventForm.back-to-list" ) ,
68+ onConfirm : ( ) => {
69+ router . push ( "/admin/events" ) ;
70+ closeDialog ( ) ;
71+ } ,
72+ classAction : "sm:justify-center" ,
73+ } ) ;
74+ } ,
75+ onError : ( ) => {
76+ openDialog ( {
77+ title : t ( "EventForm.create-error-title" ) ,
78+ description : t ( "EventForm.create-error-description" ) ,
79+ confirmText : "OK" ,
80+ classAction : "sm:justify-center" ,
81+ } ) ;
5882 } ,
5983 } ) ;
6084
@@ -69,6 +93,19 @@ export const useCreateEvent = (t: (key: string) => string) => {
6993 file_name : filename ,
7094 } ) ;
7195 } ,
96+ onError : ( ) => {
97+ openDialog ( {
98+ content : React . createElement ( DialogError , {
99+ title : t ( "EventForm.upload-error-title" ) ,
100+ description : t ( "EventForm.upload-error-description" ) ,
101+ } ) ,
102+ onConfirm : ( ) => {
103+ closeDialog ( ) ;
104+ } ,
105+ confirmText : "OK" ,
106+ classAction : "sm:justify-center" ,
107+ } ) ;
108+ } ,
72109 } ) ;
73110
74111 const isLoading = createMutation . isPending || submitMutation . isPending ;
0 commit comments