react-admin-import-csv customize success notification - javascript

In my react-admin application I am using react-admin-import-csv to import CSV files. When the import is with errors I do something like:
notify(`importError`, { type: 'error', messageArgs: { error: resultMessage }, multiLine: true })
throw new Error(errors);
This works fine and I get an error notification as expected.
But when the import is successful and I do something like:
notify(`importSuccess`, { type: 'success', messageArgs: { success: success }, multiLine: true, autoHideDuration:3000});
return;
The result is that my success notification is hidden right away by react-admin-import-csv default notification.
The only workaround that I found is throwing a "success error" instead of a simple return. It shows the success notification successfully but with an error in the console:
Is there a cleaner way to achieve this?

I do not recommand throwing a "success" error because when you do so you don't let react-admin-import-csv finish its work properly.
The best I could do is to internationalize the success message like the following:
en: {
csv: {
dialogImport: {
alertClose: "result.importSuccessLib",
title: "Importation of users",
},
dialogCommon: {
subtitle: "Importation of %{count} element(s) from %{fileName}",
}
}
}
Then I have:
en: {
result: {
importSuccessLib: 'File imported successfully'
}
}
I hope it can help someone.

Related

Braintree Node.js cannot get transaction.sale to work

I am building a reactjs app that among others will include Braintree Dropin UI integration. So far, I have managed to make the UI show up and send a payload to the back end. However, I cannot get the gateway.transaction.sale() part to work. Here is my code's relevant parts:
When the user clicks the pay button, this is fired:
instance.requestPaymentMethod().then(function (payload) {
console.log(payload);
completePayment(amount, payload.nonce, userId, sessionId).then((result) => {
console.log( result );
});
}).catch(function (err) {
alert(err.message);
});
And this is the code that should handle the transaction:
return gateway.transaction.sale({
amount: amount,
paymentMethodNonce: nonce,
customFields: {
session_id: sessionId,
user_id: userId
},
options: {
submitForSettlement: true
}
}).then(function (result) {
if (result.success) {
console.log('Transaction ID: ' + result.transaction.id);
} else {
console.error(result.message);
}
}).catch(( error ) => {
alert(error);
});
Every time this function is fired, I get this error from catch:
TypeError: can't assign to property "success" on :not an object
Can anyone point me in the right direction?
Please note that I am not very familiar with react, node etc so my code may not be the best thing around...
Check these points:
make sure you assigned your environment to the sandbox (braintree.Environment.Sandbox);
double check (merchantId, publicKey, and privateKey).

How to Configure view locals in action as machine

I am rockie in sails and kick start with action 2(action as machine). I am stuck how to configure view locals in actions 2.
For instance, in standalone action I can configure and add layout to view by the below snippet:
res.view('./pages/coffee/Boss/sell', { layout: 'layouts/layout-boss' })
My question is How can we do the same thing with action as machine(action2) ?
exits: {
success: {
responseType: "view",
viewTemplatePath: './pages/coffee/Boss/listDrink'
//Here I want to configure locals of view
//Specifically, I want to configure layout of the view
},
notFound: {
description: 'The data of drinks are empty',
respondType: 'notFound'
}
},
Looks like you can set any specific parameters in the exits.success call, like the layout or any ejs local variables you might need in the template:
fn: async function (inputs, exits) {
return exits.success({layout: 'layouts/layout-boss', ejsLocalVariable: 'value'});
}
and the exit declaration would just be
exits: {
success: {
responseType: "view",
viewTemplatePath: './pages/coffee/Boss/listDrink'
},
notFound: {
description: 'The data of drinks are empty',
respondType: 'notFound'
}
},
In SailsJS, to apply a layout to a template in an actions2 object you can do the following:
Declare your success exit as usual:
exits: {
success: {
responseType: 'view',
viewTemplatePath: 'pages/hello',
},
},
When returning from your method , add the layout to any any other values that you are passing to your template.
return exits.success({name1:value1, name2:value2, layout: 'layouts/backoffice'});
As far as I understand the layout is another local, and locals are explained here:
https://sailsjs.com/documentation/concepts/views/locals

Internal Server Error when using Meteor.loginWithFacebook

