Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor getMutationState function to accept MutationResult object #30

Closed
dominik-zeglen opened this issue Mar 1, 2019 · 1 comment · Fixed by #297
Closed

Refactor getMutationState function to accept MutationResult object #30

dominik-zeglen opened this issue Mar 1, 2019 · 1 comment · Fixed by #297

Comments

@dominik-zeglen
Copy link
Contributor

What I'm trying to achieve

To simplify code.

Describe a proposed solution

export function getMutationState<TData>(
  result: MutationResult<TData>,
  ...keys: Array<keyof TData>
): ConfirmButtonTransitionState {
  if (result.loading) {
    return "loading";
  }
  if (result.called) {
    interface MutationData {
      errors: UserError[];
    }
    return keys
      .map(key => {
        const data = (result.data[key] as unknown) as MutationData;
        return data.errors;
      })
      .map(hasErrors)
      .reduce((acc, curr) => acc || curr, false)
      ? "error"
      : "success";
  }
  return "default";
}
@maarcingebala maarcingebala transferred this issue from saleor/saleor Aug 9, 2019
@stale
Copy link

stale bot commented Nov 26, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant