You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
changedField.previousValue should be properly set on the 'Number of values' field whatever the position of that field is (See context it will be more clear)
Actual behavior
If my 'Number of values' number input field is not at the 4th position (index = 3) the hook previous value is always null and it seems that whatever the field that is at the 4th position in the array has it's previous value set instead of my number input
Failure Logs
None
Context
Please help this makes no sense to me. Also note that all fields before the prblematic one is not added or removed dynamically so that can't really change the position on 'Number of values' field
Smart action:
exportenumEnterpriseCollectionFields{Name='Name',OfferCard='Offer mobility card',Type='Spending rules type',ShortDescription='Short Description (Summary)',Description='Description',Value='Value',DailyLimit='Daily limit',TransactionLimit='Transaction limit',MonthlyAllocation='Monthly allocation'}exportdeclareenumSpendingRuleType{StripeMerchant="stripeMerchant",StripeCategory="stripeCategory",CommutifiPlan="commutifiPlan",Wallet="wallet"}{name: 'Create Wallet',type: 'single',fields: [{field: EnterpriseCollectionFields.OfferCard,description:
'Weather this wallet will setup a Commutifi card or not. Then rules like Stripe categories can be applied',type: 'Boolean',hook: 'onOfferCardChanged',isRequired: true,defaultValue: false},{field: EnterpriseCollectionFields.Type,description: 'Type of spending rule restrictions you want to add',type: 'Enum',enums: Object.values(SpendingRuleType),hook: 'onTypeChanged',isRequired: true},{field: 'Number of values',description: 'How many plans or stripe categories you want to add ?',type: 'Number',defaultValue: 1,hook: 'onNbValueChange'},{field: EnterpriseCollectionFields.Value,description:
'Commutifi Plan ids, Stripe categories or leave empty if you are making a global rule for the wallet (Ex. monthly limit only or days limit)',type: 'String',reference: 'plans.id'},{field: EnterpriseCollectionFields.Name,description: 'Wallet Name that employee will see',type: 'String',isRequired: true},{field: EnterpriseCollectionFields.Description,description:
'Long Wallet description. Markdown available in wallet detail view but we can only use a simple text here ...',type: 'String',isRequired: true},{field: EnterpriseCollectionFields.ShortDescription,description: 'Quick 50 max characters description of the wallet',type: 'String',isRequired: true,hook: 'onDescriptionChange'},{field: EnterpriseCollectionFields.DailyLimit,description: 'Daily max amount spent (in cents)',type: 'Number'},{field: EnterpriseCollectionFields.TransactionLimit,description: 'Max amount PER transaction (in cents)',type: 'Number'}],hooks: {change: {onOfferCardChanged: ({ fields, changedField })=>{if(changedField.value===true){fields.push({previousValue: undefined,value: undefined,field: EnterpriseCollectionFields.MonthlyAllocation,type: 'Number',isRequired: true})}else{constindex=fields.findIndex((f)=>f.field===EnterpriseCollectionFields.MonthlyAllocation)fields.splice(index,1)}returnfields},onTypeChanged: ({ fields, changedField })=>{constfieldsIndexToMutate=[]fields.forEach((field,i)=>field.field.startsWith(EnterpriseCollectionFields.Value)
? fieldsIndexToMutate.push(i)
: null)switch(changedField.value){caseSpendingRuleType.CommutifiPlan:
fieldsIndexToMutate.forEach((index)=>{constfield=fields[index]field.isRequired=truefield.type='String'field.reference='plans.id'field.enums=null// @ts-ignorefield.widgetEdit={name: 'belongsto typeahead',parameters: {}}})breakcaseSpendingRuleType.StripeMerchant:
fieldsIndexToMutate.forEach((index)=>{constfield=fields[index]field.isRequired=truefield.type='String'field.reference=nullfield.enums=null// @ts-ignorefield.widgetEdit={name: 'text editor',parameters: {}}})breakcaseSpendingRuleType.Wallet:
fieldsIndexToMutate.forEach((index)=>{constfield=fields[index]field.isRequired=falsefield.type='String'field.reference=nullfield.enums=null// @ts-ignorefield.widgetEdit={name: 'text editor',parameters: {}}})breakdefault:
break}returnfields},onNbValueChange: ({ changedField, fields })=>{if(changedField.value<0){returnfields}constpreviousValue=changedField.previousValue??1constvalue=changedField.value??1constvalueFieldIndex=fields.findIndex((field)=>field.field.startsWith(EnterpriseCollectionFields.Value))constindex=valueFieldIndex>=0
? valueFieldIndex
: fields.findIndex((field)=>field.field==='Number of values')+1if(previousValue<value){constnewFieldAmount=value-previousValuefields.splice(index+previousValue,0,// times function is from lodash
...times(newFieldAmount,(i)=>({previousValue: undefined,value: undefined,
...walletPlanValueField,field: `${EnterpriseCollectionFields.Value}${previousValue+i}`})))}elseif(previousValue>value){constdeleteFieldAmount=previousValue-valuefields.splice(index+value,deleteFieldAmount)}returnfields},onDescriptionChange: ({ fields, changedField })=>{if(typeofchangedField.value==='string'&&changedField.value.length>50){changedField.value.substring(0,50)}returnfields}}}}
In that configuration ⬆️ I can't get the number input to work with adding value fields properly because the previous value is set on the wrong item in the fields array
But the position in the schema is right
Screen record of bad behavior (Number of values is 3rd in array -> index 2)
Screen record of good behavior (Number of values is 4th in array -> index 3)
I have similar issues now but at one index further in the array. It's like if the schema wasn't updated and something triggers a change and then if I don't use the number input at a specific index the previousValue isn't set on the proper field but I check and it is and the browser displays the message notifying of an update and I do a refresh. Also tried incognito and same issue :(
Expected behavior
changedField.previousValue
should be properly set on the 'Number of values' field whatever the position of that field is (See context it will be more clear)Actual behavior
If my 'Number of values' number input field is not at the 4th position (index = 3) the hook previous value is always null and it seems that whatever the field that is at the 4th position in the array has it's previous value set instead of my number input
Failure Logs
None
Context
Please help this makes no sense to me. Also note that all fields before the prblematic one is not added or removed dynamically so that can't really change the position on 'Number of values' field
Smart action:
In that configuration ⬆️ I can't get the number input to work with adding value fields properly because the previous value is set on the wrong item in the fields array
But the position in the schema is right
Screen record of bad behavior (Number of values is 3rd in array -> index 2)
Screen record of good behavior (Number of values is 4th in array -> index 3)
The text was updated successfully, but these errors were encountered: