sanity-plugin-workflow 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,3 @@
1
- > This is a **Sanity Studio v3** plugin.
2
-
3
1
  # Sanity Workflow Demo Plugin Example
4
2
 
5
3
  With Sanity Studio you can [customize your content tools to support arbitrary workflows like assignment and content pipelines](https://www.sanity.io/docs/custom-workflows).
package/lib/index.esm.js CHANGED
@@ -283,6 +283,21 @@ function BeginWorkflow(props) {
283
283
  }
284
284
  };
285
285
  }
286
+ const handleDeleteMetadata = async (client, toast, id) => {
287
+ try {
288
+ await client.delete("workflow-metadata.".concat(id));
289
+ toast.push({
290
+ status: "success",
291
+ title: "Workflow completed"
292
+ });
293
+ } catch (error) {
294
+ console.error(error);
295
+ toast.push({
296
+ status: "error",
297
+ title: "Could not complete Workflow"
298
+ });
299
+ }
300
+ };
286
301
  function CompleteWorkflow(props) {
287
302
  const {
288
303
  id
@@ -296,12 +311,13 @@ function CompleteWorkflow(props) {
296
311
  const client = useClient({
297
312
  apiVersion: API_VERSION
298
313
  });
314
+ const toast = useToast();
299
315
  if (error) {
300
316
  console.error(error);
301
317
  }
302
- const handle = useCallback(() => {
303
- client.delete("workflow-metadata.".concat(id));
304
- }, [id, client]);
318
+ const handle = useCallback(async () => {
319
+ await handleDeleteMetadata(client, toast, id);
320
+ }, [client, toast, id]);
305
321
  if (!metadata) {
306
322
  return null;
307
323
  }
@@ -313,8 +329,9 @@ function CompleteWorkflow(props) {
313
329
  disabled: loading || error || !isLastState,
314
330
  label: "Complete Workflow",
315
331
  title: isLastState ? "Removes the document from the Workflow process" : "Cannot remove from workflow until in the last state",
316
- onHandle: () => {
317
- handle();
332
+ onHandle: async () => {
333
+ await handle();
334
+ props.onComplete();
318
335
  },
319
336
  color: "positive"
320
337
  };
@@ -877,17 +894,7 @@ function CompleteButton(props) {
877
894
  if (!id) {
878
895
  return;
879
896
  }
880
- client.delete("workflow-metadata.".concat(id)).then(() => {
881
- toast.push({
882
- status: "success",
883
- title: "Workflow completed"
884
- });
885
- }).catch(() => {
886
- toast.push({
887
- status: "error",
888
- title: "Could not complete Workflow"
889
- });
890
- });
897
+ handleDeleteMetadata(client, toast, id);
891
898
  }, [client, toast]);
892
899
  return /* @__PURE__ */jsx(Tooltip, {
893
900
  portal: true,