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/lib/index.js CHANGED
@@ -295,6 +295,21 @@ function BeginWorkflow(props) {
295
295
  }
296
296
  };
297
297
  }
298
+ const handleDeleteMetadata = async (client, toast, id) => {
299
+ try {
300
+ await client.delete("workflow-metadata.".concat(id));
301
+ toast.push({
302
+ status: "success",
303
+ title: "Workflow completed"
304
+ });
305
+ } catch (error) {
306
+ console.error(error);
307
+ toast.push({
308
+ status: "error",
309
+ title: "Could not complete Workflow"
310
+ });
311
+ }
312
+ };
298
313
  function CompleteWorkflow(props) {
299
314
  const {
300
315
  id
@@ -308,12 +323,13 @@ function CompleteWorkflow(props) {
308
323
  const client = sanity.useClient({
309
324
  apiVersion: API_VERSION
310
325
  });
326
+ const toast = ui.useToast();
311
327
  if (error) {
312
328
  console.error(error);
313
329
  }
314
- const handle = React.useCallback(() => {
315
- client.delete("workflow-metadata.".concat(id));
316
- }, [id, client]);
330
+ const handle = React.useCallback(async () => {
331
+ await handleDeleteMetadata(client, toast, id);
332
+ }, [client, toast, id]);
317
333
  if (!metadata) {
318
334
  return null;
319
335
  }
@@ -325,8 +341,9 @@ function CompleteWorkflow(props) {
325
341
  disabled: loading || error || !isLastState,
326
342
  label: "Complete Workflow",
327
343
  title: isLastState ? "Removes the document from the Workflow process" : "Cannot remove from workflow until in the last state",
328
- onHandle: () => {
329
- handle();
344
+ onHandle: async () => {
345
+ await handle();
346
+ props.onComplete();
330
347
  },
331
348
  color: "positive"
332
349
  };
@@ -889,17 +906,7 @@ function CompleteButton(props) {
889
906
  if (!id) {
890
907
  return;
891
908
  }
892
- client.delete("workflow-metadata.".concat(id)).then(() => {
893
- toast.push({
894
- status: "success",
895
- title: "Workflow completed"
896
- });
897
- }).catch(() => {
898
- toast.push({
899
- status: "error",
900
- title: "Could not complete Workflow"
901
- });
902
- });
909
+ handleDeleteMetadata(client, toast, id);
903
910
  }, [client, toast]);
904
911
  return /* @__PURE__ */jsxRuntime.jsx(ui.Tooltip, {
905
912
  portal: true,