How to show flash notifications after page redirect - meteor

Given the following code:
Posts.update(currentPostId, {$set: postProperties}, function(error) {
if (error) {
// display the error to the user
alert(error.reason);
} else {
Router.go('postPage', {_id: currentPostId});
}
});
How does one take the following code and add showing a flash message telling the user that the item has been updated on top of being directed to the new message?

Have you looked at the various flash message packages?
naxio:flash in particular supports iron:router.

Related

How to show body of a bad request response in angular 4?

To provide login error message I added a message in the constructor of Bad Request Response which shows in the postman while testing an web api.
Like this: return BadRequest("Error Message");
Now I want to get that message and display in a component in the client side. But I don't know how to retrieve that. I am trying like this:
signIn() {
this.authService.login(this.loginCredentials).subscribe(result=>{
if(result){
let returnUrl=this.route.snapshot.queryParamMap.get('returnUrl');
this.router.navigate([returnUrl||'/']);
}
},
(err) => {
this.loginMessage=true;
console.log(err.body);
this.invalidLogin=true;
});
}
Finally got it. It will be
console.log(err.body);

Redirect user on login

I've been trying to figure this out for hours but everything I try fails. I'm trying login a user and on success get route the user to the correct url based on the user's role. In the example below, I login successfully, and the user is successfully identified however when I try to redirect or push.history it doesn't let me. There are no errors, it just stays on the login url.
I'm using:
React router 4, Meteorjs
handleSubmit(event) {
event.preventDefault();
Meteor.loginWithPassword(email, password, (error, result) => {
if (error) {
this.setState({ loginError: 'Incorrect username or password.' });
} else {
if (!!Roles.userIsInRole(Meteor.userId(), 'isAdmin')) {
<Redirect to="/admin/dashboard" push />
}
}
});
}
A react component is something that is rendered, it's not just a function that you can call from anywhere.
Use history.push('/admin/dashboard")
If the router is being passed into your component as a prop you might also find yourself doing
this.props.history.push('/admin/dashboard")

"Object is not a function" in a Meteor route

I just created two routes that work just fine, but I'm getting an odd error in the console that I would like to fix.
Exception in callback of async function: TypeError: object is not a function
at OnBeforeActions.loginRequired (http://localhost:3000/client/router/config.js?8cea1a53d7ab131377c2c4f91d534123cba79b70:12:20)
This error shows up every time I visit the same page.
This is my config.js file:
Router.configure({
layoutTemplate: "uMain"
});
var OnBeforeActions = {
loginRequired: function (pause) {
"use strict";
if (!Meteor.userId()) {
this.render("uLogin");
return pause();
} else {
this.next();
}
}
};
Router.onBeforeAction(OnBeforeActions.loginRequired, {
except: ["uLogin"]
});
The idea is to redirected all user who are not logged in to "uLogin".
It works (or I haven't found any bugs so far).
What am I doing wrong?
You can see the line where you have the error in developers console when you click on link http://localhost:3000/client/router/config.js?8cea1a53d7ab131377c2c4f91d534123cba79b70:12:20 in your console.
Your problem is that new Iron Router does not use pause() anymore. Remove pause from your onBeforeAction.
Developers console is your good friend. Learn how to use it.

How to reset X-editable fields after save event

This is a follow-up question to this answer in https://stackoverflow.com/a/15121394/2247553 on which I cannot comment yet due to the reward system at StackOverflow.
My question is, after the collection update has been requested with Meteor, how do I reset the editable back to its original state in case the server rejects the update?
Template.editableTable.rendered = function() {
$('#myParentTable').editable({
selector: '.editable-click'
});
$('a.editable-click').unbind('save').on('save', function(e, params) {
MyCollection.update({_id: 'myid'}, {$set: {key: 'val'}}, function(error, docs) {
if (error) {
// how do I reset X-editable here?
}
});
});
};
According to the FAQ, if the server side validation fails, you should return a non 200 status.
I know this doesn't exactly answer your question. I'm trying to do the same thing, return a success:false status. It does act like an API in a way, so sending back a 200 suggests that everything worked ok, so it updates the value. The request is to update the value, 200 status is for success.
Hope that makes sense. Please comment if you would like clarification.
My code for the error param of the editable function is below...
error: function(response, newValue) {
var json = false;
try {
json = JSON.parse(response.responseText);
} catch (e) {
json = false;
}
//Bootstrap message is my own thing.
bootstrapMessage.init('#search_results');
if(response.status === 500) {
bootstrapMessage.show_message('There is a server error. Please contact our supoprt team.', 'danger');
} else {
if(json){
bootstrapMessage.show_message(json.message, 'danger');
}else{
bootstrapMessage.show_message('Problem saving your change. Please refresh the page and try again or contact our support team', 'danger');
}
}
}

Unregister push notifications phonegap push plugin

I have a problem with push notifications unregister. I am able to register the device and get the token, also sending notifications too, but I would like to add the unregister feature too. Here is the code y wrote for it:
var unsubscribeNotification = function unsubscribeNotification() {
try {
pushNotification.unregister(
function(e) {
//unRegister Success!!!
alert('unRegister Success');
},
function(e) {
//unRegister Failed!!!
alert('unRegister Failed');
});
}
catch(err) {
//Handle errors here
alert(err.message);
}
}
I also put a button to run the unsubscribeNotification() function when you click it. After a few seconds the application stops, no error, no messages, nothing!
I am using a Galaxy S3, I think it has Android 4.1
Thanks for the help!

Resources