@atlaskit/link-create 0.3.2 → 0.4.0

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/common/constants.js +4 -2
  3. package/dist/cjs/controllers/form-context/main.js +17 -5
  4. package/dist/cjs/ui/create-form/main.js +52 -40
  5. package/dist/cjs/ui/create-form/messages.js +20 -0
  6. package/dist/cjs/ui/create-form/textfield/main.js +4 -3
  7. package/dist/cjs/ui/error-boundary/error-boundary-ui/error-svg/index.js +45 -44
  8. package/dist/cjs/ui/error-boundary/error-boundary-ui/messages.js +1 -1
  9. package/dist/cjs/ui/main.js +25 -6
  10. package/dist/cjs/ui/messages.js +15 -0
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/es2019/common/constants.js +2 -1
  13. package/dist/es2019/controllers/form-context/main.js +11 -2
  14. package/dist/es2019/ui/create-form/main.js +32 -16
  15. package/dist/es2019/ui/create-form/messages.js +13 -0
  16. package/dist/es2019/ui/create-form/textfield/main.js +4 -3
  17. package/dist/es2019/ui/error-boundary/error-boundary-ui/error-svg/index.js +45 -44
  18. package/dist/es2019/ui/error-boundary/error-boundary-ui/messages.js +1 -1
  19. package/dist/es2019/ui/main.js +20 -5
  20. package/dist/es2019/ui/messages.js +8 -0
  21. package/dist/es2019/version.json +1 -1
  22. package/dist/esm/common/constants.js +2 -1
  23. package/dist/esm/controllers/form-context/main.js +17 -5
  24. package/dist/esm/ui/create-form/main.js +53 -44
  25. package/dist/esm/ui/create-form/messages.js +13 -0
  26. package/dist/esm/ui/create-form/textfield/main.js +4 -3
  27. package/dist/esm/ui/error-boundary/error-boundary-ui/error-svg/index.js +45 -44
  28. package/dist/esm/ui/error-boundary/error-boundary-ui/messages.js +1 -1
  29. package/dist/esm/ui/main.js +25 -6
  30. package/dist/esm/ui/messages.js +8 -0
  31. package/dist/esm/version.json +1 -1
  32. package/dist/types/common/constants.d.ts +1 -0
  33. package/dist/types/controllers/callback-context/main.d.ts +1 -1
  34. package/dist/types/controllers/form-context/main.d.ts +2 -0
  35. package/dist/types/ui/create-form/main.d.ts +3 -3
  36. package/dist/types/ui/create-form/messages.d.ts +12 -0
  37. package/dist/types/ui/create-form/textfield/main.d.ts +1 -1
  38. package/dist/types/ui/create-form/textfield/types.d.ts +2 -0
  39. package/dist/types/ui/messages.d.ts +7 -0
  40. package/package.json +20 -18
  41. package/report.api.md +15 -4
  42. package/dist/cjs/ui/create-form/styled.js +0 -13
  43. package/dist/cjs/ui/error-boundary/error-boundary-ui/error-svg/styled.js +0 -13
  44. package/dist/es2019/ui/create-form/styled.js +0 -7
  45. package/dist/es2019/ui/error-boundary/error-boundary-ui/error-svg/styled.js +0 -7
  46. package/dist/esm/ui/create-form/styled.js +0 -5
  47. package/dist/esm/ui/error-boundary/error-boundary-ui/error-svg/styled.js +0 -5
  48. package/dist/types/ui/create-form/styled.d.ts +0 -1
  49. package/dist/types/ui/error-boundary/error-boundary-ui/error-svg/styled.d.ts +0 -1
  50. package/tmp/api-report-tmp.d.ts +0 -141
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/link-create
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`56507598609`](https://bitbucket.org/atlassian/atlassian-frontend/commits/56507598609) - Skip minor dependency bump
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
13
+ ## 0.3.3
14
+
15
+ ### Patch Changes
16
+
17
+ - [`5cbb3a0f20c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5cbb3a0f20c) - Fix tangerine lint warnings & fix SVG id not unique & add VR test for dropdowns in modal & handle plugin errors
18
+
3
19
  ## 0.3.2
4
20
 
5
21
  ### Patch Changes
@@ -3,8 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.COMPONENT_NAME = exports.ANALYTICS_CHANNEL = void 0;
6
+ exports.CREATE_FORM_MAX_WIDTH_IN_PX = exports.COMPONENT_NAME = exports.ANALYTICS_CHANNEL = void 0;
7
7
  var ANALYTICS_CHANNEL = 'media';
8
8
  exports.ANALYTICS_CHANNEL = ANALYTICS_CHANNEL;
9
9
  var COMPONENT_NAME = 'linkCreate';
10
- exports.COMPONENT_NAME = COMPONENT_NAME;
10
+ exports.COMPONENT_NAME = COMPONENT_NAME;
11
+ var CREATE_FORM_MAX_WIDTH_IN_PX = '600';
12
+ exports.CREATE_FORM_MAX_WIDTH_IN_PX = CREATE_FORM_MAX_WIDTH_IN_PX;
@@ -17,15 +17,20 @@ var FormContext = /*#__PURE__*/(0, _react.createContext)({
17
17
  assignValidator: function assignValidator() {},
18
18
  getValidators: function getValidators() {
19
19
  return {};
20
- }
20
+ },
21
+ setFormErrorMessage: function setFormErrorMessage() {}
21
22
  });
22
23
  exports.FormContext = FormContext;
23
24
  var FormContextProvider = function FormContextProvider(_ref) {
24
25
  var children = _ref.children;
25
- var _useState = (0, _react.useState)({}),
26
+ var _useState = (0, _react.useState)(),
26
27
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
27
- validators = _useState2[0],
28
- setValidators = _useState2[1];
28
+ error = _useState2[0],
29
+ setError = _useState2[1];
30
+ var _useState3 = (0, _react.useState)({}),
31
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
32
+ validators = _useState4[0],
33
+ setValidators = _useState4[1];
29
34
 
30
35
  // Use useCallback to prevent infinite useEffect calls
31
36
  var assignValidator = (0, _react.useCallback)(function (name, fieldValidators) {
@@ -38,10 +43,17 @@ var FormContextProvider = function FormContextProvider(_ref) {
38
43
  var getValidators = (0, _react.useCallback)(function () {
39
44
  return validators;
40
45
  }, [validators]);
46
+
47
+ // Callback to reset error state
48
+ var setFormErrorMessage = (0, _react.useCallback)(function (errorMessage) {
49
+ return setError(errorMessage);
50
+ }, [setError]);
41
51
  return /*#__PURE__*/_react.default.createElement(FormContext.Provider, {
42
52
  value: {
43
53
  assignValidator: assignValidator,
44
- getValidators: getValidators
54
+ getValidators: getValidators,
55
+ setFormErrorMessage: setFormErrorMessage,
56
+ formErrorMessage: error
45
57
  }
46
58
  }, children);
47
59
  };
@@ -6,28 +6,37 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.CreateForm = void 0;
9
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
- var _react = _interopRequireWildcard(require("react"));
12
+ var _react = require("react");
12
13
  var _react2 = require("@emotion/react");
14
+ var _reactIntlNext = require("react-intl-next");
13
15
  var _analyticsNext = require("@atlaskit/analytics-next");
14
16
  var _loadingButton = _interopRequireDefault(require("@atlaskit/button/loading-button"));
15
17
  var _standardButton = _interopRequireDefault(require("@atlaskit/button/standard-button"));
16
18
  var _form = _interopRequireWildcard(require("@atlaskit/form"));
19
+ var _error = _interopRequireDefault(require("@atlaskit/icon/glyph/error"));
17
20
  var _constants = require("../../common/constants");
18
21
  var _analytics = _interopRequireDefault(require("../../common/utils/analytics/analytics.codegen"));
19
22
  var _formContext = require("../../controllers/form-context");
20
- var _styled = require("./styled");
23
+ var _messages = require("./messages");
21
24
  var _utils = require("./utils");
22
25
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
26
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
24
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } /** @jsx jsx */
25
- var withFormContext = function withFormContext(Component) {
26
- return function (props) {
27
- return (0, _react2.jsx)(_formContext.FormContextProvider, null, (0, _react2.jsx)(Component, props));
28
- };
29
- };
30
- var CreateFormWithoutContext = function CreateFormWithoutContext(_ref) {
27
+ /** @jsx jsx */
28
+
29
+ var formStyles = (0, _react2.css)({
30
+ maxWidth: "".concat(_constants.CREATE_FORM_MAX_WIDTH_IN_PX, "px"),
31
+ padding: "0 0 ".concat("var(--ds-space-300, 24px)", " 0"),
32
+ margin: "var(--ds-space-0, 0px)".concat(" auto")
33
+ });
34
+ var errorStyles = (0, _react2.css)({
35
+ display: 'flex',
36
+ alignItems: 'center',
37
+ marginRight: 'auto'
38
+ });
39
+ var CreateForm = function CreateForm(_ref) {
31
40
  var children = _ref.children,
32
41
  testId = _ref.testId,
33
42
  onCancel = _ref.onCancel,
@@ -35,31 +44,31 @@ var CreateFormWithoutContext = function CreateFormWithoutContext(_ref) {
35
44
  var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
36
45
  createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
37
46
  var _useFormContext = (0, _formContext.useFormContext)(),
38
- getValidators = _useFormContext.getValidators;
47
+ getValidators = _useFormContext.getValidators,
48
+ formErrorMessage = _useFormContext.formErrorMessage;
49
+ var intl = (0, _reactIntlNext.useIntl)();
39
50
  var handleSubmit = (0, _react.useCallback)( /*#__PURE__*/function () {
40
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) {
51
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(data) {
41
52
  var validators, errors;
42
- return _regeneratorRuntime().wrap(function _callee$(_context) {
43
- while (1) {
44
- switch (_context.prev = _context.next) {
45
- case 0:
46
- createAnalyticsEvent((0, _analytics.default)('ui.button.clicked.create', {})).fire(_constants.ANALYTICS_CHANNEL);
47
- validators = getValidators();
48
- errors = (0, _utils.validateFormData)({
49
- data: data,
50
- validators: validators
51
- });
52
- if (!(Object.keys(errors).length !== 0)) {
53
- _context.next = 5;
54
- break;
55
- }
56
- return _context.abrupt("return", errors);
57
- case 5:
58
- onSubmit(data);
59
- case 6:
60
- case "end":
61
- return _context.stop();
62
- }
53
+ return _regenerator.default.wrap(function _callee$(_context) {
54
+ while (1) switch (_context.prev = _context.next) {
55
+ case 0:
56
+ createAnalyticsEvent((0, _analytics.default)('ui.button.clicked.create', {})).fire(_constants.ANALYTICS_CHANNEL);
57
+ validators = getValidators();
58
+ errors = (0, _utils.validateFormData)({
59
+ data: data,
60
+ validators: validators
61
+ });
62
+ if (!(Object.keys(errors).length !== 0)) {
63
+ _context.next = 5;
64
+ break;
65
+ }
66
+ return _context.abrupt("return", errors);
67
+ case 5:
68
+ onSubmit(data);
69
+ case 6:
70
+ case "end":
71
+ return _context.stop();
63
72
  }
64
73
  }, _callee);
65
74
  }));
@@ -78,21 +87,24 @@ var CreateFormWithoutContext = function CreateFormWithoutContext(_ref) {
78
87
  formProps = _ref3.formProps;
79
88
  return (0, _react2.jsx)("form", (0, _extends2.default)({}, formProps, {
80
89
  name: "confluence-creation-form",
81
- "data-testid": testId
82
- // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
83
- ,
84
- css: _styled.formStyles
85
- }), (0, _react2.jsx)(_form.FormSection, null, children), (0, _react2.jsx)(_form.FormFooter, null, (0, _react2.jsx)(_standardButton.default, {
90
+ "data-testid": testId,
91
+ css: formStyles
92
+ }), (0, _react2.jsx)(_form.FormSection, null, children), (0, _react2.jsx)(_form.FormFooter, null, formErrorMessage && (0, _react2.jsx)("div", {
93
+ css: errorStyles,
94
+ "data-testid": "link-create-confluence-form-error"
95
+ }, (0, _react2.jsx)(_error.default, {
96
+ label: formErrorMessage,
97
+ primaryColor: "var(--ds-icon-danger, #E34935)"
98
+ }), formErrorMessage), (0, _react2.jsx)(_standardButton.default, {
86
99
  appearance: "subtle",
87
100
  onClick: handleCancel,
88
101
  testId: 'cancel-button'
89
- }, "Cancel"), (0, _react2.jsx)(_loadingButton.default, {
102
+ }, intl.formatMessage(_messages.messages.cancel)), (0, _react2.jsx)(_loadingButton.default, {
90
103
  appearance: "primary",
91
104
  type: "submit",
92
105
  isLoading: submitting,
93
106
  testId: 'create-button'
94
- }, "Create")));
107
+ }, intl.formatMessage(_messages.messages.create))));
95
108
  });
96
109
  };
97
- var CreateForm = withFormContext(CreateFormWithoutContext);
98
110
  exports.CreateForm = CreateForm;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.messages = void 0;
7
+ var _reactIntlNext = require("react-intl-next");
8
+ var messages = (0, _reactIntlNext.defineMessages)({
9
+ cancel: {
10
+ id: 'linkCreate.createForm.button.cancel',
11
+ defaultMessage: 'Cancel',
12
+ description: 'Button to cancel and dismiss link create'
13
+ },
14
+ create: {
15
+ id: 'linkCreate.createForm.button.create',
16
+ defaultMessage: 'Create',
17
+ description: 'Button to submit the form and Create object'
18
+ }
19
+ });
20
+ exports.messages = messages;
@@ -19,14 +19,14 @@ var _formContext = require("../../../controllers/form-context");
19
19
  * the handleSubmit function passed to the form <Form> that have a key matching the `name`
20
20
  * of this text field are shown above the field.
21
21
  */
22
-
23
22
  function TextField(_ref) {
24
23
  var label = _ref.label,
25
24
  name = _ref.name,
26
25
  validationHelpText = _ref.validationHelpText,
27
26
  isRequired = _ref.isRequired,
28
27
  testId = _ref.testId,
29
- validators = _ref.validators;
28
+ validators = _ref.validators,
29
+ placeholder = _ref.placeholder;
30
30
  var _useFormContext = (0, _formContext.useFormContext)(),
31
31
  assignValidator = _useFormContext.assignValidator;
32
32
  (0, _react.useEffect)(function () {
@@ -43,7 +43,8 @@ function TextField(_ref) {
43
43
  var fieldProps = _ref2.fieldProps,
44
44
  error = _ref2.error;
45
45
  return (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(_textfield.default, (0, _extends2.default)({}, fieldProps, {
46
- testId: testId
46
+ testId: testId,
47
+ placeholder: placeholder
47
48
  })), !error && (0, _react2.jsx)(_form.HelperMessage, null, validationHelpText), error && (0, _react2.jsx)(_form.ErrorMessage, null, error));
48
49
  });
49
50
  }
@@ -5,59 +5,60 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _react = require("@emotion/react");
8
- var _styled = require("./styled");
9
8
  /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
10
9
  /** @jsx jsx */
11
10
 
11
+ var WIDTH = 82;
12
+ var errorStyles = (0, _react.css)({
13
+ width: "".concat(WIDTH, "px"),
14
+ margin: "0 auto ".concat("var(--ds-space-300, 24px)"),
15
+ display: "block"
16
+ });
17
+ var id = 'link-create-error-svg';
12
18
  var ErrorSVG = function ErrorSVG() {
13
19
  return (0, _react.jsx)("svg", {
14
- xmlns: "http://www.w3.org/2000/svg",
15
- viewBox: "0 0 82 110"
16
- // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
17
- ,
18
- css: _styled.errorStyles
19
- }, (0, _react.jsx)("defs", null, (0, _react.jsx)("linearGradient", {
20
- id: "a",
21
- x1: "81.992%",
22
- x2: "-1.724%",
23
- y1: "43.911%",
24
- y2: "87.726%"
25
- }, (0, _react.jsx)("stop", {
26
- offset: "0%",
27
- stopColor: "#FFD740"
28
- }), (0, _react.jsx)("stop", {
29
- offset: "100%",
30
- stopColor: "#FFAB00"
31
- }))), (0, _react.jsx)("g", {
20
+ height: "90",
21
+ viewBox: "0 0 164 212",
32
22
  fill: "none",
33
- fillRule: "evenodd"
23
+ xmlns: "http://www.w3.org/2000/svg",
24
+ css: errorStyles
34
25
  }, (0, _react.jsx)("path", {
35
- fill: "url(#a)",
36
- fillRule: "nonzero",
37
- d: "M47.39 40.58l33.22 57.54a7.585 7.585 0 0 1-6.57 11.38H7.6a7.585 7.585 0 0 1-6.57-11.38l33.22-57.54a7.585 7.585 0 0 1 13.14 0z"
38
- }), (0, _react.jsx)("path", {
39
- fill: "#253858",
40
- fillRule: "nonzero",
41
- d: "M43.61 82.355l1.44-22.175a4.59 4.59 0 0 0-4.58-4.89 4.59 4.59 0 0 0-4.58 4.89l1.44 22.175a3.15 3.15 0 0 0 3.14 2.945 3.15 3.15 0 0 0 3.14-2.945zM35.69 94.125a4.765 4.765 0 0 0 5.195 4.79 4.84 4.84 0 0 0-.45-9.66 4.82 4.82 0 0 0-4.745 4.87z"
42
- }), (0, _react.jsx)("path", {
43
- fill: "#FFC400",
44
- fillRule: "nonzero",
45
- d: "M45.85 14.085L42.145.725a.305.305 0 0 0-.595.025L39.22 13.3l-2.9-.54a.305.305 0 0 0-.35.38l3.705 13.36a.305.305 0 0 0 .595 0l2.33-12.55 2.9.515a.305.305 0 0 0 .35-.38z"
26
+ d: "m95.43 74.16 66.44 115.08c5.84 10.12-1.46 22.76-13.14 22.76H15.85c-11.68 0-18.98-12.65-13.14-22.76L69.15 74.16c5.84-10.12 20.44-10.12 26.28 0Zm-7.56 83.55 2.88-44.35c.34-5.29-3.86-9.78-9.16-9.78-5.31 0-9.51 4.48-9.16 9.78l2.88 44.35a6.3 6.3 0 0 0 6.28 5.89c3.31 0 6.06-2.58 6.28-5.89Zm-15.84 23.54c0 5.66 4.76 10.1 10.39 9.58 4.85-.45 8.73-4.5 8.83-9.37.11-5.45-4.31-9.94-9.73-9.94-5.23-.01-9.49 4.37-9.49 9.73Z",
27
+ fill: "url(#".concat(id, ")")
46
28
  }), (0, _react.jsx)("path", {
47
- fill: "#FFAB00",
48
- fillRule: "nonzero",
49
- d: "M32.56 21.405l-5.44-4.275a.135.135 0 0 0-.205.165L29.68 23l-1.33.655a.135.135 0 0 0 0 .225l5.435 4.275a.135.135 0 0 0 .205-.165l-2.785-5.715 1.33-.645a.135.135 0 0 0 .025-.225z"
29
+ opacity: ".6",
30
+ d: "M93.35 27.17 85.94.45c-.17-.62-1.07-.58-1.19.05l-4.66 25.1-5.8-1.08a.612.612 0 0 0-.7.76L81 52c.17.62 1.07.58 1.19-.05l4.66-25.1 5.8 1.08c.45.08.82-.33.7-.76ZM66.77 41.81 55.9 33.26c-.22-.18-.53.07-.41.33l5.53 11.43-2.66 1.29c-.18.09-.2.33-.05.45l10.87 8.55c.22.18.53-.07.41-.33l-5.53-11.43 2.66-1.29c.17-.08.2-.33.05-.45Z",
31
+ fill: "#C1C7D0"
50
32
  }), (0, _react.jsx)("path", {
51
- stroke: "#344563",
52
- strokeLinecap: "round",
53
- strokeWidth: "2",
54
- d: "M57.575 18.8c-.585.795-5.5-2.8-6.08-2-.58.8 4.33 4.395 3.75 5.195-.58.8-5.5-2.8-6.085-2-.585.8 4.33 4.395 3.745 5.195-.585.8-5.5-2.8-6.085-2-.585.8 4.33 4.395 3.745 5.195"
55
- }), (0, _react.jsx)("path", {
56
- stroke: "#5E6C84",
57
- strokeLinecap: "round",
58
- strokeWidth: "2",
59
- d: "M59.96 32.595c-.73.665-3.525-2.39-4.255-1.72-.73.67 2.065 3.725 1.335 4.39-.73.665-3.525-2.39-4.255-1.72-.34.31.08 1.135.555 2M22.4 32.5c.91.385 2.5-3.435 3.43-3.05.93.385-.695 4.2.215 4.585.91.385 2.5-3.435 3.43-3.05.425.18.305 1.095.145 2.065"
60
- })));
33
+ opacity: ".6",
34
+ d: "M102.78 56.75a.993.993 0 0 1-.92-1.38c-.24-.77-2.29-2.85-3.54-4.11-2.97-3.01-4.93-5-3.84-6.49 1.09-1.48 3.58-.22 7.35 1.7 1.32.67 3.35 1.7 4.45 2.03-.64-.95-2.24-2.58-3.28-3.63-2.97-3.01-4.93-5-3.84-6.49 1.08-1.48 3.58-.22 7.34 1.7 1.32.67 3.34 1.7 4.45 2.03-.64-.95-2.24-2.57-3.28-3.62-2.97-3.01-4.93-5-3.84-6.49 1.08-1.48 3.57-.22 7.34 1.7 1.58.8 4.18 2.13 4.98 2.13a1.005 1.005 0 0 1 1.46 1.36c-1.09 1.48-3.57.22-7.34-1.7-1.32-.67-3.34-1.7-4.44-2.03.64.95 2.24 2.57 3.28 3.62 2.97 3.01 4.93 5 3.84 6.49-1.08 1.48-3.57.22-7.34-1.7-1.32-.67-3.35-1.7-4.45-2.03.64.95 2.24 2.57 3.28 3.63 2.97 3.01 4.93 5 3.84 6.49-1.09 1.48-3.58.22-7.35-1.7-1.32-.67-3.35-1.71-4.45-2.03.64.95 2.24 2.58 3.28 3.63 2.97 3.01 4.93 5 3.84 6.49-.21.26-.51.4-.82.4Zm5.56 14.32c-.35 0-.69-.19-.88-.52-1.04-1.88-2.22-4.02-.91-5.21 1.31-1.2 3.34.18 5.49 1.63.87.59 2.26 1.53 2.93 1.71-.12-.68-.93-2.15-1.45-3.07-1.26-2.27-2.45-4.41-1.14-5.61 1.31-1.2 3.34.18 5.49 1.63.96.65 2.54 1.72 3.1 1.74a1 1 0 0 1 1.27 1.54c-1.31 1.2-3.34-.17-5.49-1.63-.87-.59-2.26-1.53-2.93-1.71.12.68.93 2.15 1.45 3.07 1.26 2.27 2.45 4.41 1.14 5.61-1.31 1.2-3.34-.18-5.49-1.63-.87-.59-2.26-1.53-2.93-1.71.12.68.93 2.14 1.22 2.67.27.48.09 1.09-.39 1.36-.15.09-.32.13-.48.13Zm-54.32-2.89c-.22 0-.44-.04-.67-.14-1.64-.69-1.24-3.11-.81-5.67.17-1.04.45-2.7.33-3.38-.57.39-1.56 1.75-2.18 2.6-1.53 2.09-2.99 4.07-4.62 3.38a.991.991 0 0 1-.53-1.31c.2-.48.73-.72 1.21-.57.52-.21 1.65-1.75 2.34-2.68 1.53-2.09 2.98-4.08 4.62-3.38 1.64.69 1.24 3.11.81 5.67-.17 1.04-.45 2.7-.33 3.38.57-.39 1.56-1.75 2.18-2.6 1.53-2.09 2.98-4.08 4.62-3.38 1.63.69 1.24 3.09.89 5.21-.09.54-.6.91-1.15.83-.54-.09-.92-.6-.83-1.15.1-.59.37-2.24.26-2.92-.57.39-1.56 1.75-2.18 2.6-1.33 1.79-2.59 3.51-3.96 3.51Z",
35
+ fill: "#B3BAC5"
36
+ }), (0, _react.jsx)("defs", null, (0, _react.jsx)("linearGradient", {
37
+ id: id,
38
+ x1: "26.169",
39
+ y1: "228.621",
40
+ x2: "138.408",
41
+ y2: "116.382",
42
+ gradientUnits: "userSpaceOnUse"
43
+ }, (0, _react.jsx)("stop", {
44
+ stopColor: "#C1C7D0"
45
+ }), (0, _react.jsx)("stop", {
46
+ offset: ".297",
47
+ stopColor: "#C6CBD4",
48
+ stopOpacity: ".881"
49
+ }), (0, _react.jsx)("stop", {
50
+ offset: ".63",
51
+ stopColor: "#D3D7DE",
52
+ stopOpacity: ".748"
53
+ }), (0, _react.jsx)("stop", {
54
+ offset: ".98",
55
+ stopColor: "#E9EBEF",
56
+ stopOpacity: ".608"
57
+ }), (0, _react.jsx)("stop", {
58
+ offset: "1",
59
+ stopColor: "#EBECF0",
60
+ stopOpacity: ".6"
61
+ }))));
61
62
  };
62
63
  var _default = ErrorSVG;
63
64
  exports.default = _default;
@@ -13,7 +13,7 @@ var _default = (0, _reactIntlNext.defineMessages)({
13
13
  },
14
14
  description: {
15
15
  id: 'link-create.unknown-error.description',
16
- defaultMessage: '<a>Contact Support</a> if refreshing doesn’t fix things.',
16
+ defaultMessage: 'Refresh the page, or contact <a>Atlassian Support</a> if this keeps happening.',
17
17
  description: 'Description when an unknown error occurs'
18
18
  }
19
19
  });
@@ -6,22 +6,31 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.default = exports.PACKAGE_DATA = void 0;
9
+ var _objectDestructuringEmpty2 = _interopRequireDefault(require("@babel/runtime/helpers/objectDestructuringEmpty"));
9
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
11
  var _react = require("react");
11
12
  var _react2 = require("@emotion/react");
13
+ var _reactIntlNext = require("react-intl-next");
12
14
  var _analyticsNext = require("@atlaskit/analytics-next");
13
15
  var _modalDialog = _interopRequireWildcard(require("@atlaskit/modal-dialog"));
14
16
  var _constants = require("../common/constants");
15
17
  var _analytics = require("../common/utils/analytics");
16
18
  var _analytics2 = _interopRequireDefault(require("../common/utils/analytics/analytics.codegen"));
17
19
  var _callbackContext = require("../controllers/callback-context");
20
+ var _formContext = require("../controllers/form-context");
18
21
  var _version = require("../version.json");
19
22
  var _errorBoundary = require("./error-boundary");
23
+ var _messages = require("./messages");
20
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
26
  /** @jsx jsx */
23
27
 
24
- var LinkCreate = function LinkCreate(_ref) {
28
+ var withFormContext = function withFormContext(Component) {
29
+ return function (props) {
30
+ return (0, _react2.jsx)(_formContext.FormContextProvider, null, (0, _react2.jsx)(Component, props));
31
+ };
32
+ };
33
+ var LinkCreate = withFormContext(function (_ref) {
25
34
  var plugins = _ref.plugins,
26
35
  entityKey = _ref.entityKey,
27
36
  onCreate = _ref.onCreate,
@@ -30,24 +39,34 @@ var LinkCreate = function LinkCreate(_ref) {
30
39
  var chosenOne = plugins.find(function (plugin) {
31
40
  return plugin.key === entityKey;
32
41
  });
42
+ var _useFormContext = (0, _formContext.useFormContext)(),
43
+ setFormErrorMessage = _useFormContext.setFormErrorMessage;
33
44
  if (!chosenOne) {
34
45
  throw new Error('Make sure you specified a valid entityKey');
35
46
  }
36
47
  var handleCreate = (0, _react.useCallback)(function (result) {
48
+ // Reset the form error message
49
+ setFormErrorMessage(undefined);
37
50
  onCreate && onCreate(result.url);
38
- }, [onCreate]);
51
+ }, [onCreate, setFormErrorMessage]);
52
+ var handleFailure = (0, _react.useCallback)(function (errorMessage) {
53
+ // Set the form error message
54
+ setFormErrorMessage(errorMessage);
55
+ onFailure && onFailure(errorMessage);
56
+ }, [onFailure, setFormErrorMessage]);
39
57
  return (0, _react2.jsx)(_callbackContext.LinkCreateCallbackProvider, {
40
58
  onCreate: handleCreate,
41
- onFailure: onFailure,
59
+ onFailure: handleFailure,
42
60
  onCancel: onCancel
43
61
  }, chosenOne.form);
44
- };
62
+ });
45
63
  var LinkCreateWithModal = function LinkCreateWithModal(props) {
46
64
  var testId = props.testId,
47
65
  onCancel = props.onCancel,
48
66
  active = props.active;
49
67
  var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
50
68
  createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
69
+ var intl = (0, _reactIntlNext.useIntl)();
51
70
  var handleOpenComplete = (0, _react.useCallback)(function () {
52
71
  createAnalyticsEvent((0, _analytics2.default)('screen.linkCreateScreen.viewed', {})).fire(_constants.ANALYTICS_CHANNEL);
53
72
  }, [createAnalyticsEvent]);
@@ -60,10 +79,10 @@ var LinkCreateWithModal = function LinkCreateWithModal(props) {
60
79
  shouldScrollInViewport: true,
61
80
  onOpenComplete: handleOpenComplete,
62
81
  onCloseComplete: handleCloseComplete
63
- }, (0, _react2.jsx)(_modalDialog.ModalHeader, null, (0, _react2.jsx)(_modalDialog.ModalTitle, null, "Create New")), (0, _react2.jsx)(_modalDialog.ModalBody, null, (0, _react2.jsx)(_errorBoundary.ErrorBoundary, null, (0, _react2.jsx)(LinkCreate, props)))));
82
+ }, (0, _react2.jsx)(_modalDialog.ModalHeader, null, (0, _react2.jsx)(_modalDialog.ModalTitle, null, intl.formatMessage(_messages.messages.heading))), (0, _react2.jsx)(_modalDialog.ModalBody, null, (0, _react2.jsx)(_errorBoundary.ErrorBoundary, null, (0, _react2.jsx)(_formContext.FormContextProvider, null, (0, _react2.jsx)(LinkCreate, props))))));
64
83
  };
65
84
  var LinkCreateWithAnalyticsContext = (0, _analytics.withLinkCreateAnalyticsContext)( /*#__PURE__*/(0, _react.memo)(function (_ref2) {
66
- var props = (0, _extends2.default)({}, _ref2);
85
+ var props = (0, _extends2.default)({}, ((0, _objectDestructuringEmpty2.default)(_ref2), _ref2));
67
86
  return (0, _react2.jsx)(LinkCreateWithModal, props);
68
87
  }));
69
88
  var PACKAGE_DATA = {
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.messages = void 0;
7
+ var _reactIntlNext = require("react-intl-next");
8
+ var messages = (0, _reactIntlNext.defineMessages)({
9
+ heading: {
10
+ id: 'linkCreate.modal.heading',
11
+ defaultMessage: 'Create new',
12
+ description: 'Header for the create modal'
13
+ }
14
+ });
15
+ exports.messages = messages;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-create",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,2 +1,3 @@
1
1
  export const ANALYTICS_CHANNEL = 'media';
2
- export const COMPONENT_NAME = 'linkCreate';
2
+ export const COMPONENT_NAME = 'linkCreate';
3
+ export const CREATE_FORM_MAX_WIDTH_IN_PX = '600';
@@ -1,11 +1,13 @@
1
1
  import React, { createContext, useCallback, useContext, useState } from 'react';
2
2
  export const FormContext = /*#__PURE__*/createContext({
3
3
  assignValidator: () => {},
4
- getValidators: () => ({})
4
+ getValidators: () => ({}),
5
+ setFormErrorMessage: () => {}
5
6
  });
6
7
  const FormContextProvider = ({
7
8
  children
8
9
  }) => {
10
+ const [error, setError] = useState();
9
11
  const [validators, setValidators] = useState({});
10
12
 
11
13
  // Use useCallback to prevent infinite useEffect calls
@@ -20,10 +22,17 @@ const FormContextProvider = ({
20
22
  const getValidators = useCallback(() => {
21
23
  return validators;
22
24
  }, [validators]);
25
+
26
+ // Callback to reset error state
27
+ const setFormErrorMessage = useCallback(errorMessage => {
28
+ return setError(errorMessage);
29
+ }, [setError]);
23
30
  return /*#__PURE__*/React.createElement(FormContext.Provider, {
24
31
  value: {
25
32
  assignValidator,
26
- getValidators
33
+ getValidators,
34
+ setFormErrorMessage,
35
+ formErrorMessage: error
27
36
  }
28
37
  }, children);
29
38
  };
@@ -1,18 +1,29 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  /** @jsx jsx */
3
- import React, { useCallback } from 'react';
4
- import { jsx } from '@emotion/react';
3
+ import { useCallback } from 'react';
4
+ import { css, jsx } from '@emotion/react';
5
+ import { useIntl } from 'react-intl-next';
5
6
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
6
7
  import LoadingButton from '@atlaskit/button/loading-button';
7
8
  import Button from '@atlaskit/button/standard-button';
8
9
  import Form, { FormFooter, FormSection } from '@atlaskit/form';
9
- import { ANALYTICS_CHANNEL } from '../../common/constants';
10
+ import ErrorIcon from '@atlaskit/icon/glyph/error';
11
+ import { ANALYTICS_CHANNEL, CREATE_FORM_MAX_WIDTH_IN_PX } from '../../common/constants';
10
12
  import createEventPayload from '../../common/utils/analytics/analytics.codegen';
11
- import { FormContextProvider, useFormContext } from '../../controllers/form-context';
12
- import { formStyles } from './styled';
13
+ import { useFormContext } from '../../controllers/form-context';
14
+ import { messages } from './messages';
13
15
  import { validateFormData } from './utils';
14
- const withFormContext = Component => props => jsx(FormContextProvider, null, jsx(Component, props));
15
- const CreateFormWithoutContext = ({
16
+ const formStyles = css({
17
+ maxWidth: `${CREATE_FORM_MAX_WIDTH_IN_PX}px`,
18
+ padding: `0 0 ${"var(--ds-space-300, 24px)"} 0`,
19
+ margin: `${"var(--ds-space-0, 0px)"} auto`
20
+ });
21
+ const errorStyles = css({
22
+ display: 'flex',
23
+ alignItems: 'center',
24
+ marginRight: 'auto'
25
+ });
26
+ export const CreateForm = ({
16
27
  children,
17
28
  testId,
18
29
  onCancel,
@@ -22,8 +33,10 @@ const CreateFormWithoutContext = ({
22
33
  createAnalyticsEvent
23
34
  } = useAnalyticsEvents();
24
35
  const {
25
- getValidators
36
+ getValidators,
37
+ formErrorMessage
26
38
  } = useFormContext();
39
+ const intl = useIntl();
27
40
  const handleSubmit = useCallback(async data => {
28
41
  createAnalyticsEvent(createEventPayload('ui.button.clicked.create', {})).fire(ANALYTICS_CHANNEL);
29
42
  const validators = getValidators();
@@ -47,19 +60,22 @@ const CreateFormWithoutContext = ({
47
60
  formProps
48
61
  }) => jsx("form", _extends({}, formProps, {
49
62
  name: "confluence-creation-form",
50
- "data-testid": testId
51
- // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
52
- ,
63
+ "data-testid": testId,
53
64
  css: formStyles
54
- }), jsx(FormSection, null, children), jsx(FormFooter, null, jsx(Button, {
65
+ }), jsx(FormSection, null, children), jsx(FormFooter, null, formErrorMessage && jsx("div", {
66
+ css: errorStyles,
67
+ "data-testid": "link-create-confluence-form-error"
68
+ }, jsx(ErrorIcon, {
69
+ label: formErrorMessage,
70
+ primaryColor: "var(--ds-icon-danger, #E34935)"
71
+ }), formErrorMessage), jsx(Button, {
55
72
  appearance: "subtle",
56
73
  onClick: handleCancel,
57
74
  testId: 'cancel-button'
58
- }, "Cancel"), jsx(LoadingButton, {
75
+ }, intl.formatMessage(messages.cancel)), jsx(LoadingButton, {
59
76
  appearance: "primary",
60
77
  type: "submit",
61
78
  isLoading: submitting,
62
79
  testId: 'create-button'
63
- }, "Create"))));
64
- };
65
- export const CreateForm = withFormContext(CreateFormWithoutContext);
80
+ }, intl.formatMessage(messages.create)))));
81
+ };