function* ChangePasswordToken(action: any): SagaIterator { try { const { token, password } = action.payload yield put(Actions.LoadingPage.onLoadingOn()) const data = yield call(ChangePasswordTokenFrost, token, password) yield put(Actions.ChangePasswordToken.onChangePasswordTokenSuccess(data)) yield put(Actions.LoadingPage.onLoadingFull()) yield put(Actions.SignOut.onSignOut({ redirectLogin: false })) yield put(Actions.SetTokenLogin.onSetTokenLogin(data)) yield call(delay, 1000) browserHistory.push('/dashboard') toast.success('Your password has been updated!', { className: 'toast', autoClose: 2500, }) } catch (e) { yield put(Actions.LoadingPage.onLoadingFull()) yield put(Actions.ChangePasswordToken.onChangePasswordTokenError(e)) yield call(delay, 300) yield put(Actions.ChangePasswordToken.onChangePasswordTokenClearError()) toast.error(e, { className: 'toast', autoClose: 2500, }) } }
function* VerifiedAccount(action: any): SagaIterator { const toastId = toast.info('Verifying account...', { className: 'toast', }) try { const { token, password } = action.payload yield put(Actions.LoadingPage.onLoadingOn()) const data = yield call(GetApiTokensFrost, token, password) yield put(Actions.VerifiedAccount.onVerifiedAccountSuccess()) yield put(Actions.LoadingPage.onLoadingFull()) yield put(Actions.SignOut.onSignOut({ redirectLogin: false })) yield put(Actions.SetTokenLogin.onSetTokenLogin(data)) yield call(delay, 1000) browserHistory.push('/dashboard') toast.success('Your account has been verified!', { className: 'toast', autoClose: 2500, }) } catch (e) { yield put(Actions.LoadingPage.onLoadingFull()) yield put(Actions.VerifiedAccount.onVerifiedAccountError(e)) yield call(delay, 300) yield put(Actions.VerifiedAccount.onVerifiedAccountClearError()) if (e.includes('Email already verified')) { browserHistory.push('/dashboard') toast.info(e, { className: 'toast', autoClose: 2500, }) } else if (e.includes('Expired token')) { const message = 'This link has expired. Please login and request a new validation email.' toast.update(toastId, { render: message, type: toast.TYPE.ERROR, className: 'toast', autoClose: false, }) } else toast.update(toastId, { render: e, type: toast.TYPE.ERROR, autoClose: false, className: 'toast', }) } }
function* GetApiTokens(action: any): SagaIterator { try { yield put(Actions.LoadingPage.onLoadingOn()) yield put(Actions.NotificationBar.onResetNotificationBar()) const { token } = action.payload const { apiToken } = yield call(CreateApiTokenFrost, token) yield put(Actions.ApiTokens.onCreateApiTokenSuccess(apiToken)) yield put( Actions.NotificationBar.onShowNotificationBar({ type: 'success', message: 'API TOKEN SUCCESSFULLY CREATED', }) ) yield put(Actions.LoadingPage.onLoadingFull()) yield call(delay, 2000) yield put(Actions.NotificationBar.onHideNotificationBar()) yield call(delay, 2000) yield put(Actions.NotificationBar.onResetNotificationBar()) } catch (e) { yield put(Actions.ApiTokens.onCreateApiTokenError(e)) yield put(Actions.LoadingPage.onLoadingFull()) const errorMessage = typeof e === 'object' ? e.message : e toast.error(errorMessage, { className: 'toast', autoClose: 2500, }) } }
.then(response => { if (action.meta && action.meta.successMessage) { toast.success(action.meta.successMessage); } else if (response && response.action && response.action.payload && response.action.payload.headers) { const headers = response.action.payload.headers; let alert: string = null; let alertParams: string = null; Object.entries(headers).forEach(([k, v]: [string, string]) => { if (k.endsWith('app-alert')) { alert = v; } else if (k.endsWith('app-params')) { alertParams = v; } }); if (alert) { const alertParam = alertParams; toast.success(translate(alert, { param: alertParam })); } } return Promise.resolve(response); })
export const reverseGeoCode = async (lat:number, lng:number) => { const API_URL = `https://maps.googleapis.com/maps/api/geocode/json?language=ko&latlng=${lat},${lng}&key=${MAPS_KEY}`; const {status, data} = await axois(API_URL); if(status===200 && !data.error_message){ const {results} = data; const firstPlace = results[0]; const address = firstPlace.formatted_address; return address; } else { toast.error(data.error_message || "Some Unknown Error Happened", {hideProgressBar:true}); return false; } }
function* DeleteApiToken(action: any): SagaIterator { try { const { token, apiToken } = action.payload yield put(Actions.LoadingPage.onLoadingOn()) yield call(DeleteApiTokenFrost, token, apiToken) yield put(Actions.DeleteApiToken.onDeleteApiTokenSuccess(apiToken)) yield put(Actions.LoadingPage.onLoadingFull()) yield put(Actions.Modal.onHideModal()) yield call(delay, 300) } catch (e) { yield put(Actions.LoadingPage.onLoadingFull()) yield put(Actions.DeleteApiToken.onDeleteApiTokenError(e)) const errorMessage = typeof e === 'object' ? e.message : e toast.error(errorMessage, { className: 'toast', autoClose: 2500, }) } }
function* SignIn(action: any): SagaIterator { try { const { email, password } = action.payload yield put(Actions.LoadingPage.onLoadingOn()) const { token } = yield call(signInFrost, { email, password }) yield put(Actions.SignIn.onSignInSuccess({ token, ...{ profile: { email } } })) yield put(Actions.Profile.onProfile({ token })) yield put(Actions.LoadingPage.onLoadingFull()) yield call(delay, 300) browserHistory.push('/dashboard') } catch (e) { yield put(Actions.LoadingPage.onLoadingFull()) yield put(Actions.SignIn.onSignInError(e)) yield call(delay, 300) yield put(Actions.SignIn.onSignInClearError()) toast.error(e, { className: 'toast', autoClose: 2500, }) } }
export const geoCode = async(address:string) => { const API_URL = `https://maps.googleapis.com/maps/api/geocode/json?language=ko&address=${address},+Mountain+View,+CA&key=${MAPS_KEY}`; const {status, data} = await axois(API_URL); if(status===200 && !data.error_message){ console.log(data); const {results} = data; const firstPlace = results[0]; const { formatted_address, geometry:{ location:{lat, lng} } } = firstPlace; if(formatted_address.search("Mountain View")>=0 || formatted_address.search("캘리포니아 마운틴뷰")>=0){ return false; } return {lat, lng, formatted_address} } else { toast.error(data.error_message || "Some Unknown Error Happened", {hideProgressBar:true}); return false; } };
graphQLErrors.map(({ message }) => { toast.error(`Unexpected error: ${message}`); });
.catch(error => { if (action.meta && action.meta.errorMessage) { toast.error(action.meta.errorMessage); } else if (error && error.response) { const response = error.response; const data = response.data; if (!(response.status === 401 && (error.message === '' || (data && data.path && data.path.includes('/api/account'))))) { let i; switch (response.status) { // connection refused, server not reachable case 0: addErrorAlert('Server not reachable', 'error.server.not.reachable'); break; case 400: const headers = Object.entries(response.headers); let errorHeader = null; let entityKey = null; headers.forEach(([k, v]: [string, string]) => { if (k.endsWith('app-error')) { errorHeader = v; } else if (k.endsWith('app-params')) { entityKey = v; } }); if (errorHeader) { const entityName = translate('global.menu.entities.' + entityKey); addErrorAlert(errorHeader, errorHeader, { entityName }); } else if (data !== '' && data.fieldErrors) { const fieldErrors = data.fieldErrors; for (i = 0; i < fieldErrors.length; i++) { const fieldError = fieldErrors[i]; if (['Min', 'Max', 'DecimalMin', 'DecimalMax'].includes(fieldError.message)) { fieldError.message = 'Size'; } // convert 'something[14].other[4].id' to 'something[].other[].id' so translations can be written to it const convertedField = fieldError.field.replace(/\[\d*\]/g, '[]'); const fieldName = translate(`demoGatewayApp.${fieldError.objectName}.${convertedField}`); addErrorAlert(`Error on field "${fieldName}"`, `error.${fieldError.message}`, { fieldName }); } } else if (data !== '' && data.message) { addErrorAlert(data.message, data.message, data.params); } else { addErrorAlert(data); } break; case 404: addErrorAlert('Not found', 'error.url.not.found'); break; default: if (data !== '' && data.message) { addErrorAlert(data.message); } else { addErrorAlert(data); } } } } else if (error && error.message) { toast.error(error.message); } else { toast.error('Unknown error!'); } return Promise.reject(error); });