Please see my update below.
The scenario: when onEntry to the submit state it fires a defined saveData action. This action persists the form data, the catch is I can’t get access to the data although if I hardcode a dataset object and use that it works. I can see the data exists in ctx.bank_details._state.context.answers.
// state
[submit]: {
onEntry: saveData,
type: 'final'
},
// action
[saveData]: assign((ctx, ev) => {
console.log('test');
const { data } = ctx;
const answers1 = ctx.machines?.answers;
const answers = {
"account_no": "123",
"transit_no": "123",
"bank_no": "bank_no",
"sin": "123",
"dob": "123",
"postal_code": "1",
"province": "B",
"city": "123",
"apt_suite": "123",
"address": "123",
"last_name": "123",
"first_name": "123",
} as any;
(async (data: any, answers: any) => {
apiCall(
`service/answers`,
{
body: { answers },
method: 'PUT',
},
data.context,
).catch((error) => error);
})(data,answers);
return ctx;
}),
UPDATE:
I've been at this all day and I can all I need to do is access that current state. The problem is machine _state is private and I can't figure out how to get access to this in the action
const { machines = {}, data, form, } = ctx;
const { order } = form;
const index = 0;
const currentStep = order[index];
const machine = machines[currentStep];