function* deleteSample(action) { try { yield put({ type: types.DELETE_PENDING }) yield call(Delete, `sample/${action.idRow}/`) yield put({ type: types.DELETE_FULFILLED }) toast.success('Eliminado correctamente', { position : toast.POSITION.TOP_CENTER, hideProgressBar: true }) } catch (e) { switch (e.type) { case 'cancel': yield put({ type: types.DELETE_CANCEL }) break default: const message = e.response.data.message || '' yield put({ type: types.DELETE_FAILURE, error: e.message }) toast.error(`Error al eliminar: ${message}`, { position : toast.POSITION.TOP_CENTER, hideProgressBar: true }) break } } }
function* createSample(action) { try { yield put({ type: types.POST_PENDING }) const payload = yield call(Post, 'sample/', action.dataForm) yield put({ type: types.POST_FULFILLED, id : payload.item.id }) toast.success('Guardado correctamente', { position : toast.POSITION.TOP_CENTER, hideProgressBar: true }) } catch (e) { switch (e.type) { case 'cancel': yield put({ type: types.POST_CANCEL }) break default: const { message = '', errors } = e.response.data let currentMessage = message if(errors) currentMessage = errors.message toast.error(`Error al crear: ${currentMessage}`, { position : toast.POSITION.TOP_CENTER, hideProgressBar: true }) yield put({ type: types.POST_FAILURE, error: currentMessage }) break } } }
(err, res) => { if (err) { toast.error( <div> {this.props.application.imageName} deleting error: {"" + err} <br /> {err.response && err.response.data && err.response.data.json && err.response.data.json.message ? err.response.data.json.message : ""} </div> ); } else { toast.success( <div> {this.props.application.name} has been deleted{" "} <i className={"fa fa-trash"} /> </div> ); } // hide the popup this.setState({ modalIsOpen: !this.state.modalIsOpen, deleteBtnDisabled: false }); }
function* updateSample(action) { try { yield put({ type: types.PUT_PENDING }) yield call(Put, `sample/${action.dataForm.id}`, action.dataForm) yield put({ type: types.PUT_FULFILLED }) toast.success('Actualizado correctamente', { position : toast.POSITION.TOP_CENTER, hideProgressBar: true }) } catch (e) { switch (e.type) { case 'cancel': yield put({ type: types.PUT_CANCEL }) break default: const { message = '', errors } = e.response.data let currentMessage = message if(errors) currentMessage = errors.message toast.error(`Error al actualizar: ${currentMessage}`, { position : toast.POSITION.TOP_CENTER, hideProgressBar: true }) yield put({ type: types.PUT_FAILURE, error: currentMessage }) break } } }
function(err, body) { if (err) { toast.error( <div> Application creation error: <br /> {err} <br /> {body} </div> ); } else { toast.success( <div> <i className="fa fa-plus-circle" /> Application{" "} <strong> {self.state.applicationName}:{self.state.applicationVersion} </strong>{" "} has been created </div> ); } // hide the modal self.props.toggle(); self.setState({ creatingApplication: false }); }
onLogin = () => { const { id, pw } = this.state; if (id.length < 1) return toast.error('아이디를 입력해주세요'); if (pw.length < 1) return toast.error('비밀번호를 입력해주세요'); login(this.state) .then((res) => { toast.success('로그인완료'); }) .catch((err) => { const errMsg = ['다시 시도해주세요', '없는 아이디입니다', '비밀번호를 확인해주세요']; toast.error(errMsg[err.response.data.code]); }); };
onLogin = () => { const { id, pw, name } = this.state; if (id.length < 1) return toast.error('아이디를 입력해주세요'); if (pw.length < 1) return toast.error('비밀번호를 입력해주세요'); if (name.length < 1) return toast.error('이름을 입력해주세요'); change(this.state) .then((res) => { toast.success('수정 완료'); }) .catch((err) => { const errMsg = ['다시 시도해주세요', '없는 아이디입니다']; toast.error(errMsg[err.response.data.code]); }); };
axios.get('https://joes-autos.herokuapp.com/api/vehicles').then(res => { toast.success('See all vehicles') console.log(res.data); this.setState({ vehiclesToDisplay: res.data }) }).catch(error => toast.error('No vehicles found, check back later'))
axios.post('https://joes-autos.herokuapp.com/api/vehicles', newCar).then(res => { toast.success('Vehicle Added!') console.log(res.data.vehicles) this.setState({ vehiclesToDisplay: res.data.vehicles }) }).catch(error => toast.error("Vehicle could not be added"))
axios.interceptors.response.use(null, error => { const expectedError = error.response && error.response.status >= 400 && error.response.status < 500; if (!expectedError) { logger.log(error); toast.error("an unexpected error occurrred"); } return Promise.reject(error); })
export const deleteContent = id => async (dispatch) => { try { const response = await client({ method: "DELETE", path: `/api/contents/${id}`, headers: { Accept: "application/json", "Content-Type": "application/json", "X-Requested-With": "XMLHttpRequest" } }); if (response.status.code === 200) { dispatch(fetchContents()); toast.success("Content deleted Successfully!"); } else { console.log(response.status.code); } } catch (err) { toast.error("Content could not be deleted!"); console.log(err); } };
export const addContent = (newContent, callback) => async (dispatch) => { console.log(newContent); try { const response = await client({ method: 'POST', path: `/api/contents`, entity: newContent, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' } }); if (response.status.code === 201) { dispatch(fetchSlugsWithTitles()); typeof callback === 'function' && callback(); toast.success("Content saved Successfully!"); } else { console.log(response.status.code); } } catch (error) { console.log(error); if (error.entity) { // on duplicate slug if (error.entity.err.name.includes("Unique")) { toast.error("Duplicate Title.!\nContent Could Not Be Saved!"); } else { toast.error( "Content Could Not Be Saved! " + error.entity.err ); } } else { toast.error("Content could not be Saved!"); } } };
(err, res) => { if (err) { toast.error( <div> Instance <strong>{self.props.instance.technicalName}</strong>{" "} starting error: {"" + err} </div> ); toast.error( <div style={{ width: "30rem" }}> {renderHTML(err.response.data)} </div> ); } else { toast.success( <div> <i className="fa fa-play-circle" /> Instance{" "} <strong>{self.props.instance.technicalName}</strong> has been started </div> ); } }
componentDidMount() { /*Checks if geolocation exists*/ if (!navigator.geolocation) { const error = 'Geolocation is not supported by your browser' toast.error(`Ups! ${error}, sorry!`) return; } /*Geolocation API*/ logic.userPosition() .then((position) => { const { coords: { latitude, longitude } } = position this.setState({ lat: latitude, lng: longitude }) }) .then(() => { const { lng, lat } = this.state logic.listNearbyEvents(lng, lat) .then(events => { this.setState({ eventsDraw: events }) _events = events //save a copy for manipulation }) .catch(err => toast.error(`Ups! Something happens: ${err}`)) }) .catch((err) => { toast.error(`Ups! Something happens: ${err}`) }) /* Import Event Types and set the display boolean for the filter buttons */ logic.listEventTypes() .then(eventTypes => { this.setState({ eventTypes }) let eventTypesDisplay = {} Object.keys(eventTypes).map((key) => { return eventTypesDisplay[key] = true }) this.setState({ eventTypesDisplay }) }) .catch(err => toast.error(`Ups! Something happens: ${err}`)) //setTimeout added for allow to load the css before the tiles of map (prevents gray tiles) setTimeout(() => this.setState({ readyToRender: true }), 170); }
handleRaffleWinnerConfirmation() { const raffleWinnerIDs = this.state.selection if (raffleWinnerIDs.length <= 0) { toast.error('No winners selected.') return } confirmRaffleWinners(raffleWinnerIDs) .then(res => { this.setState({ selection: [], selectAll: false }) this.props.clearRaffleWinners() toast.success(res.data) }) .catch(err => { toast.error(err.response.data) console.error(err.response.data) }) }
}).catch( err => toast.error('Could not retrieve vehicles!'))
}).catch(err=> toast.error('Could not retrieve by year'))
axios.get(`https://joes-autos.herokuapp.com/api/vehicles?year=${year}`).then(res => { toast.success('Got vehicles by year') this.setState({ vehiclesToDisplay: res.data }) }).catch(err=> toast.error('Could not retrieve by year'))
}).catch(err => toast.error("Couldn't search for buyers"))
axios.get(`https://joes-autos.herokuapp.com/api/buyers?name=${searchLetters}`).then(res => { toast.success('Searched buyers by name!') this.setState({ buyersToDisplay:res.data }) }).catch(err => toast.error("Couldn't search for buyers"))
axios.delete('https://joes-autos.herokuapp.com/api/buyers/${id}').then(res => { toast.success('They bought a car!') this.setState({ buyersToDisplay:res.data.buyers }) })
axios.post("https://joes-autos.herokuapp.com/api/buyers", newBuyer).then(res => { toast.success('Added Buyer') this.setState({ buyersToDisplay: res.data.buyers }) }).catch(err => toast.error('Could not retrieve buyers'))
const showToast = message => { toast.error(message, { position: toast.POSITION.TOP_RIGHT }) }
static error = ({ text }, id) => { BackendToast.dismissIfActive(id) return toast.error(text, { autoClose: false }) }
success: msg => toast.success(msg),
axios.get('https://joes-autos.herokuapp.com/api/buyers').then(res => { toast.success('Successfully got Buyers!') this.setState({ buyersToDisplay: res.data }) }).catch( err => toast.error('Could not retrieve Buyers. :('))
}).catch( err => toast.error('Could not retrieve Buyers. :('))
}).catch(err => toast.error('Could not retrieve buyers'))
error: msg => toast.error(msg, { autoClose: false })
static success = ({ text }, id) => { BackendToast.dismissIfActive(id) return toast.success(text) }