How to cancel react-final-form validation after form submission? - redux-form

When submitting the form that updates existing values I dispatch a redux action creator.
<Form onSubmit={onFormSubmit} destroyOnUnregister>
{({dirty, invalid, handleSubmit}) =>
...
<Button
onClick={handleSubmit}
disabled={invalid || !dirty}>
Save
</Button>
}
When form values are received on the backend, the server responds with the updated data, which react-final-form interprets as a submission error (the invalid prop from react-final-form stays true, even when the form was submitted successfully). How can I prevent such behaviour?
I'm updating just one field at a time, i.e. name, when submitting the form, but the server response contains the whole slice of data to update redux store). The validation error I'm getting is:
"submitErrors": {
"data": {
"id": 1,
"name": "Company 1",
"country": "USA",
"city": "New York",
...
...
"createdAt": "2020-08-06",
"updatedAt": "2020-08-06",
"deletedAt": null
},
"type": "company/UPDATE_INFO_SUCCESS"
}
Please, notice that the company/UPDATE_INFO_SUCCESS action was triggered.
I did see the following part in the docs about the form submission
3. Asynchronous with a Promise
Returns a Promise<?Object> that resolves with no value on success or resolves with an Object of submission errors on failure. The reason it resolves with errors is to leave rejection for when there is a server or communications error.
but such behaviour is highly undesirable.

Related

Create inactive account

I want to synchronize with another system, accounts, and if the entity is inactive in that system, I want to create the account with inactive status. something very simple like:
{
"accountnumber": "InactiveAcct",
"name": "Account that should be created as inactive",
"description": "demo",
"statecode": 1,
"statuscode": 2
}
I'm doing a POST request but as a reply I get:
{
"error": {
"code": "0x80048408",
"message": "2 is not a valid status code for state code AccountState.Active on account with Id e2d0f844-313e-eb11-a813-000d3a795762."
}
}
Unfortunately you cannot create (POST) an inactive record, you have to create it first and then make an update (PATCH) call to mark inactive. This is by design and it’s a limitation. Read more
statecode field is not available for create. Record will be always created as active. The only way for you is to do 2 steps operation - create and set as inactive after.
In other words, statecode=0 is set as default by system, when you pass statuscode=2 in create payload - the platform validation kicks in and say this is invalid pair.

Microservice design

We have a product where 4 microservices are communicating with each other.
Let's say entry point receives a payload as below:
{
"Employees": [
{
"userId": "rirani",
"jobTitleName": "Developer",
"firstName": "Romin",
"lastName": "Irani",
"preferredFullName": "Romin Irani",
"employeeCode": "E1",
"region": "CA",
"phoneNumber": "408-1234567",
"emailAddress": "romin.k.irani#gmail.com"
}
]
}
The 1st microservice does validation on the payload "employeeCode" it allows only employee code which. starts with "E" else returns 400 status code. The Same payload is forwarded to other componet as well if all validation passes.
Now my question is tomorrow there could be fair chance that external service consumes our any of the components to process their request. Do we need to have the validation in all the components?
Now there is no external client which uses our components but in the future maybe.
It's a more of a design question. Do we need to make our validation as a jar or we should not duplicate the validation itself? Its client responsibility to send the correct data if they are calling any other component except Microservice-1.
Thanks, in advance.

IE11 Can't reach this page, but the page is valid and accessible

