File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import axios from 'axios' ;
2+ import { ENDPOINTS } from '../../utils/URL' ;
3+ import { toast } from 'react-toastify' ;
4+
5+ export const createEvent = eventData => {
6+ return async dispatch => {
7+ try {
8+ const res = await axios . post ( ENDPOINTS . EVENTS , eventData ) ;
9+ if ( res . status === 201 ) {
10+ toast . success ( 'Event created successfully!' ) ;
11+ return { success : true , event : res . data } ;
12+ }
13+ return { success : false , error : 'Unexpected response status' } ;
14+ } catch ( error ) {
15+ if ( error . response ?. status === 500 ) {
16+ toast . error ( 'Error creating event. Please try again.' ) ;
17+ } else if ( error . response ?. status === 404 || error . response ?. status === 403 || error . response ?. status === 400 ) {
18+ toast . error ( 'Permission or Validation Error. Please check your input or access rights' ) ;
19+ } else {
20+ toast . error ( 'Error creating event. Please try again.' ) ;
21+ }
22+ return { success : false , error : error . response ?. data || error . message } ;
23+ }
24+ } ;
25+ } ;
26+
You can’t perform that action at this time.
0 commit comments