IdoPesok / zsa

https://zsa.vercel.app
MIT License
447 stars 13 forks source link

adding support for a onFinish callback which is invoked after either … #95

Closed webdevcody closed 1 month ago

webdevcody commented 1 month 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 1 month ago

⚠️ No Changeset found

Latest commit: cfc4b54e8d32bfdfff4b77e883ff4316b907b1d1

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 1 month 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 4:59am
IdoPesok commented 1 month ago

Perfect! Thanks 🫡