cozy-sharing 11.0.1 → 12.0.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 (69) hide show
  1. package/.storybook/preview.jsx +11 -5
  2. package/CHANGELOG.md +31 -0
  3. package/dist/SharingProvider.js +111 -62
  4. package/dist/components/Avatar/GroupAvatar.js +13 -0
  5. package/dist/components/Avatar/GroupAvatar.stories.js +10 -0
  6. package/dist/components/Recipient/GroupRecipient.js +49 -0
  7. package/dist/components/Recipient/GroupRecipient.stories.js +41 -0
  8. package/dist/components/Recipient/GroupRecipientPermissions.js +133 -0
  9. package/dist/components/Recipient/GroupRecipientPermissions.stories.js +37 -0
  10. package/dist/components/Recipient/MemberRecipient.stories.js +11 -1
  11. package/dist/components/Recipient/MemberRecipientPermissions.js +31 -40
  12. package/dist/components/Recipient/MemberRecipientPermissions.stories.js +30 -4
  13. package/dist/components/Recipient/RecipientList.js +16 -1
  14. package/dist/components/Recipient/RecipientList.stories.js +28 -0
  15. package/dist/components/Recipient/actions/permission.js +30 -0
  16. package/dist/components/Recipient/actions/revokeGroup.js +41 -0
  17. package/dist/components/Recipient/actions/revokeMember.js +41 -0
  18. package/dist/components/ShareByEmail.js +8 -29
  19. package/dist/components/ShareByEmail.spec.js +1 -1
  20. package/dist/components/ShareDialogCozyToCozy.js +2 -2
  21. package/dist/components/ShareDialogCozyToCozy.spec.js +1 -1
  22. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +2 -2
  23. package/dist/components/ShareDialogTwoStepsConfirmationContainer.spec.js +1 -1
  24. package/dist/components/ShareModal/EditableSharingModal.js +43 -42
  25. package/dist/components/ShareModal/EditableSharingModal.spec.js +2 -2
  26. package/dist/components/ShareModal.js +4 -4
  27. package/dist/components/ShareRecipientsInput.js +7 -7
  28. package/dist/components/ShareRecipientsInput.spec.js +2 -2
  29. package/dist/helpers/recipients.js +38 -0
  30. package/dist/helpers/successMessage.spec.js +1 -1
  31. package/dist/propTypes.js +1 -1
  32. package/dist/queries/queries.js +1 -1
  33. package/dist/state.js +85 -2
  34. package/dist/state.spec.js +190 -10
  35. package/locales/en.json +24 -30
  36. package/locales/fr.json +24 -30
  37. package/package.json +5 -5
  38. package/src/SharingProvider.jsx +15 -0
  39. package/src/components/Avatar/GroupAvatar.jsx +10 -0
  40. package/src/components/Avatar/GroupAvatar.stories.jsx +13 -0
  41. package/src/components/Recipient/GroupRecipient.jsx +56 -0
  42. package/src/components/Recipient/GroupRecipient.stories.jsx +38 -0
  43. package/src/components/Recipient/GroupRecipientPermissions.jsx +106 -0
  44. package/src/components/Recipient/GroupRecipientPermissions.stories.jsx +41 -0
  45. package/src/components/Recipient/MemberRecipient.stories.jsx +12 -1
  46. package/src/components/Recipient/MemberRecipientPermissions.jsx +37 -53
  47. package/src/components/Recipient/MemberRecipientPermissions.stories.jsx +31 -4
  48. package/src/components/Recipient/RecipientList.jsx +18 -1
  49. package/src/components/Recipient/RecipientList.stories.jsx +34 -0
  50. package/src/components/Recipient/actions/permission.js +28 -0
  51. package/src/components/Recipient/actions/revokeGroup.js +39 -0
  52. package/src/components/Recipient/actions/revokeMember.js +39 -0
  53. package/src/components/ShareByEmail.jsx +14 -32
  54. package/src/components/ShareByEmail.spec.jsx +1 -1
  55. package/src/components/ShareDialogCozyToCozy.jsx +2 -2
  56. package/src/components/ShareDialogCozyToCozy.spec.jsx +1 -1
  57. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +2 -2
  58. package/src/components/ShareDialogTwoStepsConfirmationContainer.spec.jsx +1 -1
  59. package/src/components/ShareModal/EditableSharingModal.jsx +48 -46
  60. package/src/components/ShareModal/EditableSharingModal.spec.jsx +1 -1
  61. package/src/components/ShareModal.jsx +4 -4
  62. package/src/components/ShareRecipientsInput.jsx +9 -9
  63. package/src/components/ShareRecipientsInput.spec.jsx +2 -2
  64. package/src/helpers/recipients.js +45 -0
  65. package/src/helpers/successMessage.spec.js +1 -1
  66. package/src/propTypes.js +1 -1
  67. package/src/queries/queries.js +1 -1
  68. package/src/state.js +81 -2
  69. package/src/state.spec.js +230 -9
