@panneau/form-resource 3.0.281 → 3.0.283

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 (2) hide show
  1. package/es/index.js +137 -14
  2. package/package.json +9 -9
package/es/index.js CHANGED
@@ -15,8 +15,8 @@ import Button from '@panneau/element-button';
15
15
  import Form from '@panneau/element-form';
16
16
  import { useResourceValues } from '@panneau/intl';
17
17
 
18
- var _excluded$1 = ["resource", "action", "previous", "status", "value", "onSubmit", "errors", "generalError", "className"];
19
- var propTypes$1 = {
18
+ var _excluded$2 = ["resource", "action", "previous", "status", "value", "onSubmit", "errors", "generalError", "className"];
19
+ var propTypes$2 = {
20
20
  resource: PropTypes.resource.isRequired,
21
21
  action: PropTypes$1.string,
22
22
  previous: PropTypes$1.string,
@@ -30,7 +30,7 @@ var propTypes$1 = {
30
30
  errors: PropTypes$1.objectOf(PropTypes$1.arrayOf(PropTypes$1.string)),
31
31
  className: PropTypes$1.string
32
32
  };
33
- var defaultProps$1 = {
33
+ var defaultProps$2 = {
34
34
  action: null,
35
35
  previous: null,
36
36
  status: null,
@@ -50,7 +50,7 @@ var DeleteForm = function DeleteForm(_ref) {
50
50
  _ref.errors;
51
51
  var generalError = _ref.generalError,
52
52
  className = _ref.className,
53
- props = _objectWithoutProperties(_ref, _excluded$1);
53
+ props = _objectWithoutProperties(_ref, _excluded$2);
54
54
  var _ref2 = value || {},
55
55
  _ref2$id = _ref2.id,
56
56
  id = _ref2$id === void 0 ? null : _ref2$id;
@@ -123,11 +123,121 @@ var DeleteForm = function DeleteForm(_ref) {
123
123
  }]
124
124
  })))));
125
125
  };
126
- DeleteForm.propTypes = propTypes$1;
127
- DeleteForm.defaultProps = defaultProps$1;
126
+ DeleteForm.propTypes = propTypes$2;
127
+ DeleteForm.defaultProps = defaultProps$2;
128
128
  var DeleteForm$1 = DeleteForm;
129
129
 
130
- var _excluded = ["component", "resource", "onSuccess", "item", "type", "isDelete"];
130
+ var _excluded$1 = ["resource", "action", "previous", "status", "value", "onSubmit", "errors", "generalError", "className"];
131
+ var propTypes$1 = {
132
+ resource: PropTypes.resource.isRequired,
133
+ action: PropTypes$1.string,
134
+ previous: PropTypes$1.string,
135
+ fields: PropTypes.fields.isRequired,
136
+ value: PropTypes$1.object,
137
+ // eslint-disable-line react/forbid-prop-types
138
+ onChange: PropTypes$1.func.isRequired,
139
+ onSubmit: PropTypes$1.func,
140
+ status: PropTypes.formStatus,
141
+ generalError: PropTypes$1.string,
142
+ errors: PropTypes$1.objectOf(PropTypes$1.arrayOf(PropTypes$1.string)),
143
+ className: PropTypes$1.string
144
+ };
145
+ var defaultProps$1 = {
146
+ action: null,
147
+ previous: null,
148
+ status: null,
149
+ value: null,
150
+ onSubmit: null,
151
+ generalError: null,
152
+ errors: null,
153
+ className: null
154
+ };
155
+ var DuplicateForm = function DuplicateForm(_ref) {
156
+ var resource = _ref.resource,
157
+ action = _ref.action,
158
+ previous = _ref.previous;
159
+ _ref.status;
160
+ var value = _ref.value,
161
+ onSubmit = _ref.onSubmit;
162
+ _ref.errors;
163
+ var generalError = _ref.generalError,
164
+ className = _ref.className,
165
+ props = _objectWithoutProperties(_ref, _excluded$1);
166
+ var _ref2 = value || {},
167
+ _ref2$id = _ref2.id,
168
+ id = _ref2$id === void 0 ? null : _ref2$id;
169
+ var resourceValues = useResourceValues(resource, {
170
+ id: id
171
+ });
172
+ return /*#__PURE__*/React.createElement(Form, Object.assign({
173
+ className: classNames(['form', _defineProperty({
174
+ 'invalid-feedback': generalError !== null
175
+ }, className, className !== null)]),
176
+ action: action,
177
+ onSubmit: onSubmit,
178
+ withoutActions: true,
179
+ withoutErrors: true
180
+ }, props), /*#__PURE__*/React.createElement("div", {
181
+ className: classNames(['card', _defineProperty({}, className, className !== null)])
182
+ }, /*#__PURE__*/React.createElement("div", {
183
+ className: "card-body"
184
+ }, /*#__PURE__*/React.createElement(FormattedMessage, {
185
+ values: resourceValues,
186
+ id: "ZhnMCD",
187
+ defaultMessage: [{
188
+ "type": 0,
189
+ "value": "Are you sure you want to duplicate "
190
+ }, {
191
+ "type": 1,
192
+ "value": "the_singular"
193
+ }, {
194
+ "type": 0,
195
+ "value": " #"
196
+ }, {
197
+ "type": 1,
198
+ "value": "id"
199
+ }, {
200
+ "type": 0,
201
+ "value": "?"
202
+ }]
203
+ }), generalError ? /*#__PURE__*/React.createElement("p", {
204
+ className: "text-danger"
205
+ }, /*#__PURE__*/React.createElement(FormattedMessage, {
206
+ id: "y9zauY",
207
+ defaultMessage: [{
208
+ "type": 0,
209
+ "value": "An error occured and we could not delete this item successfully."
210
+ }]
211
+ })) : null), /*#__PURE__*/React.createElement("div", {
212
+ className: "card-body d-flex"
213
+ }, previous !== null ? /*#__PURE__*/React.createElement(Button, {
214
+ href: previous,
215
+ className: "me-2",
216
+ theme: "secondary",
217
+ outline: true
218
+ }, /*#__PURE__*/React.createElement(FormattedMessage, {
219
+ id: "PyxZY2",
220
+ defaultMessage: [{
221
+ "type": 0,
222
+ "value": "Cancel"
223
+ }]
224
+ })) : null, /*#__PURE__*/React.createElement(Button, {
225
+ type: "submit",
226
+ className: "ms-auto",
227
+ theme: "warning"
228
+ }, /*#__PURE__*/React.createElement(FormattedMessage, {
229
+ id: "HzCxmr",
230
+ defaultMessage: [{
231
+ "type": 0,
232
+ "value": "Duplicate"
233
+ }]
234
+ })))));
235
+ };
236
+ DuplicateForm.propTypes = propTypes$1;
237
+ DuplicateForm.defaultProps = defaultProps$1;
238
+ var DuplicateForm$1 = DuplicateForm;
239
+
240
+ var _excluded = ["component", "resource", "onSuccess", "item", "type", "isDelete", "isDuplicate"];
131
241
  var propTypes = {
132
242
  resource: PropTypes.resource.isRequired,
133
243
  item: PropTypes$1.object,
@@ -135,14 +245,16 @@ var propTypes = {
135
245
  type: PropTypes$1.string,
136
246
  component: PropTypes$1.string,
137
247
  onSuccess: PropTypes$1.func,
138
- isDelete: PropTypes$1.bool
248
+ isDelete: PropTypes$1.bool,
249
+ isDuplicate: PropTypes$1.bool
139
250
  };
140
251
  var defaultProps = {
141
252
  item: null,
142
253
  type: null,
143
254
  component: null,
144
255
  onSuccess: null,
145
- isDelete: false
256
+ isDelete: false,
257
+ isDuplicate: false
146
258
  };
147
259
  var ResourceForm = function ResourceForm(_ref) {
148
260
  var component = _ref.component,
@@ -151,6 +263,7 @@ var ResourceForm = function ResourceForm(_ref) {
151
263
  item = _ref.item,
152
264
  type = _ref.type,
153
265
  isDelete = _ref.isDelete,
266
+ isDuplicate = _ref.isDuplicate,
154
267
  props = _objectWithoutProperties(_ref, _excluded);
155
268
  var locales = useLocales();
156
269
  var FormComponents = useFormsComponents();
@@ -232,12 +345,15 @@ var ResourceForm = function ResourceForm(_ref) {
232
345
  }, [setValueState]);
233
346
 
234
347
  // Form action
235
- var modifyAction = isCreate ? resourceRoute('store') : resourceRoute('update', {
348
+ var action = isCreate ? resourceRoute('store') : resourceRoute('update', {
236
349
  id: item.id
237
350
  });
238
- var action = isDelete ? resourceRoute('destroy', {
351
+ action = isDelete ? resourceRoute('destroy', {
352
+ id: item.id
353
+ }) : action;
354
+ action = isDuplicate ? resourceRoute('clone', {
239
355
  id: item.id
240
- }) : modifyAction;
356
+ }) : action;
241
357
  var _useForm = useForm({
242
358
  action: action,
243
359
  fields: finalFields,
@@ -252,10 +368,17 @@ var ResourceForm = function ResourceForm(_ref) {
252
368
  status = _useForm.status,
253
369
  generalError = _useForm.generalError,
254
370
  errors = _useForm.errors;
255
- var defaultFormName = isDelete ? component || formComponent || null : component || formComponent || defaultComponent || 'normal';
371
+ var defaultFormName = isDelete || isDuplicate ? component || formComponent || null : component || formComponent || defaultComponent || 'normal';
372
+ var finalComponent = component;
373
+ if (isDelete) {
374
+ finalComponent = DeleteForm$1;
375
+ }
376
+ if (isDuplicate) {
377
+ finalComponent = DuplicateForm$1;
378
+ }
256
379
 
257
380
  // Form component
258
- var FormComponent = getComponentFromName(defaultFormName, FormComponents, isDelete ? DeleteForm$1 : component);
381
+ var FormComponent = getComponentFromName(defaultFormName, FormComponents, finalComponent);
259
382
 
260
383
  // Listen to item value change - this is important
261
384
  useEffect(function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/form-resource",
3
- "version": "3.0.281",
3
+ "version": "3.0.283",
4
4
  "description": "Default resource forms",
5
5
  "keywords": [
6
6
  "javascript"
@@ -49,13 +49,13 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@babel/runtime": "^7.12.5",
52
- "@panneau/core": "^3.0.281",
53
- "@panneau/data": "^3.0.281",
54
- "@panneau/element-button": "^3.0.281",
55
- "@panneau/element-form": "^3.0.281",
56
- "@panneau/field-fields": "^3.0.281",
57
- "@panneau/intl": "^3.0.281",
58
- "@panneau/themes": "^3.0.281",
52
+ "@panneau/core": "^3.0.283",
53
+ "@panneau/data": "^3.0.283",
54
+ "@panneau/element-button": "^3.0.283",
55
+ "@panneau/element-form": "^3.0.283",
56
+ "@panneau/field-fields": "^3.0.283",
57
+ "@panneau/intl": "^3.0.283",
58
+ "@panneau/themes": "^3.0.283",
59
59
  "classnames": "^2.5.1",
60
60
  "lodash-es": "^4.17.21",
61
61
  "prop-types": "^15.7.2",
@@ -64,5 +64,5 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "cd0e6200af7c6f27d6e41acd13a8aba548dffd91"
67
+ "gitHead": "7295ec0fa362a586252e5ff6fa3a01717c84e2d1"
68
68
  }