@bigbinary/neeto-approvals-frontend 0.0.8 → 0.0.10

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/dist/index.cjs.js CHANGED
@@ -5023,12 +5023,6 @@ var nullSafe$1 = function nullSafe(func) {
5023
5023
  );
5024
5024
  };
5025
5025
  var noop = function noop() {};
5026
- var toLabelAndValue = function toLabelAndValue(string) {
5027
- return {
5028
- label: string,
5029
- value: string
5030
- };
5031
- };
5032
5026
  var isNotEmpty = /*#__PURE__*/ramda.complement(ramda.isEmpty);
5033
5027
  var isNotPresent = /*#__PURE__*/ramda.either(ramda.isNil, ramda.isEmpty);
5034
5028
  var isPresent = /*#__PURE__*/ramda.complement(isNotPresent);
@@ -7817,7 +7811,7 @@ const HISTORY_TABLE_COLUMNS = [{
7817
7811
  title: t$1("common.id"),
7818
7812
  render: (approvalLabel, _ref) => {
7819
7813
  let requestableUrl = _ref.requestableUrl;
7820
- const url = new URL(requestableUrl);
7814
+ const url = new URL(requestableUrl || window.location.origin);
7821
7815
  return /*#__PURE__*/t__default["default"].createElement(neetoui.Button, {
7822
7816
  to: url.pathname,
7823
7817
  label: approvalLabel,
@@ -8140,16 +8134,21 @@ const fetch$1 = params => axios__default["default"].get(`${BASE_URL}/templates`,
8140
8134
  params
8141
8135
  });
8142
8136
  const show$1 = id => axios__default["default"].get(`${BASE_URL}/templates/${id}`);
8143
- const create = payload => axios__default["default"].post(`${BASE_URL}/templates`, payload);
8144
- const update = _ref => {
8145
- let id = _ref.id,
8137
+ const create = _ref => {
8138
+ let _ref$url = _ref.url,
8139
+ url = _ref$url === void 0 ? BASE_URL : _ref$url,
8146
8140
  payload = _ref.payload;
8147
- return axios__default["default"].put(`${BASE_URL}/templates/${id}`, {
8148
- template: payload
8149
- });
8141
+ return axios__default["default"].post(url, payload);
8150
8142
  };
8151
- const destroy = _ref2 => {
8152
- let templateId = _ref2.templateId;
8143
+ const update = _ref2 => {
8144
+ let id = _ref2.id,
8145
+ payload = _ref2.payload,
8146
+ _ref2$url = _ref2.url,
8147
+ url = _ref2$url === void 0 ? BASE_URL : _ref2$url;
8148
+ return axios__default["default"].put(`${url}/${id}`, payload);
8149
+ };
8150
+ const destroy = _ref3 => {
8151
+ let templateId = _ref3.templateId;
8153
8152
  return axios__default["default"].delete(`${BASE_URL}/templates/${templateId}`);
8154
8153
  };
8155
8154
  const templatesApi = {
@@ -8226,7 +8225,11 @@ const columnData = _ref => {
8226
8225
  dataIndex: "visibility",
8227
8226
  key: "visibility",
8228
8227
  sorter: true,
8229
- title: instance.t("common.visibility")
8228
+ title: instance.t("common.visibility"),
8229
+ render: (_, _ref2) => {
8230
+ let accessible = _ref2.accessible;
8231
+ return accessible.label;
8232
+ }
8230
8233
  }, {
8231
8234
  key: "actions",
8232
8235
  ellipsis: true,
@@ -8317,10 +8320,7 @@ const Templates = _ref => {
8317
8320
  label: t("common.add_", {
8318
8321
  what: t("common.approvalTemplate").toLocaleLowerCase()
8319
8322
  }),
8320
- onClick: () => {
8321
- setIsMenubarOpen(false);
8322
- history.push(`${approvalsPath}${routes.templates.new}`);
8323
- }
8323
+ onClick: () => history.push(`${approvalsPath}${routes.templates.new}`)
8324
8324
  });
8325
8325
  if (isTemplateLoading) {
8326
8326
  return /*#__PURE__*/t__default["default"].createElement("div", {
@@ -8385,26 +8385,16 @@ const TEMPLATE_FORM_INITIAL_VALUES = {
8385
8385
  };
8386
8386
  const TEMPLATE_FORM_VALIDATION_SCHEMA = yup__namespace.object().shape({
8387
8387
  name: yup__namespace.string().trim().required(t$1("validations.name")),
8388
- description: yup__namespace.string().trim().required(t$1("validations.description")),
8389
8388
  recipient: yup__namespace.object().required(t$1("validations.recipient")),
8390
8389
  message: yup__namespace.string().test("message", t$1("validations.message"), content => !fr(content)),
8391
8390
  variables: yup__namespace.array().of(yup__namespace.object().shape({
8392
8391
  variable: yup__namespace.string().trim().required(t$1("validations.variable"))
8393
8392
  }))
8394
8393
  });
8395
- const VISIBILITY_OPTIONS = [{
8394
+ const SELF_VISIBILITY = {
8396
8395
  label: t$1("select.visibility.self"),
8397
- value: "Self"
8398
- }, {
8399
- label: t$1("select.visibility.supportTeam"),
8400
- value: "Support team"
8401
- }, {
8402
- label: t$1("select.visibility.managers"),
8403
- value: "Managers"
8404
- }, {
8405
- label: t$1("select.visibility.financeTeam"),
8406
- value: "Finance team"
8407
- }];
8396
+ value: "self"
8397
+ };
8408
8398
 
8409
8399
  const DynamicBlock = () => {
8410
8400
  const _useTranslation = useTranslation(),
@@ -8412,11 +8402,12 @@ const DynamicBlock = () => {
8412
8402
  const _useFormikContext = formik$1.useFormikContext(),
8413
8403
  _useFormikContext$val = _useFormikContext.values.variables,
8414
8404
  variables = _useFormikContext$val === void 0 ? [] : _useFormikContext$val;
8415
- const editorVariables = variables.map(_ref => {
8405
+ const editorVariables = variables.map((_ref, index) => {
8416
8406
  let variable = _ref.variable;
8407
+ const variableValue = variable || `variable_${index + 1}`;
8417
8408
  return {
8418
- key: variable,
8419
- label: variable
8409
+ key: variableValue,
8410
+ label: variableValue
8420
8411
  };
8421
8412
  });
8422
8413
  return /*#__PURE__*/t__default["default"].createElement(t__default["default"].Fragment, null, /*#__PURE__*/t__default["default"].createElement("div", {
@@ -8467,7 +8458,8 @@ const Form$1 = _ref => {
8467
8458
  _ref$onSubmit = _ref.onSubmit,
8468
8459
  onSubmit = _ref$onSubmit === void 0 ? noop : _ref$onSubmit,
8469
8460
  _ref$isLoading = _ref.isLoading,
8470
- isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading;
8461
+ isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
8462
+ visibilityOptions = _ref.visibilityOptions;
8471
8463
  const history = reactRouterDom.useHistory();
8472
8464
  const _useTranslation = useTranslation(),
8473
8465
  t = _useTranslation.t;
@@ -8508,9 +8500,9 @@ const Form$1 = _ref => {
8508
8500
  }), /*#__PURE__*/t__default["default"].createElement(formik.Select, {
8509
8501
  name: "visibility",
8510
8502
  label: t("common.visibility"),
8511
- options: VISIBILITY_OPTIONS
8503
+ options: [...visibilityOptions, SELF_VISIBILITY]
8512
8504
  })), /*#__PURE__*/t__default["default"].createElement(DynamicBlock, null), /*#__PURE__*/t__default["default"].createElement("div", {
8513
- className: "space-x-4"
8505
+ className: "space-x-4 pb-6"
8514
8506
  }, /*#__PURE__*/t__default["default"].createElement(neetoui.Button, {
8515
8507
  label: t("buttons.saveChanges"),
8516
8508
  type: "submit",
@@ -8532,16 +8524,20 @@ const buildTemplatePayload = template => {
8532
8524
  let variable = _ref.variable;
8533
8525
  return [`variable${index + 1}`, variable];
8534
8526
  });
8535
- const payload = _objectSpread$3(_objectSpread$3({}, template), {}, {
8536
- visibility: visibility.value,
8537
- approverId: recipient.value,
8538
- variables: ramda.fromPairs(indexedVariables)
8539
- });
8527
+ const payload = {
8528
+ template: _objectSpread$3(_objectSpread$3({}, template), {}, {
8529
+ accessibleId: visibility.value,
8530
+ approverId: recipient.value,
8531
+ variables: ramda.fromPairs(indexedVariables)
8532
+ })
8533
+ };
8540
8534
  return payload;
8541
8535
  };
8542
8536
 
8543
8537
  const Create = _ref => {
8544
- let approvalsPath = _ref.approvalsPath;
8538
+ let approvalsPath = _ref.approvalsPath,
8539
+ visibilityOptions = _ref.visibilityOptions,
8540
+ templateUrl = _ref.templateUrl;
8545
8541
  const history = reactRouterDom.useHistory();
8546
8542
  const _useTranslation = useTranslation(),
8547
8543
  t = _useTranslation.t;
@@ -8550,7 +8546,10 @@ const Create = _ref => {
8550
8546
  isLoading = _useCreateTemplate.isLoading;
8551
8547
  const onSubmit = template => {
8552
8548
  const payload = buildTemplatePayload(template);
8553
- createTemplate(payload, {
8549
+ createTemplate({
8550
+ url: templateUrl,
8551
+ payload
8552
+ }, {
8554
8553
  onSuccess: () => history.push(`${approvalsPath}${routes.templates.index}`)
8555
8554
  });
8556
8555
  };
@@ -8564,7 +8563,8 @@ const Create = _ref => {
8564
8563
  }]
8565
8564
  }), /*#__PURE__*/t__default["default"].createElement(Form$1, {
8566
8565
  onSubmit: onSubmit,
8567
- isLoading: isLoading
8566
+ isLoading: isLoading,
8567
+ visibilityOptions: visibilityOptions
8568
8568
  }));
8569
8569
  };
8570
8570
 
@@ -8572,7 +8572,9 @@ function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if
8572
8572
  function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8573
8573
  const Edit = _ref => {
8574
8574
  var _template$recipient, _template$recipient2;
8575
- let approvalsPath = _ref.approvalsPath;
8575
+ let approvalsPath = _ref.approvalsPath,
8576
+ visibilityOptions = _ref.visibilityOptions,
8577
+ templateUrl = _ref.templateUrl;
8576
8578
  const _useParams = reactRouterDom.useParams(),
8577
8579
  id = _useParams.id;
8578
8580
  const history = reactRouterDom.useHistory();
@@ -8595,7 +8597,8 @@ const Edit = _ref => {
8595
8597
  const payload = buildTemplatePayload(template);
8596
8598
  updateTemplate({
8597
8599
  id,
8598
- payload
8600
+ payload,
8601
+ url: templateUrl
8599
8602
  });
8600
8603
  };
8601
8604
  if (isFetchingTemplate) {
@@ -8612,10 +8615,11 @@ const Edit = _ref => {
8612
8615
  text: t("common.templates")
8613
8616
  }]
8614
8617
  }), /*#__PURE__*/t__default["default"].createElement(Form$1, {
8618
+ visibilityOptions: visibilityOptions,
8615
8619
  onSubmit: onSubmit,
8616
8620
  isLoading: isUpdating,
8617
8621
  initialData: _objectSpread$2(_objectSpread$2({}, template), {}, {
8618
- visibility: toLabelAndValue(template.visibility),
8622
+ visibility: template.accessible.id,
8619
8623
  recipient: {
8620
8624
  label: (_template$recipient = template.recipient) === null || _template$recipient === void 0 ? void 0 : _template$recipient.name,
8621
8625
  value: (_template$recipient2 = template.recipient) === null || _template$recipient2 === void 0 ? void 0 : _template$recipient2.id
@@ -8657,7 +8661,7 @@ const Menu = _ref => {
8657
8661
  const _useTranslation = useTranslation(),
8658
8662
  t = _useTranslation.t;
8659
8663
  const category = (_pathname$split$ = pathname.split(routes.approvals)[1]) === null || _pathname$split$ === void 0 ? void 0 : _pathname$split$.toLocaleUpperCase();
8660
- const isActive = filter => approvalFilterKeys.includes(category) && ramda.identical(filter, category);
8664
+ const isActive = filter => category.includes(filter);
8661
8665
  const getRoute = filter => `${approvalsPath}${filter.toLowerCase()}`;
8662
8666
  return /*#__PURE__*/t__default["default"].createElement(layouts.MenuBar, {
8663
8667
  showMenu: isMenuOpen,
@@ -8674,7 +8678,7 @@ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if
8674
8678
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8675
8679
  const Approvals = _ref => {
8676
8680
  let config = _ref.config;
8677
- const _useState = t$2.useState(false),
8681
+ const _useState = t$2.useState(true),
8678
8682
  _useState2 = _slicedToArray$2(_useState, 2),
8679
8683
  isMenubarOpen = _useState2[0],
8680
8684
  setIsMenubarOpen = _useState2[1];
@@ -8772,7 +8776,7 @@ const Form = _ref => {
8772
8776
  }, variables.map(variable => /*#__PURE__*/t__default["default"].createElement(neetoui.Input, {
8773
8777
  className: "w-full",
8774
8778
  key: variable,
8775
- label: capitalize$1(variable),
8779
+ label: variable,
8776
8780
  value: variableValues[variable],
8777
8781
  onChange: event => {
8778
8782
  setVariableValues(ramda.assoc(variable, event.target.value));