@@ -10,6 +10,7 @@ import CozyTheme from 'cozy-ui/transpiled/react/providers/CozyTheme'
10
10
  import { CozyProvider, createFakeClient } from 'cozy-client'
11
11
 
12
12
  import enLocale from '../locales/en.json'
13
+ import SharingContext from "../src/context";
13
14
 
14
15
  const preview = {
15
16
  decorators: [
@@ -40,11 +41,16 @@ const preview = {
40
41
  <CozyProvider client={fakeClient}>
41
42
  <CozyTheme>
42
43
  <BreakpointsProvider>
43
- <I18n lang="en" dictRequire={() => enLocale}>
44
- <div style={{position: "relative"}}>
45
- <Story />
46
- </div>
47
- </I18n>
44
+ <SharingContext.Provider value={{
45
+ revokeGroup: () => {},
46
+ revokeSelf: () => {}
47
+ }}>
48
+ <I18n lang="en" dictRequire={() => enLocale}>
49
+ <div style={{position: "relative"}}>
50
+ <Story />
51
+ </div>
52
+ </I18n>
53
+ </SharingContext.Provider>
48
54
  </BreakpointsProvider>
49
55
  </CozyTheme>
50
56
  </CozyProvider>
package/CHANGELOG.md CHANGED
@@ -3,6 +3,37 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [12.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@11.1.0...cozy-sharing@12.0.0) (2024-03-21)
7
+
8
+
9
+ ### Features
10
+
11
+ * Making it possible to revoke a group ([cc3e998](https://github.com/cozy/cozy-libs/commit/cc3e998d94450d0698373f217a4eea06d1a81ede))
12
+ * Update cozy-client from 45.14.0 to 46.1.0 ([958c55c](https://github.com/cozy/cozy-libs/commit/958c55c5d55a540d0c5b341b6780cb16b1617ff9))
13
+
14
+
15
+ ### BREAKING CHANGES
16
+
17
+ * you must have `cozy-client >=46.1.0`
18
+
19
+
20
+
21
+
22
+
23
+ # [11.1.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@11.0.1...cozy-sharing@11.1.0) (2024-03-21)
24
+
25
+
26
+ ### Features
27
+
28
+ * Add groups to recipients ([4be590d](https://github.com/cozy/cozy-libs/commit/4be590d8280fe9198fb56d32d2ff55665864e746))
29
+ * Add groups to recipients if flag ([4ac2199](https://github.com/cozy/cozy-libs/commit/4ac21990174d1312ee8d5b452e524db6c53429a9))
30
+ * Extract logic from onRecipientPick to an helper ([2d08da1](https://github.com/cozy/cozy-libs/commit/2d08da1fb5a767819d8d89bd3e59f8d9927cceea))
31
+ * **RecipientList:** Show recipient groups ([60d155c](https://github.com/cozy/cozy-libs/commit/60d155c53702782863a777c649e786deeb64a314))
32
+
33
+
34
+
35
+
36
+
6
37
  ## [11.0.1](https://github.com/cozy/cozy-libs/compare/cozy-sharing@11.0.0...cozy-sharing@11.0.1) (2024-03-12)
7
38
 
8
39
 
@@ -39,7 +39,7 @@ import { fetchFilesPaths } from './helpers/files';
39
39
  import { getSharingObject, createSharingInStore, updateSharingInStore } from './helpers/sharings';
40
40
  import { SynchronousJobQueue } from './helpers/synchronousJobQueue';
41
41
  import { fetchApps } from './queries/queries';
42
- import reducer, { receiveSharings, addSharing, updateSharing, addSharingLink, updateSharingLink, revokeSharingLink, revokeRecipient, revokeSelf, receivePaths, isOwner as _isOwner, canReshare as _canReshare, getOwner as _getOwner, getRecipients as _getRecipients, getSharingById, getExternalSharingIds, getSharingForSelf as _getSharingForSelf, getSharingType as _getSharingType, getSharingLink as _getSharingLink, getSharedDocIdsBySharings, getDocumentSharing, getDocumentPermissions as _getDocumentPermissions, hasSharedParent as _hasSharedParent, hasSharedChild as _hasSharedChild, getSharedParentPath as _getSharedParentPath } from './state';
42
+ import reducer, { receiveSharings, addSharing, updateSharing, addSharingLink, updateSharingLink, revokeSharingLink, revokeRecipient, revokeGroup as revokeGroupFromState, revokeSelf, receivePaths, isOwner as _isOwner, canReshare as _canReshare, getOwner as _getOwner, getRecipients as _getRecipients, getSharingById, getExternalSharingIds, getSharingForSelf as _getSharingForSelf, getSharingType as _getSharingType, getSharingLink as _getSharingLink, getSharedDocIdsBySharings, getDocumentSharing, getDocumentPermissions as _getDocumentPermissions, hasSharedParent as _hasSharedParent, hasSharedChild as _hasSharedChild, getSharedParentPath as _getSharedParentPath } from './state';
43
43
  var SHARING_DOCTYPE = 'io.cozy.sharings';
44
44
  var PERMISSION_DOCTYPE = 'io.cozy.permissions';
45
45
  export var SharingProvider = /*#__PURE__*/function (_Component) {
@@ -359,14 +359,62 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
359
359
  };
360
360
  }());
361
361
 
362
- _defineProperty(_assertThisInitialized(_this), "revokeSelf", /*#__PURE__*/function () {
363
- var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(document) {
364
- var sharing;
362
+ _defineProperty(_assertThisInitialized(_this), "revokeGroup", /*#__PURE__*/function () {
363
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(document, sharingId, recipientIndex) {
364
+ var _this$props5, client, doctype, sharing;
365
+
365
366
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
366
367
  while (1) switch (_context7.prev = _context7.next) {
368
+ case 0:
369
+ _this$props5 = _this.props, client = _this$props5.client, doctype = _this$props5.doctype;
370
+ sharing = getSharingById(_this.state, sharingId);
371
+ _context7.next = 4;
372
+ return _this.sharingCol.revokeGroup(sharing, recipientIndex);
373
+
374
+ case 4:
375
+ _context7.t0 = _this;
376
+ _context7.t1 = revokeGroupFromState;
377
+ _context7.t2 = sharing;
378
+ _context7.t3 = recipientIndex;
379
+ _context7.t4 = document.path;
380
+
381
+ if (_context7.t4) {
382
+ _context7.next = 13;
383
+ break;
384
+ }
385
+
386
+ _context7.next = 12;
387
+ return fetchFilesPaths(client, doctype, [document]);
388
+
389
+ case 12:
390
+ _context7.t4 = _context7.sent;
391
+
392
+ case 13:
393
+ _context7.t5 = _context7.t4;
394
+ _context7.t6 = (0, _context7.t1)(_context7.t2, _context7.t3, _context7.t5);
395
+
396
+ _context7.t0.dispatch.call(_context7.t0, _context7.t6);
397
+
398
+ case 16:
399
+ case "end":
400
+ return _context7.stop();
401
+ }
402
+ }, _callee7);
403
+ }));
404
+
405
+ return function (_x10, _x11, _x12) {
406
+ return _ref9.apply(this, arguments);
407
+ };
408
+ }());
409
+
410
+ _defineProperty(_assertThisInitialized(_this), "revokeSelf", /*#__PURE__*/function () {
411
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(document) {
412
+ var sharing;
413
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
414
+ while (1) switch (_context8.prev = _context8.next) {
367
415
  case 0:
368
416
  sharing = _getSharingForSelf(_this.state, document.id);
369
- _context7.next = 3;
417
+ _context8.next = 3;
370
418
  return _this.sharingCol.revokeSelf(sharing);
371
419
 
372
420
  case 3:
@@ -374,41 +422,41 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
374
422
 
375
423
  case 4:
376
424
  case "end":
377
- return _context7.stop();
425
+ return _context8.stop();
378
426
  }
379
- }, _callee7);
427
+ }, _callee8);
380
428
  }));
381
429
 
382
- return function (_x10) {
383
- return _ref9.apply(this, arguments);
430
+ return function (_x13) {
431
+ return _ref10.apply(this, arguments);
384
432
  };
385
433
  }());
386
434
 
387
435
  _defineProperty(_assertThisInitialized(_this), "shareByLink", /*#__PURE__*/function () {
388
- var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(document, options) {
436
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(document, options) {
389
437
  var resp;
390
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
391
- while (1) switch (_context8.prev = _context8.next) {
438
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
439
+ while (1) switch (_context9.prev = _context9.next) {
392
440
  case 0:
393
- _context8.next = 2;
441
+ _context9.next = 2;
394
442
  return _this.permissionCol.createSharingLink(document, options);
395
443
 
396
444
  case 2:
397
- resp = _context8.sent;
445
+ resp = _context9.sent;
398
446
 
399
447
  _this.dispatch(addSharingLink(resp.data));
400
448
 
401
- return _context8.abrupt("return", resp);
449
+ return _context9.abrupt("return", resp);
402
450
 
403
451
  case 5:
404
452
  case "end":
405
- return _context8.stop();
453
+ return _context9.stop();
406
454
  }
407
- }, _callee8);
455
+ }, _callee9);
408
456
  }));
409
457
 
410
- return function (_x11, _x12) {
411
- return _ref10.apply(this, arguments);
458
+ return function (_x14, _x15) {
459
+ return _ref11.apply(this, arguments);
412
460
  };
413
461
  }());
414
462
 
@@ -421,71 +469,71 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
421
469
  * @return {Array}
422
470
  */
423
471
  _defineProperty(_assertThisInitialized(_this), "updateDocumentPermissions", /*#__PURE__*/function () {
424
- var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(document, newVerbs) {
472
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(document, newVerbs) {
425
473
  var permissions, responses;
426
- return _regeneratorRuntime.wrap(function _callee10$(_context10) {
427
- while (1) switch (_context10.prev = _context10.next) {
474
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
475
+ while (1) switch (_context11.prev = _context11.next) {
428
476
  case 0:
429
477
  permissions = _getDocumentPermissions(_this.state, document.id);
430
- _context10.next = 3;
478
+ _context11.next = 3;
431
479
  return Promise.all(permissions.map( /*#__PURE__*/function () {
432
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(permissionDocument) {
480
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(permissionDocument) {
433
481
  var updatedPermissions, resp;
434
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
435
- while (1) switch (_context9.prev = _context9.next) {
482
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
483
+ while (1) switch (_context10.prev = _context10.next) {
436
484
  case 0:
437
485
  updatedPermissions = permissionDocument.attributes.permissions;
438
486
  Object.keys(updatedPermissions).map(function (permType) {
439
487
  updatedPermissions[permType].verbs = newVerbs;
440
488
  });
441
- _context9.next = 4;
489
+ _context10.next = 4;
442
490
  return _this.permissionCol.add(permissionDocument, updatedPermissions);
443
491
 
444
492
  case 4:
445
- resp = _context9.sent;
493
+ resp = _context10.sent;
446
494
 
447
495
  _this.dispatch(updateSharingLink(resp));
448
496
 
449
- return _context9.abrupt("return", resp);
497
+ return _context10.abrupt("return", resp);
450
498
 
451
499
  case 7:
452
500
  case "end":
453
- return _context9.stop();
501
+ return _context10.stop();
454
502
  }
455
- }, _callee9);
503
+ }, _callee10);
456
504
  }));
457
505
 
458
- return function (_x15) {
459
- return _ref12.apply(this, arguments);
506
+ return function (_x18) {
507
+ return _ref13.apply(this, arguments);
460
508
  };
461
509
  }()));
462
510
 
463
511
  case 3:
464
- responses = _context10.sent;
465
- return _context10.abrupt("return", responses);
512
+ responses = _context11.sent;
513
+ return _context11.abrupt("return", responses);
466
514
 
467
515
  case 5:
468
516
  case "end":
469
- return _context10.stop();
517
+ return _context11.stop();
470
518
  }
471
- }, _callee10);
519
+ }, _callee11);
472
520
  }));
473
521
 
474
- return function (_x13, _x14) {
475
- return _ref11.apply(this, arguments);
522
+ return function (_x16, _x17) {
523
+ return _ref12.apply(this, arguments);
476
524
  };
477
525
  }());