I have a bit of a bizarre problem happening in IE11. I'm running DataTables with server-side processing so I had to create a custom button for exporting the full data set, since the default buttons only export the visible data set.
Here's the Yajra DataTables for Laravel configuration for one of my buttons:
'buttons' => [
['extend' => 'csv',
'text' => '<i class="fa fa-file-excel-o"></i> CSV',
'action' => 'function(e,dt,node,config){
var data=$.extend(
true,
dt.context[0].oSavedState,
{
columns:dt.context[0].aoColumns.map(function(col){
return {"data":col.data}
})
})
window.location.href = window.location.href +
"?action=csv&" +
$.param(data);
}'
],
...
The button works fine, it basically compiles a list of the columns and filters and sends the user to a Laravel route that handles the action=csv request and generates an Excel download that triggers automatically in Chrome and Firefox.
In IE11, however, the browser redirects to the Excel download route but throws up a "Can’t reach this page" error message. I can see in the address bar that the URL is correct, and what's odd is that if I just hit Refresh in the browser, the CSV download is triggered and I am given the option to save.
This happens every time I click the download link. What might cause IE11 to think the page can't be reached, when it can?
I tried looking at the request/response headers in network tools and everything seems to be just fine. Any ideas?
Also, I tried rewriting my window.location logic to create a hyperlink element, attach it to the DOM, trigger a click, and it still yields the same thing.
More Information
I tried a few other things and was able to eject the download process at any point in the code up until final response to the browser. The browser responds with a 200 status code, when I look at the Network Tab and view the Response Body, I can see my CSV content right there with appropriate Content Disposition, Content Length headers. The Content-Type header is text/plain, but changing it to text/csv didn't solve the problem.
If the IE's Network Tab renders everything correctly, why might IE's browser renderer show a Page Can't Be Displayed error?
Well, I was finally able to resolve the IE/Edge exporting issue and it comes down to query-string length.
The DataTables grid makes a GET request with a whole bunch of properties related to the query (columns that are visible, which filters were applied, etc.).
Sample Request Params:
{
"action": "csv",
"time": "1529689896632",
"start": "0",
"length": "10",
"order": [
["2","asc"],
["1","asc"]
],
"search": {
"search": "",
"smart": "true",
"regex": "false",
"caseInsensitive": "true"
},
"columns": [
{
"visible": "true",
"search": {
"search": "",
"smart": "true",
"regex": "false",
"caseInsensitive": "false"
},
"data": "programs"
},
// ...
Because there are so many columns, these request params create a very lengthy query-string (in the realm of 3-4000 characters). IE and Edge appear to handle query-strings up to a certain length, as I've noticed some bugs come through where the query-string data was truncated.
I ended up reducing the query-string length by omitting unnecessary and default property values needed for the export. Now IE and Edge both immediately respond with the file download instead of throwing a page not found or other bizarre error.

Paypal REST API - Description/Item name missing

I am using paypal ruby sdk in order to process credit cards via rest api. Everything is working fine from perspective of credit card processing. Credit cards are processed properly without any kind of issues.
Unfortunately, when i preform the csv export of transactions on the sandbox (or live) merchant paypal account, the "Item Title" field is not populated and also I cannot see that description field is used anywhere.
Request to the paypal:
Request[post]: https://api.sandbox.paypal.com/v1/payments/payment
Request.body={
"intent":"sale",
"payer":{
"payment_method":"credit_card",
"funding_instruments":[{
"credit_card":{
"number":"xxxxxxxxxxxxxxxx",
"type":"visa",
"expire_month":10,
"expire_year":2020,
"first_name":"First Name",
"last_name":"Last Name"
}
}]
},
"transactions":[{
"amount":{
"currency":"USD",
"total":"1"
},
"description":"This is item description",
"item_list":{
"items":[{
"quantity":"1",
"name":"This is item description",
"price":"1",
"currency":"USD",
"sku":"This is item description"
}]
}
}]
}
Within the successful paypal response I am getting all of these data back including the fields populated with "This is item description".
My question is, which parameter we need to provide for this api call in order to populate "Item Title" field within transactions csv export?
What is the purpose of "description" field within this api request and where this field is used on paypal side (showed) after we process payment with credit card?
EDITED
Tried with PHP SDK as well (just to be sure that this is not an issue with specific SDK). At the end it seems that question is "Is there a field to be used as part of REST API which corresponds to 'Item Title' column within paypal export?"
Indeed answer from pp_pduan answers on initial bounty question (related with specific report). I am adding an update related with this specific report and other reports as well.
For credit card processing you can use following API's on paypal side:
Rest API
DoDirect Payment Api (Pro 3.0)
Payflow Gateway Api (Pro 1.5-2.0)
As per my discussion with paypal side and quite a detailed research, it is not possible to populate Item Name for some of the reports using REST API.
For credit card processing (in order to avoid issues in general with reporting systems) I suggest to go with DoDirect Payment Api if you have Pro accounts. Seems that this specific API is "older" then REST API credit card processing hence it is more stable and do not have any kind of issues with reporting system.
Having in mind that DoDirect Payment Api have weird documentation (at least for me this is not covered properly) I suggest to check following php repository with working solution (examples).
Try put a sample request payload like this,
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://localhost:80/getpaypal",
"cancel_url": "http://localhost:80/cancel"
},
"transactions": [
{
"description": "Transaction Desc Text",
"amount": {
"total":"80",
"currency":"USD"
},
"item_list": {
"items": [
{
"name": "Test Ticket 1",
"currency": "USD",
"quantity": "1",
"sku": "55a460ff65f13",
"price": "10"
},
{
"name": "Test Ticket 2",
"currency": "USD",
"quantity": "2",
"sku": "55a460ff66c7a",
"price": "20"
},
{
"name": "Test Ticket 3",
"currency": "USD",
"quantity": "3",
"sku": "55a460ff66ce2",
"price": "10"
}
]
},
"invoice_number": "55a460ff696br"
}
]
}
And when you download transaction history (csv) from your PayPal profile,
If you've ticked the option "Include Shopping Cart details",
the "name" field under each item object will display in the "Item Title" col; and the description field in transaction object will be in that col as well
If you leave the option of "Include Shopping Cart details", the transaction will be a single record in the csv without the cart item rows, and you'll only see ""description": "Transaction Desc Text"," (description field in transaction object) in the Item Title col

How to handle (failed) validation when creating multiple entities with a REST API

Let's say I have an endpoint user/1/results and I want to upload multiple results at a time.
So I send it JSON like:
{
"data": [
{
"date": "2014-02-14 03:15:41",
"score": 18649,
"time": 42892
},
{
"date": "2013-11-18 09:21:46",
"score": 7856,
"time": 23568.8
}]
}
Let's say time needs to be an integer, so the second entity fails validation.
What's the best thing to do:
Fail both, nothing saves, respond with error message..
Save first entity, respond with error message.
In either case, what would an error message look like? i.e. how/does it specify that it's the second entity that fails validation.
I think you should fail both and respond with an error message because it might be cumbersome again to track the remaining results.
Error message should give the details of failing location. for example if it fails at the second one then specify it in json response.

Resources