IdoPesok / zsa

https://zsa.vercel.app
MIT License
763 stars 23 forks source link

Adding onFinish callback support #94

Closed webdevcody closed 4 months ago

webdevcody commented 4 months ago

adding support for a onFinish callback which is invoked after either onSuccess and onError for finally type of functionality.

The reason I'm adding this, is because in my own code I needed to disable / enable the ability for a user to close a sheet / drawer. For example, this is what I'm doing in my app

 const { execute, isPending } = useServerAction(createGroupAction, {
    retry: {
      maxAttempts: 3,
      delay: 2000,
    },
    onStart() {
      preventCloseRef.current = true;
    },
    onFinish() {
      preventCloseRef.current = false;
    },
    onError({ err }) {
      toast({
        title: "Something went wrong",
        description: err.message,
        variant: "destructive",
      });
    },
    onSuccess() {
      toast({
        title: "Group Created",
        description: "You can now start managing your events",
      });
      setIsOpen(false);
    },
  });

Before adding this functionality, I had to copy the same line in both the onSuccess() and onError() callbacks.

changeset-bot[bot] commented 4 months ago

⚠️ No Changeset found

Latest commit: 1a801e5b90fa093551a373a9a9b8f540ec27700d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zsa ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2024 3:41am
IdoPesok commented 4 months ago

That makes sense -- can you make the same PR but into the IdoPesok:fix-transitions branch? That has the transition bug fix you implemented (code will be a tad different) and planning to merge that branch in tonight. PR is here #92

webdevcody commented 4 months ago

sure thing, I'll probably do it tomorrow