478
526
 
479
527
  _defineProperty(_assertThisInitialized(_this), "revokeSharingLink", /*#__PURE__*/function () {
480
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(document) {
528
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(document) {
481
529
  var perms;
482
- return _regeneratorRuntime.wrap(function _callee11$(_context11) {
483
- while (1) switch (_context11.prev = _context11.next) {
530
+ return _regeneratorRuntime.wrap(function _callee12$(_context12) {
531
+ while (1) switch (_context12.prev = _context12.next) {
484
532
  case 0:
485
533
  // Because some duplicate links have been created in the past, we must ensure
486
534
  // we revoke all of them
487
535
  perms = _getDocumentPermissions(_this.state, document.id);
488
- _context11.next = 3;
536
+ _context12.next = 3;
489
537
  return Promise.all(perms.map(function (p) {
490
538
  return _this.permissionCol.destroy(p);
491
539
  }));
@@ -495,13 +543,13 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
495
543
 
496
544
  case 4:
497
545
  case "end":
498
- return _context11.stop();
546
+ return _context12.stop();
499
547
  }
500
- }, _callee11);
548
+ }, _callee12);
501
549
  }));
502
550
 
503
- return function (_x16) {
504
- return _ref13.apply(this, arguments);
551
+ return function (_x19) {
552
+ return _ref14.apply(this, arguments);
505
553
  };
506
554
  }());
507
555
 
@@ -558,6 +606,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
558
606
  share: _this.share,
559
607
  onShared: onShared,
560
608
  revoke: _this.revoke,
609
+ revokeGroup: _this.revokeGroup,
561
610
  revokeSelf: _this.revokeSelf,
562
611
  shareByLink: _this.shareByLink,
563
612
  updateDocumentPermissions: _this.updateDocumentPermissions,
@@ -600,18 +649,18 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
600
649
  }, {
601
650
  key: "fetchAllSharings",
602
651
  value: function () {
603
- var _fetchAllSharings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
604
- var _this$props5, doctype, client, _yield$Promise$all, _yield$Promise$all2, sharings, permissions, apps, sharedDocIds, resp, folderPaths, filePaths;
652
+ var _fetchAllSharings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
653
+ var _this$props6, doctype, client, _yield$Promise$all, _yield$Promise$all2, sharings, permissions, apps, sharedDocIds, resp, folderPaths, filePaths;
605
654
 
606
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
607
- while (1) switch (_context12.prev = _context12.next) {
655
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
656
+ while (1) switch (_context13.prev = _context13.next) {
608
657
  case 0:
609
- _this$props5 = this.props, doctype = _this$props5.doctype, client = _this$props5.client;
610
- _context12.next = 3;
658
+ _this$props6 = this.props, doctype = _this$props6.doctype, client = _this$props6.client;
659
+ _context13.next = 3;
611
660
  return Promise.all([this.sharingCol.findByDoctype(doctype), this.permissionCol.findLinksByDoctype(doctype), client.fetchQueryAndGetFromState(fetchApps())]);
612
661
 
613
662
  case 3:
614
- _yield$Promise$all = _context12.sent;
663
+ _yield$Promise$all = _context13.sent;
615
664
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
616
665
  sharings = _yield$Promise$all2[0];
617
666
  permissions = _yield$Promise$all2[1];
@@ -626,35 +675,35 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
626
675
  hasLoadedAtLeastOnePage: true
627
676
  }); // eslint-disable-next-line promise/catch-or-return
628
677
 
629
- _context12.next = 12;
678
+ _context13.next = 12;
630
679
  return fetchNextPermissions(permissions, this.dispatch, this.permissionCol);
631
680
 
632
681
  case 12:
633
682
  if (!(doctype === 'io.cozy.files')) {
634
- _context12.next = 22;
683
+ _context13.next = 22;
635
684
  break;
636
685
  }
637
686
 
638
687
  sharedDocIds = getSharedDocIdsBySharings(sharings);
639
- _context12.next = 16;
688
+ _context13.next = 16;
640
689
  return client.collection(doctype).all({
641
690
  keys: sharedDocIds
642
691
  });
643
692
 
644
693
  case 16:
645
- resp = _context12.sent;
694
+ resp = _context13.sent;
646
695
  folderPaths = resp.data.filter(function (f) {
647
696
  return f.type === 'directory' && !f.trashed;
648
697
  }).map(function (f) {
649
698
  return f.path;
650
699
  });
651
- _context12.next = 20;
700
+ _context13.next = 20;
652
701
  return fetchFilesPaths(client, doctype, resp.data.filter(function (f) {
653
702
  return f.type !== 'directory' && !f.trashed;
654
703
  }));
655
704
 
656
705
  case 20:
657
- filePaths = _context12.sent;
706
+ filePaths = _context13.sent;
658
707
  this.dispatch(receivePaths([].concat(_toConsumableArray(folderPaths), _toConsumableArray(filePaths))));
659
708
 
660
709
  case 22:
@@ -664,9 +713,9 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
664
713
 
665
714
  case 23:
666
715
  case "end":
667
- return _context12.stop();
716
+ return _context13.stop();
668
717
  }
669
- }, _callee12, this);
718
+ }, _callee13, this);
670
719
  }));