Using the service-configuration and accounts-facebook packages, after clicking on the facebook button and logging in from the Facebook authorization window that pops up, we're getting an Internal server error when performing a Meteor.loginWithFacebook.
This was tested on a very basic example, what is causing this error?
Template.login.events({
'click .btn-facebook': function (ev) {
Meteor.loginWithFacebook({}, function(error) {
if(error) {
throw new Meteor.Error('Facebook login failed: ', error);
}
})
}
});
/server/lib/config/social.js
Meteor.startup(function() {
ServiceConfiguration.configurations.update(
{ service: "facebook" },
{ $set: {
appId: "xxx",
secret: "xxx"
}
},
{ upsert: true }
);
})
Error (server side)
Exception while invoking method 'login' undefined
Error (client side)
Error: Internal server error [500]
at _.extend._livedata_result (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4964:23)
at onMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3725:12)
at http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2717:11
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:11)
at _.extend._launchConnection.self.socket.onmessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2716:11)
at REventTarget.dispatchEvent (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:156:22)
at SockJS._dispatchMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1141:10)
at SockJS._didMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1199:18)
at WebSocket.SockJS.websocket.that.ws.onmessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1346:17)
I had the same issue, and solved it like this :
After checking that you have configured your schema as described here :
Schema.User = new SimpleSchema({
_id: {
type: String
}
...
});
You should add the second part into an Accounts.onCreateUser like this, into server/accounts.js for example :
Accounts.onCreateUser(function (options, user) {
if (user.services.facebook) {
user.emails = [{
address: user.services.facebook.email,
verified: true
}];
}
return user;
});
It will append the facebook email to the newly created account. The error should disapear.

Parse.com Failed with: ReferenceError

I am trying to run the following parse background job in Cloud Code
Parse.Cloud.job("sendAlert", function(sendAlert) {
Parse.Push.send({
data: {
"content-available": 1,
}
}, {
success: function() {
status.success("Push Worked!!!");
},
error: function(error) {
status.error("Uh oh, something went wrong.");
}
});
});
with the intended result of, when it is run, a "transparent" (not seen by users, but seen by the app) push being sent to users.
When I run it, I get the error
Jobs:
sendAlert
E2015-02-20T19:17:22.637Z] v17: Ran job sendAlert with:
Input: {}
Failed with: ReferenceError: status is not defined
at Object.Parse.Push.send.error (main.js:12:5)
at Parse.js:2:7940
at f (Parse.js:2:6852)
at Parse.js:2:6344
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:661)
at c.extend.reject (Parse.js:2:6297)
at Parse.js:2:6956
at f (Parse.js:2:6852)
at Parse.js:2:7386
in the log. What am I doing wrong? Thanks, and appreciate it - total Parse novice here.
If you look for the word status in your code, you will see that you haven't declared it anywhere. A variable named status can't just come out of nowhere, so that's why you're getting a ReferenceError.
According to the documentation, the second parameter passed into the Parse.Cloud.job() callback is a JobStatus object with error and success methods, so it seems that's what you're trying to use:
// declare it here ---------v
Parse.Cloud.job("sendAlert", function(sendAlert, status) {
Parse.Push.send({
data: {
"content-available": 1,
}
}, {
success: function() {
status.success("Push Worked!!!");
},
error: function(error) {
status.error("Uh oh, something went wrong.");
}
});
});

Posting picture to facebook Graph API using angularjs

I try to get the image upload to facebook working... Unfortunately, the facebook graph API always returns the following error:
{ error: Objectcode: 324, message: "(#324) Requires upload file", type: "OAuthException" }
It seems that the picture data is not transfered correctly. The facebook docs tell me to use a multipart/form-data upload. (See here > Publishing)
I am using angular-easyfb as a wrapper for the faceebook sdk. What's the easiest way to get this thing working? My current code is:
var sharePhoto = function() {
ezfb.api("/me/photos",
"POST",
{
"source": content,
"message": "This is a test Photo"
},
function (response) {
console.log("shared", response);
if (response && !response.error) {
/* handle the result */
}
});
};
ezfb.getLoginStatus(function(response) {
if(response.status === 'connected') {
console.log("already conntected", response);
sharePhoto();
} else {
ezfb.login(function(response) {
// Do something with response.
console.log("FB",response);
sharePhoto();
}, {scope: 'public_profile,email,user_photos,publish_actions'});
}
});
The console-log is:
already conntected {status: "connected", authResponse: Object}
shared {error: {code: 324, message: "(#324) Requires upload file", type: "OAuthException"}}
My questions are:
Whats the expected format of my variable content? How do I need to
encode it?
Do I have to manipulate the request Headers of the request? How?
Thanks a lot for your help!
Edit: Console-Log added

Categories