From e8d1067fbb3eeb2c2fdd050a967c220ad52b59c0 Mon Sep 17 00:00:00 2001 From: christianmat Date: Wed, 25 Sep 2024 18:46:05 -0700 Subject: [PATCH] fix: flow action handler params --- .changeset/few-trainers-float.md | 5 +++++ packages/react/src/hooks/useStepHandlers.ts | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 .changeset/few-trainers-float.md diff --git a/.changeset/few-trainers-float.md b/.changeset/few-trainers-float.md new file mode 100644 index 00000000..66c6b2cd --- /dev/null +++ b/.changeset/few-trainers-float.md @@ -0,0 +1,5 @@ +--- +"@frigade/react": patch +--- + +Fixes an issue where visibilityCriteria is not respected with some flow actions diff --git a/packages/react/src/hooks/useStepHandlers.ts b/packages/react/src/hooks/useStepHandlers.ts index 01c36e0a..1ae1b432 100644 --- a/packages/react/src/hooks/useStepHandlers.ts +++ b/packages/react/src/hooks/useStepHandlers.ts @@ -36,16 +36,16 @@ export function useStepHandlers(step: FlowStep, { onPrimary, onSecondary }: Step const { navigate } = useContext(FrigadeContext) const stepActions = { - 'flow.back': () => step.flow.back(), - 'flow.complete': () => step.flow.complete(), - 'flow.forward': () => step.flow.forward(), + 'flow.back': (...args) => step.flow.back(...args), + 'flow.complete': (...args) => step.flow.complete(...args), + 'flow.forward': (...args) => step.flow.forward(...args), 'flow.restart': () => step.flow.restart(), - 'flow.skip': () => step.flow.skip(), - 'flow.start': () => step.flow.start(), - 'step.complete': () => step.complete(), - 'step.skip': () => step.skip(), + 'flow.skip': (...args) => step.flow.skip(...args), + 'flow.start': (...args) => step.flow.start(...args), + 'step.complete': (...args) => step.complete(...args), + 'step.skip': (...args) => step.skip(...args), 'step.reset': () => step.reset(), - 'step.start': () => step.start(), + 'step.start': (...args) => step.start(...args), } return { @@ -62,7 +62,7 @@ export function useStepHandlers(step: FlowStep, { onPrimary, onSecondary }: Step step.primaryButton.action === false ? false : stepActions[step.primaryButton.action] if (typeof primaryAction === 'function') { - primaryAction() + await primaryAction(properties, optimistic) } else if (primaryAction !== false) { await step.complete(properties, optimistic) }