671
720
 
672
721
  function fetchAllSharings() {
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import Avatar from 'cozy-ui/transpiled/react/Avatar';
3
+ import TeamIcon from 'cozy-ui/transpiled/react/Icons/Team';
4
+
5
+ var GroupAvatar = function GroupAvatar(_ref) {
6
+ var size = _ref.size;
7
+ return /*#__PURE__*/React.createElement(Avatar, {
8
+ icon: TeamIcon,
9
+ size: size
10
+ });
11
+ };
12
+
13
+ export { GroupAvatar };
@@ -0,0 +1,10 @@
1
+ import { GroupAvatar } from './GroupAvatar';
2
+ var meta = {
3
+ component: GroupAvatar,
4
+ args: {}
5
+ };
6
+ export default meta;
7
+ export var Default = {
8
+ name: 'Default',
9
+ args: {}
10
+ };
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { useClient } from 'cozy-client';
3
+ import Fade from 'cozy-ui/transpiled/react/Fade';
4
+ import ListItem from 'cozy-ui/transpiled/react/ListItem';
5
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
6
+ import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryAction';
7
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
8
+ import Typography from 'cozy-ui/transpiled/react/Typography';
9
+ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
10
+ import { GroupRecipientPermissions } from './GroupRecipientPermissions';
11
+ import { FADE_IN_DURATION } from '../../helpers/recipients';
12
+ import { GroupAvatar } from '../Avatar/GroupAvatar';
13
+
14
+ var GroupRecipient = function GroupRecipient(props) {
15
+ var name = props.name,
16
+ members = props.members,
17
+ fadeIn = props.fadeIn;
18
+
19
+ var _useI18n = useI18n(),
20
+ t = _useI18n.t;
21
+
22
+ var client = useClient();
23
+ var nbMember = members.length;
24
+ var nbMemberReady = members.filter(function (member) {
25
+ return !['revoked', 'mail-not-sent'].includes(member.status);
26
+ }).length;
27
+ var isCurrentInstanceInsideMembers = members.some(function (member) {
28
+ return member.instance === client.options.uri;
29
+ });
30
+ return /*#__PURE__*/React.createElement(Fade, {
31
+ in: true,
32
+ timeout: fadeIn ? FADE_IN_DURATION : 0
33
+ }, /*#__PURE__*/React.createElement(ListItem, {
34
+ disableGutters: true
35
+ }, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(GroupAvatar, {
36
+ size: "small"
37
+ })), /*#__PURE__*/React.createElement(ListItemText, {
38
+ primary: /*#__PURE__*/React.createElement(Typography, {
39
+ className: "u-ellipsis",
40
+ variant: "body1"
41
+ }, name),
42
+ secondary: t('GroupRecipient.secondary', {
43
+ nbMember: nbMember,
44
+ nbMemberReady: nbMemberReady
45
+ }) + (isCurrentInstanceInsideMembers ? " (".concat(t('GroupRecipient.secondary_you'), ")") : '')
46
+ }), /*#__PURE__*/React.createElement(ListItemSecondaryAction, null, /*#__PURE__*/React.createElement(GroupRecipientPermissions, props))));
47
+ };
48
+
49
+ export { GroupRecipient };
@@ -0,0 +1,41 @@
1
+ import { GroupRecipient } from './GroupRecipient';
2
+ var meta = {
3
+ component: GroupRecipient,
4
+ args: {
5
+ name: 'Family',
6
+ isOwner: true,
7
+ read_only: false,
8
+ members: [{
9
+ status: 'ready'
10
+ }, {
11
+ status: 'mail-not-sent'
12
+ }, {
13
+ status: 'pending'
14
+ }, {
15
+ status: 'revoked'
16
+ }],
17
+ groupIndex: 0
18
+ }
19
+ };
20
+ export default meta;
21
+ export var Default = {
22
+ name: 'Default',
23
+ args: {}
24
+ };
25
+ export var InstanceInsideMembers = {
26
+ name: 'Instance inside members',
27
+ args: {
28
+ isOwner: false,
29
+ instance: 'http://alice.cozy.localhost:8080',
30
+ members: [{
31
+ status: 'ready',
32
+ instance: 'http://alice.cozy.localhost:8080'
33
+ }, {
34
+ status: 'mail-not-sent'
35
+ }, {
36
+ status: 'pending'
37
+ }, {
38
+ status: 'revoked'
39
+ }]
40
+ }
41
+ };
@@ -0,0 +1,133 @@
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 React, { useState, useRef } from 'react';
5
+ import { useClient } from 'cozy-client';
6
+ import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu';
7
+ import { makeActions, divider } from 'cozy-ui/transpiled/react/ActionsMenu/Actions';
8
+ import ActionsMenuMobileHeader from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuMobileHeader';
9
+ import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton';
10
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
11
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
12
+ import Spinner from 'cozy-ui/transpiled/react/Spinner';
13
+ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
14
+ import { permission } from './actions/permission';
15
+ import { revokeGroup as revokeGroupAction } from './actions/revokeGroup';
16
+ import { useSharingContext } from '../../hooks/useSharingContext';
17
+ import { GroupAvatar } from '../Avatar/GroupAvatar';
18
+
19
+ var GroupRecipientPermissions = function GroupRecipientPermissions(_ref) {
20
+ var name = _ref.name,
21
+ isOwner = _ref.isOwner,
22
+ instance = _ref.instance,
23
+ sharingId = _ref.sharingId,
24
+ groupIndex = _ref.groupIndex,
25
+ _ref$read_only = _ref.read_only,
26
+ isReadOnly = _ref$read_only === void 0 ? false : _ref$read_only,
27
+ className = _ref.className;
28
+
29
+ var _useI18n = useI18n(),
30
+ t = _useI18n.t;
31
+
32
+ var buttonRef = useRef();
33
+ var client = useClient();
34
+
35
+ var _useSharingContext = useSharingContext(),
36
+ revokeGroup = _useSharingContext.revokeGroup,
37
+ revokeSelf = _useSharingContext.revokeSelf;
38
+
39
+ var _useState = useState(false),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ isMenuDisplayed = _useState2[0],
42
+ setMenuDisplayed = _useState2[1];
43
+
44
+ var _useState3 = useState(false),
45
+ _useState4 = _slicedToArray(_useState3, 2),
46
+ revoking = _useState4[0],
47
+ setRevoking = _useState4[1];
48
+
49
+ var instanceMatchesClient = instance !== undefined && instance === client.options.uri;
50
+ var shouldShowMenu = !revoking && (instanceMatchesClient && !isOwner || isOwner);
51
+
52
+ var toggleMenu = function toggleMenu() {
53
+ return setMenuDisplayed(!isMenuDisplayed);
54
+ };
55
+
56
+ var hideMenu = function hideMenu() {
57
+ return setMenuDisplayed(false);
58
+ };
59
+
60
+ var handleRevocation = /*#__PURE__*/function () {
61
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
62
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
63
+ while (1) switch (_context.prev = _context.next) {
64
+ case 0:
65
+ setRevoking(true);
66
+
67
+ if (!isOwner) {
68
+ _context.next = 6;
69
+ break;
70
+ }
71
+
72
+ _context.next = 4;
73
+ return revokeGroup(document, sharingId, groupIndex);
74
+
75
+ case 4:
76
+ _context.next = 8;
77
+ break;
78
+
79
+ case 6:
80
+ _context.next = 8;
81
+ return revokeSelf(document);
82
+
83
+ case 8:
84
+ setRevoking(false);
85
+
86
+ case 9:
87
+ case "end":
88
+ return _context.stop();
89
+ }
90
+ }, _callee);
91
+ }));
92
+
93
+ return function handleRevocation() {
94
+ return _ref2.apply(this, arguments);
95
+ };
96
+ }();
97
+
98
+ var type = isReadOnly ? 'one-way' : 'two-way';
99
+ var actions = makeActions([permission, divider, revokeGroupAction], {
100
+ t: t,
101
+ type: type,
102
+ isOwner: isOwner,
103
+ handleRevocation: handleRevocation
104
+ });
105
+ return /*#__PURE__*/React.createElement("div", {
106
+ className: className
107
+ }, revoking && /*#__PURE__*/React.createElement(Spinner, null), shouldShowMenu && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DropdownButton, {
108
+ ref: buttonRef,
109
+ "aria-controls": "simple-menu",
110
+ "aria-haspopup": "true",
111
+ onClick: toggleMenu,
112
+ textVariant: "body2"
113
+ }, t("Share.type.".concat(type)).toLowerCase()), /*#__PURE__*/React.createElement(ActionsMenu, {
114
+ ref: buttonRef,
115
+ open: isMenuDisplayed,
116
+ actions: actions,
117
+ anchorOrigin: {
118
+ vertical: 'bottom',
119
+ horizontal: 'right'
120
+ },
121
+ autoClose: true,
122
+ onClose: hideMenu
123
+ }, /*#__PURE__*/React.createElement(ActionsMenuMobileHeader, null, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(GroupAvatar, {
124
+ size: "small"
125
+ })), /*#__PURE__*/React.createElement(ListItemText, {
126
+ primary: name,
127
+ primaryTypographyProps: {
128
+ variant: 'h6'
129
+ }
130
+ })))));
131
+ };
132
+
133
+ export { GroupRecipientPermissions };