Skip to content

Instantly share code, notes, and snippets.

@basanth-ivoyant
Created November 9, 2020 11:57
Show Gist options
  • Save basanth-ivoyant/4e061efd5c921b5e7d4b64af71f9c9cc to your computer and use it in GitHub Desktop.
Save basanth-ivoyant/4e061efd5c921b5e7d4b64af71f9c9cc to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
"id": "MoveSubscriber",
"initial": "start",
"context": {
"jumpTo": {
"CONFIRM": {
"conditionExpr": "data.moveSubCheck.totalDue > 0 ? 'PAYMENT':'MOVESUBCONFRIM'",
"source": "context"
}
},
"mappings": {
"moveSubCheck": [
{
"source": "context",
"expr": "{'body':$merge([{'request':{'body':{'phoneNumbers':[data.INIT.routeData[0].telephoneData.telephoneNumber],'sourceBillingAccountNumber':data.INIT.data.accountDetails.billingAccountNumber,'targetBillingAccountNumber':$string(data.lookupAccount.billingAccountNumber)}}},{'datasource':data.INIT.datasources[0]}])}"
}
],
"moveSub": [
{
"source": "context",
"expr": "{'body':$merge([{'request':{'body':{'phoneNumbers':[data.INIT.routeData[0].telephoneData.telephoneNumber],'sourceBillingAccountNumber':data.INIT.data.accountDetails.billingAccountNumber,'targetBillingAccountNumber':$string(data.lookupAccount.billingAccountNumber)}}},{'datasource':data.INIT.datasources[1]}])}"
}
]
}
},
"states": {
"start": {
"on": {
"INIT": {
"actions": ["helpers-store"],
"target": "searchAccount"
}
}
},
"searchAccount": {
"on": {
"LOOKUP": "lookupAccount",
"CANCEL": "cancelFromAccountSearch"
}
},
"lookupAccount": {
"invoke": {
"id": "helpers-invokeService",
"src": "helpers-invokeService",
"onDone": {
"actions": [
{
"type": "helpers-storeResp",
"data": { "key": "lookupAccount" }
}
],
"target": "validate"
},
"onError": {
"target": "searchAccount"
}
}
},
"validate": {
"on": {
"VALIDATE": "validateAccount",
"CANCEL": "cancelFromAccountSearch"
}
},
"reenterSecurityDetails": {
"on": {
"VALIDATE": "validateAccount",
"CANCEL": "cancelFromAccountSearch"
}
},
"validateAccount": {
"invoke": {
"id": "helpers-invokeService",
"src": "helpers-invokeService",
"onDone": {
"target": "moveSubCheck"
},
"onError": {
"target": "reenterSecurityDetails"
}
}
},
"cancelFromAccountSearch": {
"type": "final"
},
"moveSubCheck": {
"invoke": {
"src": {
"type": "helpers-invokeService",
"op": "moveSubCheck"
},
"onDone": {
"actions": [
{
"type": "helpers-storeResp",
"data": { "key": "moveSubCheck" }
}
],
"target": "waitForConfirmation"
},
"onError": {
"target": "validate"
}
}
},
"waitForConfirmation": {
"on": {
"CONFIRM": {
"actions": ["jumpTo"]
},
"PAYMENT": "payment",
"MOVESUBCONFRIM": "confirmMoveSub",
"CANCEL": "cancelMoveSub"
}
},
"cancelMoveSub": {
"type": "final"
},
"payment": {
"on": {
"SUBMITPAYMENT": "submitPayment",
"CANCEL": "cancelFromPayment"
}
},
"cancelFromPayment": {
"type": "final"
},
"submitPayment": {
"invoke": {
"id": "helpers-invokeService",
"src": "helpers-invokeService",
"onDone": {
"target": "confirmMoveSub"
},
"onError": {
"target": "payment"
}
}
},
"confirmMoveSub": {
"invoke": {
"src": {
"type": "helpers-invokeService",
"op": "moveSub"
},
"onDone": {
"target": "end"
},
"onError": {
"target": "error"
}
}
},
"end": {
"type": "final"
},
"error": {
"type": "final"
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment