cozy-ui 138.12.0 → 138.13.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [138.13.1](https://github.com/cozy/cozy-ui/compare/v138.13.0...v138.13.1) (2026-05-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Allow absence of success or error callback for useSubmitWithLoader ([f8f902c](https://github.com/cozy/cozy-ui/commit/f8f902c))
7
+
8
+ # [138.13.0](https://github.com/cozy/cozy-ui/compare/v138.12.0...v138.13.0) (2026-05-28)
9
+
10
+
11
+ ### Features
12
+
13
+ * Add hook to submit with a loader ([ff36c73](https://github.com/cozy/cozy-ui/commit/ff36c73))
14
+
1
15
  # [138.12.0](https://github.com/cozy/cozy-ui/compare/v138.11.0...v138.12.0) (2026-05-13)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "138.12.0",
3
+ "version": "138.13.1",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -0,0 +1,37 @@
1
+ import { useState } from 'react'
2
+ import { useI18n } from 'twake-i18n'
3
+
4
+ import { useAlert } from '../../providers/Alert'
5
+
6
+ export const useSubmitWithLoader = () => {
7
+ const [isLoading, setIsLoading] = useState(false)
8
+ const { showAlert } = useAlert()
9
+ const { t } = useI18n()
10
+
11
+ const onSubmit = async ({ submit, success, error }) => {
12
+ setIsLoading(true)
13
+
14
+ try {
15
+ await submit()
16
+
17
+ showAlert({
18
+ severity: 'success',
19
+ message: success?.message || t('useSubmitWithLoader.success')
20
+ })
21
+
22
+ success?.action?.()
23
+ } catch (e) {
24
+ showAlert({
25
+ severity: 'error',
26
+ message:
27
+ error?.message?.(e) || t('useSubmitWithLoader.error', { error })
28
+ })
29
+
30
+ error?.action?.()
31
+ } finally {
32
+ setIsLoading(false)
33
+ }
34
+ }
35
+
36
+ return { onSubmit, isLoading }
37
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "useSubmitWithLoader": {
3
+ "success": "Success!",
4
+ "error": "An error occured %{error}"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "useSubmitWithLoader": {
3
+ "success": "Succès !",
4
+ "error": "Une erreur est survenue %{error}"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "useSubmitWithLoader": {
3
+ "success": "Успешно!",
4
+ "error": "Произошла ошибка %{error}"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "useSubmitWithLoader": {
3
+ "success": "Thành công!",
4
+ "error": "Đã xảy ra lỗi %{error}"
5
+ }
6
+ }
@@ -0,0 +1,8 @@
1
+ export function useSubmitWithLoader(): {
2
+ onSubmit: ({ submit, success, error }: {
3
+ submit: any;
4
+ success: any;
5
+ error: any;
6
+ }) => Promise<void>;
7
+ isLoading: boolean;
8
+ };
@@ -0,0 +1,75 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import { useState } from 'react';
5
+ import { useI18n } from 'twake-i18n';
6
+ import { useAlert } from "cozy-ui/transpiled/react/providers/Alert";
7
+ export var useSubmitWithLoader = function useSubmitWithLoader() {
8
+ var _useState = useState(false),
9
+ _useState2 = _slicedToArray(_useState, 2),
10
+ isLoading = _useState2[0],
11
+ setIsLoading = _useState2[1];
12
+
13
+ var _useAlert = useAlert(),
14
+ showAlert = _useAlert.showAlert;
15
+
16
+ var _useI18n = useI18n(),
17
+ t = _useI18n.t;
18
+
19
+ var onSubmit = /*#__PURE__*/function () {
20
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
21
+ var submit, success, error, _success$action, _error$message, _error$action;
22
+
23
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
24
+ while (1) {
25
+ switch (_context.prev = _context.next) {
26
+ case 0:
27
+ submit = _ref.submit, success = _ref.success, error = _ref.error;
28
+ setIsLoading(true);
29
+ _context.prev = 2;
30
+ _context.next = 5;
31
+ return submit();
32
+
33
+ case 5:
34
+ showAlert({
35
+ severity: 'success',
36
+ message: (success === null || success === void 0 ? void 0 : success.message) || t('useSubmitWithLoader.success')
37
+ });
38
+ success === null || success === void 0 ? void 0 : (_success$action = success.action) === null || _success$action === void 0 ? void 0 : _success$action.call(success);
39
+ _context.next = 13;
40
+ break;
41
+
42
+ case 9:
43
+ _context.prev = 9;
44
+ _context.t0 = _context["catch"](2);
45
+ showAlert({
46
+ severity: 'error',
47
+ message: (error === null || error === void 0 ? void 0 : (_error$message = error.message) === null || _error$message === void 0 ? void 0 : _error$message.call(error, _context.t0)) || t('useSubmitWithLoader.error', {
48
+ error: error
49
+ })
50
+ });
51
+ error === null || error === void 0 ? void 0 : (_error$action = error.action) === null || _error$action === void 0 ? void 0 : _error$action.call(error);
52
+
53
+ case 13:
54
+ _context.prev = 13;
55
+ setIsLoading(false);
56
+ return _context.finish(13);
57
+
58
+ case 16:
59
+ case "end":
60
+ return _context.stop();
61
+ }
62
+ }
63
+ }, _callee, null, [[2, 9, 13, 16]]);
64
+ }));
65
+
66
+ return function onSubmit(_x) {
67
+ return _ref2.apply(this, arguments);
68
+ };
69
+ }();
70
+
71
+ return {
72
+ onSubmit: onSubmit,
73
+ isLoading: isLoading
74
+ };
75
+ };