sanity-plugin-workflow 1.0.4 → 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
@@ -14,7 +14,7 @@ var router = require('sanity/router');
14
14
  var dnd = require('@hello-pangea/dnd');
15
15
  var groq = require('groq');
16
16
  var reactVirtual = require('@tanstack/react-virtual');
17
- var styled = require('styled-components');
17
+ var styledComponents = require('styled-components');
18
18
  var framerMotion = require('framer-motion');
19
19
  function _interopDefaultCompat(e) {
20
20
  return e && typeof e === 'object' && 'default' in e ? e : {
@@ -23,7 +23,6 @@ function _interopDefaultCompat(e) {
23
23
  }
24
24
  var React__default = /*#__PURE__*/_interopDefaultCompat(React);
25
25
  var groq__default = /*#__PURE__*/_interopDefaultCompat(groq);
26
- var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
27
26
  function defineStates(states) {
28
27
  return states;
29
28
  }
@@ -296,6 +295,21 @@ function BeginWorkflow(props) {
296
295
  }
297
296
  };
298
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
+ };
299
313
  function CompleteWorkflow(props) {
300
314
  const {
301
315
  id
@@ -309,12 +323,13 @@ function CompleteWorkflow(props) {
309
323
  const client = sanity.useClient({
310
324
  apiVersion: API_VERSION
311
325
  });
326
+ const toast = ui.useToast();
312
327
  if (error) {
313
328
  console.error(error);
314
329
  }
315
- const handle = React.useCallback(() => {
316
- client.delete("workflow-metadata.".concat(id));
317
- }, [id, client]);
330
+ const handle = React.useCallback(async () => {
331
+ await handleDeleteMetadata(client, toast, id);
332
+ }, [client, toast, id]);
318
333
  if (!metadata) {
319
334
  return null;
320
335
  }
@@ -326,8 +341,9 @@ function CompleteWorkflow(props) {
326
341
  disabled: loading || error || !isLastState,
327
342
  label: "Complete Workflow",
328
343
  title: isLastState ? "Removes the document from the Workflow process" : "Cannot remove from workflow until in the last state",
329
- onHandle: () => {
330
- handle();
344
+ onHandle: async () => {
345
+ await handle();
346
+ props.onComplete();
331
347
  },
332
348
  color: "positive"
333
349
  };
@@ -890,17 +906,7 @@ function CompleteButton(props) {
890
906
  if (!id) {
891
907
  return;
892
908
  }
893
- client.delete("workflow-metadata.".concat(id)).then(() => {
894
- toast.push({
895
- status: "success",
896
- title: "Workflow completed"
897
- });
898
- }).catch(() => {
899
- toast.push({
900
- status: "error",
901
- title: "Could not complete Workflow"
902
- });
903
- });
909
+ handleDeleteMetadata(client, toast, id);
904
910
  }, [client, toast]);
905
911
  return /* @__PURE__ */jsxRuntime.jsx(ui.Tooltip, {
906
912
  portal: true,
@@ -1454,7 +1460,7 @@ var __template$1 = (cooked, raw) => __freeze$1(__defProp$1(cooked, "raw", {
1454
1460
  value: __freeze$1(raw || cooked.slice())
1455
1461
  }));
1456
1462
  var _a$1;
1457
- const StyledStickyCard = styled__default.default(ui.Card)(() => styled.css(_a$1 || (_a$1 = __template$1(["\n position: sticky;\n top: 0;\n z-index: 1;\n "]))));
1463
+ const StyledStickyCard = styledComponents.styled(ui.Card)(() => styledComponents.css(_a$1 || (_a$1 = __template$1(["\n position: sticky;\n top: 0;\n z-index: 1;\n "]))));
1458
1464
  function StateTitle(props) {
1459
1465
  const {
1460
1466
  state,
@@ -1539,7 +1545,7 @@ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", {
1539
1545
  value: __freeze(raw || cooked.slice())
1540
1546
  }));
1541
1547
  var _a;
1542
- const StyledFloatingCard = styled__default.default(ui.Card)(() => styled.css(_a || (_a = __template(["\n position: fixed;\n bottom: 0;\n left: 0;\n z-index: 1000;\n "]))));
1548
+ const StyledFloatingCard = styledComponents.styled(ui.Card)(() => styledComponents.css(_a || (_a = __template(["\n position: fixed;\n bottom: 0;\n left: 0;\n z-index: 1000;\n "]))));
1543
1549
  function FloatingCard(_ref3) {
1544
1550
  let {
1545
1551
  children