@@ -46,54 +46,33 @@ export default function ResetPage() {
4646 } ) ;
4747
4848 const startHackathonMutation = useMutation ( {
49- mutationFn : async ( {
50- startDate,
51- endDate,
52- } : {
53- startDate : string ;
54- endDate : string ;
55- } ) => {
56- const toastObj = toast . loading ( "Scheduling hackathon start..." ) ;
57- try {
58- const response = await client . mutations . StartHackathon ( {
59- startDate,
60- endDate,
61- } ) ;
62-
63- console . log ( "StartHackathon response:" , response ) ;
49+ mutationFn : async ( input : Schema [ "StartHackathon" ] [ "args" ] ) => {
50+ console . log ( input ) ;
6451
65- if ( response . errors && response . errors . length > 0 ) {
66- toast . dismiss ( toastObj ) ;
67- const error = response . errors [ 0 ] ;
68- console . error ( "GraphQL errors:" , response . errors ) ;
69- const errorMsg =
70- error . message || JSON . stringify ( error ) || "Unknown GraphQL error" ;
71- toast . error ( `Error: ${ errorMsg } ` ) ;
72- throw new Error ( errorMsg ) ;
52+ try {
53+ const existingHackathon = await client . models . Hackathon . list ( ) ;
54+ if ( existingHackathon . data && existingHackathon . data . length > 0 ) {
55+ toast . error ( "A hackathon already exists. Please reset first." ) ;
56+ throw new Error ( "Hackathon already exists" ) ;
7357 }
7458
75- if ( response . data ?. statusCode === 200 ) {
76- toast . dismiss ( toastObj ) ;
77- toast . success ( "Hackathon start scheduled successfully" ) ;
78- await hackathonData . refetch ( ) ;
79- return response . data ;
80- } else {
59+ const toastObj = toast . loading ( "Scheduling hackathon start..." ) ;
60+ const { data : statusCode , errors } =
61+ await client . mutations . StartHackathon ( {
62+ ... input ,
63+ } ) ;
64+ if ( errors ) {
8165 toast . dismiss ( toastObj ) ;
82- const respData = response . data
83- ? JSON . stringify ( response . data )
84- : "No data" ;
85- console . error ( "Unexpected response:" , response ) ;
86- toast . error ( `Unexpected response: ${ respData } ` ) ;
87- throw new Error ( `Unexpected response: ${ respData } ` ) ;
66+ toast . error ( "Error scheduling hackathon start" ) ;
67+ console . log ( errors ) ;
8868 }
89- } catch ( error ) {
69+ void statusCode ;
9070 toast . dismiss ( toastObj ) ;
91- console . error ( "Error scheduling hackathon start:" , error ) ;
92- const errorMessage =
93- error instanceof Error
94- ? error . message
95- : JSON . stringify ( error ) || "Unknown error" ;
96- toast . error ( `Failed to schedule: ${ errorMessage } ` ) ;
71+ toast . success ( "Hackathon start scheduled successfully" ) ;
72+ await hackathonData . refetch ( ) ;
73+ return ;
74+ } catch ( error ) {
75+ console . error ( "Error scheduling hackathon start" , error ) ;
9776 throw error ;
9877 }
9978 } ,
0 commit comments