cozy-sharing 31.1.0 → 32.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 (65) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/components/FederatedFolder/DumbFederatedFolderModal.js +15 -16
  3. package/dist/components/FederatedFolder/FederatedFolderModal.js +78 -103
  4. package/dist/components/FederatedFolder/FederatedFolderModal.spec.js +102 -292
  5. package/dist/components/Recipient/RecipientConfirm.js +0 -5
  6. package/dist/components/ShareAutosuggest.js +9 -4
  7. package/dist/components/ShareByEmail.js +29 -274
  8. package/dist/components/ShareByEmail.spec.js +52 -230
  9. package/dist/components/ShareByLink.js +1 -3
  10. package/dist/components/ShareDialogCozyToCozy.js +169 -35
  11. package/dist/components/ShareDialogCozyToCozy.spec.js +122 -35
  12. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +13 -3
  13. package/dist/components/ShareModal/SharingDetailsModal.js +0 -5
  14. package/dist/components/ShareRecipientsInput.js +6 -3
  15. package/dist/components/SharedDrive/SharedDriveForm.js +11 -23
  16. package/dist/components/SharedDrive/SharedDriveModal.js +1 -1
  17. package/dist/components/SharedDrive/useSharedDrive.js +33 -57
  18. package/dist/components/SharedDrive/useSharedDrive.spec.js +29 -93
  19. package/dist/components/SharedFolder/DumbBatchSharedFolderModal.js +15 -26
  20. package/dist/components/Sharetypeselect.js +85 -90
  21. package/dist/hooks/usePendingRecipients.js +20 -0
  22. package/dist/hooks/usePendingRecipients.spec.js +30 -0
  23. package/dist/styles/autosuggest.styl +8 -2
  24. package/dist/styles/share.styl +0 -39
  25. package/dist/stylesheet.css +8 -44
  26. package/locales/en.json +5 -9
  27. package/locales/fr.json +5 -9
  28. package/locales/ru.json +5 -9
  29. package/locales/vi.json +5 -9
  30. package/package.json +4 -5
  31. package/src/components/FederatedFolder/DumbFederatedFolderModal.jsx +14 -15
  32. package/src/components/FederatedFolder/FederatedFolderModal.jsx +50 -67
  33. package/src/components/FederatedFolder/FederatedFolderModal.spec.jsx +63 -186
  34. package/src/components/ShareAutosuggest.jsx +7 -2
  35. package/src/components/ShareByEmail.jsx +35 -186
  36. package/src/components/ShareByEmail.spec.jsx +22 -173
  37. package/src/components/ShareByLink.jsx +1 -7
  38. package/src/components/ShareDialogCozyToCozy.jsx +171 -38
  39. package/src/components/ShareDialogCozyToCozy.spec.jsx +66 -0
  40. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +11 -1
  41. package/src/components/ShareRecipientsInput.jsx +5 -2
  42. package/src/components/SharedDrive/SharedDriveForm.jsx +10 -23
  43. package/src/components/SharedDrive/SharedDriveModal.jsx +1 -1
  44. package/src/components/SharedDrive/useSharedDrive.js +24 -50
  45. package/src/components/SharedDrive/useSharedDrive.spec.js +19 -67
  46. package/src/components/SharedFolder/DumbBatchSharedFolderModal.jsx +15 -29
  47. package/src/components/Sharetypeselect.jsx +75 -58
  48. package/src/hooks/usePendingRecipients.js +13 -0
  49. package/src/hooks/usePendingRecipients.spec.js +21 -0
  50. package/src/styles/autosuggest.styl +8 -2
  51. package/src/styles/share.styl +0 -39
  52. package/dist/components/SharedDrive/helpers.js +0 -102
  53. package/dist/components/SharedDrive/helpers.spec.js +0 -227
  54. package/dist/components/SharedStatus.js +0 -61
  55. package/dist/components/SharedStatus.spec.js +0 -44
  56. package/dist/components/Sharesubmit.js +0 -28
  57. package/dist/components/__snapshots__/SharedStatus.spec.js.snap +0 -94
  58. package/dist/propTypes.js +0 -26
  59. package/src/components/SharedDrive/helpers.js +0 -108
  60. package/src/components/SharedDrive/helpers.spec.js +0 -177
  61. package/src/components/SharedStatus.jsx +0 -50
  62. package/src/components/SharedStatus.spec.js +0 -48
  63. package/src/components/Sharesubmit.jsx +0 -31
  64. package/src/components/__snapshots__/SharedStatus.spec.js.snap +0 -94
  65. package/src/propTypes.js +0 -29
@@ -5,7 +5,8 @@ import { useState } from 'react';
5
5
  import { useClient } from 'cozy-client';
6
6
  import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
7
7
  import { useI18n } from 'twake-i18n';
8
- import { RECIPIENT_INDEX_PREFIX, formatRecipients, mergeAndDeduplicateRecipients, moveRecipientToReadOnly, moveRecipientToReadWrite } from './helpers';
8
+ import { getOrCreateFromArray } from '../../helpers/contacts';
9
+ import { usePendingRecipients } from '../../hooks/usePendingRecipients';
9
10
  import { Contact } from '../../models';
10
11
  export var useSharedDrive = function useSharedDrive(_ref) {
11
12
  var onSuccess = _ref.onSuccess;
@@ -17,58 +18,59 @@ export var useSharedDrive = function useSharedDrive(_ref) {
17
18
  var _useAlert = useAlert(),
18
19
  showAlert = _useAlert.showAlert;
19
20
 
20
- var _useState = useState({
21
- recipients: [],
22
- readOnlyRecipients: []
23
- }),
21
+ var _useState = useState(''),
24
22
  _useState2 = _slicedToArray(_useState, 2),
25
- sharedDriveRecipients = _useState2[0],
26
- setSharedDriveRecipients = _useState2[1];
23
+ sharedDriveName = _useState2[0],
24
+ setSharedDriveName = _useState2[1];
27
25
 
28
- var _useState3 = useState(''),
29
- _useState4 = _slicedToArray(_useState3, 2),
30
- sharedDriveName = _useState4[0],
31
- setSharedDriveName = _useState4[1];
26
+ var _usePendingRecipients = usePendingRecipients(),
27
+ pendingRecipients = _usePendingRecipients.pendingRecipients,
28
+ setPendingRecipients = _usePendingRecipients.setPendingRecipients,
29
+ selectedOption = _usePendingRecipients.selectedOption,
30
+ setSelectedOption = _usePendingRecipients.setSelectedOption;
32
31
 
33
32
  var handleSharedDriveNameChange = function handleSharedDriveNameChange(event) {
34
33
  setSharedDriveName(event.target.value);
35
34
  };
36
35
 
37
- var onShare = function onShare(params) {
38
- setSharedDriveRecipients(function (prev) {
39
- return {
40
- recipients: mergeAndDeduplicateRecipients([prev.recipients, params.recipients]),
41
- readOnlyRecipients: mergeAndDeduplicateRecipients([prev.readOnlyRecipients, params.readOnlyRecipients])
42
- };
43
- });
36
+ var createContact = function createContact(contact) {
37
+ return client.create(Contact.doctype, contact);
44
38
  };
45
39
 
46
40
  var onCreate = /*#__PURE__*/function () {
47
41
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
42
+ var contacts, readWriteRecipients, readOnlyRecipients;
48
43
  return _regeneratorRuntime.wrap(function _callee$(_context) {
49
44
  while (1) switch (_context.prev = _context.next) {
50
45
  case 0:
51
46
  _context.prev = 0;
52
47
  _context.next = 3;
48
+ return getOrCreateFromArray(client, pendingRecipients, createContact);
49
+
50
+ case 3:
51
+ contacts = _context.sent;
52
+ readWriteRecipients = selectedOption === 'readOnly' ? [] : contacts;
53
+ readOnlyRecipients = selectedOption === 'readOnly' ? contacts : [];
54
+ _context.next = 8;
53
55
  return client.collection('io.cozy.sharings').createSharedDrive({
54
56
  name: sharedDriveName,
55
57
  description: sharedDriveName,
56
- recipients: sharedDriveRecipients.recipients,
57
- readOnlyRecipients: sharedDriveRecipients.readOnlyRecipients
58
+ recipients: readWriteRecipients,
59
+ readOnlyRecipients: readOnlyRecipients
58
60
  });
59
61
 
60
- case 3:
62
+ case 8:
61
63
  showAlert({
62
64
  message: t('SharedDrive.sharedDriveModal.successNotification'),
63
65
  severity: 'success',
64
66
  variant: 'filled'
65
67
  });
66
68
  onSuccess();
67
- _context.next = 10;
69
+ _context.next = 15;
68
70
  break;
69
71
 
70
- case 7:
71
- _context.prev = 7;
72
+ case 12:
73
+ _context.prev = 12;
72
74
  _context.t0 = _context["catch"](0);
73
75
  showAlert({
74
76
  message: t('SharedDrive.sharedDriveModal.errorNotification'),
@@ -76,11 +78,11 @@ export var useSharedDrive = function useSharedDrive(_ref) {
76
78
  variant: 'filled'
77
79
  });
78
80
 
79
- case 10:
81
+ case 15:
80
82
  case "end":
81
83
  return _context.stop();
82
84
  }
83
- }, _callee, null, [[0, 7]]);
85
+ }, _callee, null, [[0, 12]]);
84
86
  }));
85
87
 
86
88
  return function onCreate() {
@@ -88,39 +90,13 @@ export var useSharedDrive = function useSharedDrive(_ref) {
88
90
  };
89
91
  }();
90
92
 
91
- var onSetType = function onSetType(index, newType) {
92
- var _id = index.split(RECIPIENT_INDEX_PREFIX)[1];
93
- setSharedDriveRecipients(function (prev) {
94
- return newType === 'two-way' ? moveRecipientToReadWrite(prev, _id) : moveRecipientToReadOnly(prev, _id);
95
- });
96
- };
97
-
98
- var onRevoke = function onRevoke(index) {
99
- var _id = index.split(RECIPIENT_INDEX_PREFIX)[1];
100
- setSharedDriveRecipients(function (prev) {
101
- return {
102
- recipients: prev.recipients.filter(function (r) {
103
- return r._id !== _id;
104
- }),
105
- readOnlyRecipients: prev.readOnlyRecipients.filter(function (r) {
106
- return r._id !== _id;
107
- })
108
- };
109
- });
110
- };
111
-
112
- var createContact = function createContact(contact) {
113
- return client.create(Contact.doctype, contact);
114
- };
115
-
116
93
  return {
117
94
  sharedDriveName: sharedDriveName,
118
- recipients: formatRecipients(sharedDriveRecipients),
119
95
  handleSharedDriveNameChange: handleSharedDriveNameChange,
120
- onShare: onShare,
121
- onCreate: onCreate,
122
- onSetType: onSetType,
123
- onRevoke: onRevoke,
124
- createContact: createContact
96
+ pendingRecipients: pendingRecipients,
97
+ setPendingRecipients: setPendingRecipients,
98
+ selectedOption: selectedOption,
99
+ setSelectedOption: setSelectedOption,
100
+ onCreate: onCreate
125
101
  };
126
102
  };
@@ -16,19 +16,10 @@ jest.mock('cozy-client', function () {
16
16
  return {
17
17
  useClient: jest.fn(function () {
18
18
  return {
19
- collection: mockCollection
19
+ collection: mockCollection,
20
+ create: jest.fn()
20
21
  };
21
- }),
22
- models: {
23
- contact: {
24
- getPrimaryEmail: jest.fn(function (r) {
25
- return Array.isArray(r.email) && r.email[0] ? r.email[0].address : '';
26
- }),
27
- getDisplayName: jest.fn(function (r) {
28
- return r.displayName || r.name || '';
29
- })
30
- }
31
- }
22
+ })
32
23
  };
33
24
  });
34
25
  jest.mock('cozy-ui/transpiled/react/providers/Alert', function () {
@@ -56,6 +47,13 @@ jest.mock('../../models', function () {
56
47
  }
57
48
  };
58
49
  });
50
+ jest.mock('../../helpers/contacts', function () {
51
+ return {
52
+ getOrCreateFromArray: jest.fn(function (client, recipients) {
53
+ return Promise.resolve(recipients);
54
+ })
55
+ };
56
+ });
59
57
  describe('useSharedDrive', function () {
60
58
  beforeEach(function () {
61
59
  jest.clearAllMocks();
@@ -69,7 +67,8 @@ describe('useSharedDrive', function () {
69
67
  result = _renderHook.result;
70
68
 
71
69
  expect(result.current.sharedDriveName).toBe('');
72
- expect(result.current.recipients).toEqual([]);
70
+ expect(result.current.pendingRecipients).toEqual([]);
71
+ expect(result.current.selectedOption).toBe('readWrite');
73
72
  });
74
73
  it('handleSharedDriveNameChange updates the name', function () {
75
74
  var _renderHook2 = renderHook(function () {
@@ -88,95 +87,28 @@ describe('useSharedDrive', function () {
88
87
  });
89
88
  expect(result.current.sharedDriveName).toBe('My Drive');
90
89
  });
91
- it('onRevoke removes a recipient from both lists', function () {
92
- var _renderHook3 = renderHook(function () {
93
- return useSharedDrive({
94
- onSuccess: jest.fn()
95
- });
96
- }),
97
- result = _renderHook3.result;
98
-
99
- act(function () {
100
- result.current.onShare({
101
- recipients: [{
102
- _id: 'abc',
103
- displayName: 'Alice',
104
- email: []
105
- }],
106
- readOnlyRecipients: []
107
- });
108
- });
109
- act(function () {
110
- result.current.onRevoke("virtual-shared-drive-sharing-abc");
111
- });
112
- expect(result.current.recipients).toHaveLength(0);
113
- });
114
- it('onSetType moves a recipient to read-only', function () {
115
- var _renderHook4 = renderHook(function () {
116
- return useSharedDrive({
117
- onSuccess: jest.fn()
118
- });
119
- }),
120
- result = _renderHook4.result;
121
-
122
- act(function () {
123
- result.current.onShare({
124
- recipients: [{
125
- _id: 'abc',
126
- displayName: 'Alice',
127
- email: []
128
- }],
129
- readOnlyRecipients: []
130
- });
131
- });
132
- act(function () {
133
- result.current.onSetType("virtual-shared-drive-sharing-abc", 'one-way');
134
- });
135
- expect(result.current.recipients[0].type).toBe('one-way');
136
- });
137
- it('onSetType moves a recipient to read-write', function () {
138
- var _renderHook5 = renderHook(function () {
139
- return useSharedDrive({
140
- onSuccess: jest.fn()
141
- });
142
- }),
143
- result = _renderHook5.result;
144
-
145
- act(function () {
146
- result.current.onShare({
147
- recipients: [],
148
- readOnlyRecipients: [{
149
- _id: 'xyz',
150
- displayName: 'Bob',
151
- email: []
152
- }]
153
- });
154
- });
155
- act(function () {
156
- result.current.onSetType("virtual-shared-drive-sharing-xyz", 'two-way');
157
- });
158
- expect(result.current.recipients).toHaveLength(1);
159
- expect(result.current.recipients[0].type).toBe('two-way');
160
- });
161
- it('onCreate calls createSharedDrive, showAlert with success, and onSuccess', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
162
- var onSuccess, _renderHook6, result;
90
+ it('onCreate calls createSharedDrive and onSuccess', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
91
+ var onSuccess, _renderHook3, result;
163
92
 
164
93
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
165
94
  while (1) switch (_context2.prev = _context2.next) {
166
95
  case 0:
167
96
  onSuccess = jest.fn();
168
97
  mockCreateSharedDrive.mockResolvedValue({});
169
- _renderHook6 = renderHook(function () {
98
+ _renderHook3 = renderHook(function () {
170
99
  return useSharedDrive({
171
100
  onSuccess: onSuccess
172
101
  });
173
- }), result = _renderHook6.result;
102
+ }), result = _renderHook3.result;
174
103
  act(function () {
175
104
  result.current.handleSharedDriveNameChange({
176
105
  target: {
177
106
  value: 'My Drive'
178
107
  }
179
108
  });
109
+ result.current.setPendingRecipients([{
110
+ email: 'a@b.c'
111
+ }]);
180
112
  });
181
113
  _context2.next = 6;
182
114
  return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
@@ -194,10 +126,14 @@ describe('useSharedDrive', function () {
194
126
  })));
195
127
 
196
128
  case 6:
197
- expect(mockCreateSharedDrive).toHaveBeenCalledWith(expect.objectContaining({
129
+ expect(mockCreateSharedDrive).toHaveBeenCalledWith({
198
130
  name: 'My Drive',
199
- description: 'My Drive'
200
- }));
131
+ description: 'My Drive',
132
+ recipients: [{
133
+ email: 'a@b.c'
134
+ }],
135
+ readOnlyRecipients: []
136
+ });
201
137
  expect(mockShowAlert).toHaveBeenCalledWith(expect.objectContaining({
202
138
  severity: 'success'
203
139
  }));
@@ -210,18 +146,18 @@ describe('useSharedDrive', function () {
210
146
  }, _callee2);
211
147
  })));
212
148
  it('onCreate shows error alert and does not call onSuccess on failure', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
213
- var onSuccess, _renderHook7, result;
149
+ var onSuccess, _renderHook4, result;
214
150
 
215
151
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
216
152
  while (1) switch (_context4.prev = _context4.next) {
217
153
  case 0:
218
154
  onSuccess = jest.fn();
219
155
  mockCreateSharedDrive.mockRejectedValue(new Error('network error'));
220
- _renderHook7 = renderHook(function () {
156
+ _renderHook4 = renderHook(function () {
221
157
  return useSharedDrive({
222
158
  onSuccess: onSuccess
223
159
  });
224
- }), result = _renderHook7.result;
160
+ }), result = _renderHook4.result;
225
161
  _context4.next = 5;
226
162
  return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
227
163
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
@@ -14,32 +14,30 @@ export var DumbBatchSharedFolderModal = withLocales(function (_ref) {
14
14
  document = _ref.document,
15
15
  folderName = _ref.folderName,
16
16
  handleFolderNameChange = _ref.handleFolderNameChange,
17
- createContact = _ref.createContact,
18
17
  recipients = _ref.recipients,
19
18
  currentRecipients = _ref.currentRecipients,
20
19
  onRevoke = _ref.onRevoke,
21
- onSetType = _ref.onSetType,
22
20
  onCreate = _ref.onCreate,
23
21
  onSend = _ref.onSend,
24
22
  onClose = _ref.onClose,
25
- _onShare = _ref.onShare,
26
23
  onRename = _ref.onRename,
27
24
  _ref$showNameField = _ref.showNameField,
28
25
  showNameField = _ref$showNameField === void 0 ? false : _ref$showNameField,
29
26
  sharingLink = _ref.sharingLink,
30
27
  nameLabel = _ref.nameLabel,
31
28
  addPeopleLabel = _ref.addPeopleLabel,
32
- addButtonLabel = _ref.addButtonLabel,
33
29
  cancelLabel = _ref.cancelLabel,
34
30
  createLabel = _ref.createLabel,
35
31
  shareLabel = _ref.shareLabel,
36
32
  saveLabel = _ref.saveLabel,
37
- sharingDesc = _ref.sharingDesc,
38
33
  _ref$showShareByEmail = _ref.showShareByEmail,
39
34
  showShareByEmail = _ref$showShareByEmail === void 0 ? true : _ref$showShareByEmail,
40
35
  autoOpenShareRestriction = _ref.autoOpenShareRestriction,
41
- showGenerateLinkButton = _ref.showGenerateLinkButton;
42
- var hasRecipients = Boolean(recipients === null || recipients === void 0 ? void 0 : recipients.length); // Determine action buttons based on modal mode
36
+ showGenerateLinkButton = _ref.showGenerateLinkButton,
37
+ pendingRecipients = _ref.pendingRecipients,
38
+ onPendingRecipientsChange = _ref.onPendingRecipientsChange,
39
+ selectedOption = _ref.selectedOption,
40
+ onSelectedOptionChange = _ref.onSelectedOptionChange;
43
41
 
44
42
  var actionButtons = function () {
45
43
  if (showNameField && onCreate) {
@@ -74,7 +72,7 @@ export var DumbBatchSharedFolderModal = withLocales(function (_ref) {
74
72
  }), /*#__PURE__*/React.createElement(Button, {
75
73
  variant: "primary",
76
74
  label: shareLabel,
77
- disabled: !hasRecipients || !onSend,
75
+ disabled: !onSend,
78
76
  onClick: onSend
79
77
  }));
80
78
  }
@@ -121,17 +119,13 @@ export var DumbBatchSharedFolderModal = withLocales(function (_ref) {
121
119
  variant: "h6",
122
120
  className: "u-mt-1-half u-mb-half"
123
121
  }, addPeopleLabel), showShareByEmail && /*#__PURE__*/React.createElement(DumbShareByEmail, {
124
- createContact: createContact,
125
122
  currentRecipients: currentRecipients,
126
123
  document: document,
127
124
  documentType: "Files",
128
- sharedDrive: true,
129
- sharingDesc: sharingDesc,
130
- onShare: function onShare(params) {
131
- _onShare(params);
132
- },
133
- submitLabel: addButtonLabel,
134
- showNotifications: false
125
+ pendingRecipients: pendingRecipients,
126
+ onPendingRecipientsChange: onPendingRecipientsChange,
127
+ selectedOption: selectedOption,
128
+ onSelectedOptionChange: onSelectedOptionChange
135
129
  })), /*#__PURE__*/React.createElement(WhoHasAccess, {
136
130
  isOwner: true,
137
131
  isSharedDrive: true,
@@ -140,7 +134,6 @@ export var DumbBatchSharedFolderModal = withLocales(function (_ref) {
140
134
  documentType: "Files",
141
135
  className: "u-w-100",
142
136
  onRevoke: onRevoke,
143
- onSetType: onSetType,
144
137
  link: sharingLink
145
138
  })),
146
139
  actions: actionButtons
@@ -151,30 +144,26 @@ DumbBatchSharedFolderModal.propTypes = {
151
144
  document: PropTypes.object,
152
145
  folderName: PropTypes.string,
153
146
  handleFolderNameChange: PropTypes.func,
154
- createContact: PropTypes.func.isRequired,
155
147
  recipients: PropTypes.array,
156
148
  currentRecipients: PropTypes.array,
157
149
  onRevoke: PropTypes.func.isRequired,
158
- onSetType: PropTypes.func.isRequired,
159
150
  onCreate: PropTypes.func,
160
151
  onSend: PropTypes.func,
161
152
  onClose: PropTypes.func.isRequired,
162
- onShare: PropTypes.func.isRequired,
163
153
  onRename: PropTypes.func,
164
154
  showNameField: PropTypes.bool,
165
155
  sharingLink: PropTypes.string,
166
156
  nameLabel: PropTypes.string,
167
157
  addPeopleLabel: PropTypes.string,
168
- addButtonLabel: PropTypes.string,
169
158
  cancelLabel: PropTypes.string,
170
159
  createLabel: PropTypes.string,
171
160
  shareLabel: PropTypes.string,
172
161
  saveLabel: PropTypes.string,
173
- sharingDesc: PropTypes.string,
174
162
  showShareByEmail: PropTypes.bool,
175
163
  autoOpenShareRestriction: PropTypes.bool,
176
- showGenerateLinkButton: PropTypes.bool
177
- };
178
- DumbBatchSharedFolderModal.defaultProps = {
179
- sharingDesc: ''
164
+ showGenerateLinkButton: PropTypes.bool,
165
+ pendingRecipients: PropTypes.array,
166
+ onPendingRecipientsChange: PropTypes.func,
167
+ selectedOption: PropTypes.oneOf(['readWrite', 'readOnly']),
168
+ onSelectedOptionChange: PropTypes.func
180
169
  };
@@ -1,104 +1,99 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
7
- import cx from 'classnames';
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _extends from "@babel/runtime/helpers/extends";
8
3
  import PropTypes from 'prop-types';
9
- import React from 'react';
10
- import Icon from 'cozy-ui/transpiled/react/Icon';
11
- import BottomIcon from 'cozy-ui/transpiled/react/Icons/Bottom';
12
- import CheckIcon from 'cozy-ui/transpiled/react/Icons/Check';
13
- import SelectBox, { components } from 'cozy-ui/transpiled/react/SelectBox';
4
+ import React, { forwardRef, useRef, useState } from 'react';
5
+ import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu';
6
+ import { makeActions } from 'cozy-ui/transpiled/react/ActionsMenu/Actions';
7
+ import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem';
8
+ import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton';
9
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
10
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
11
+ import Radios from 'cozy-ui/transpiled/react/Radios';
14
12
  import logger from '../logger';
15
- var styles = {
16
- "share-modal-content": "share__share-modal-content___1iqEq",
17
- "coz-form": "share__coz-form___1ICST",
18
- "coz-form-group": "share__coz-form-group___VsQp7",
19
- "coz-form-desc": "share__coz-form-desc___2mYN4",
20
- "coz-form-label": "share__coz-form-label___bogBw",
21
- "coz-form-label--error": "share__coz-form-label--error___3YPkf",
22
- "coz-form-errors": "share__coz-form-errors___2xYRz",
23
- "coz-form-controls": "share__coz-form-controls___H8kGc",
24
- "coz-form-controls--full": "share__coz-form-controls--full___1oQXF",
25
- "coz-form-controls--dispatch": "share__coz-form-controls--dispatch___1zIxt",
26
- "error": "share__error___pwqPO",
27
- "share-byemail-onlybylink": "share__share-byemail-onlybylink___29W-t",
28
- "aligned-dropdown-button": "share__aligned-dropdown-button___3crgG",
29
- "share-type-control": "share__share-type-control___1YoRr",
30
- "select-wrapper": "share__select-wrapper___3XBKC",
31
- "select-option": "share__select-option___3Jp8_",
32
- "select-option-label": "share__select-option-label___1BWz_",
33
- "select-option-desc": "share__select-option-desc___3jOnr",
34
- "share-details-created": "share__share-details-created___z3nvO",
35
- "share-details-perm": "share__share-details-perm___3HjxK",
36
- "share-details-perm-desc": "share__share-details-perm-desc___3HyHu"
37
- };
38
13
 
39
- var DropdownIndicator = function DropdownIndicator(props) {
40
- return /*#__PURE__*/React.createElement(components.DropdownIndicator, props, /*#__PURE__*/React.createElement(Icon, {
41
- icon: BottomIcon,
42
- color: "var(--iconTextColor)"
43
- }));
14
+ var makeShareTypeAction = function makeShareTypeAction(_ref) {
15
+ var option = _ref.option,
16
+ isSelected = _ref.isSelected,
17
+ onSelect = _ref.onSelect;
18
+ var Component = /*#__PURE__*/forwardRef(function (props, ref) {
19
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
20
+ ref: ref,
21
+ onClick: function onClick() {
22
+ return onSelect(option.value);
23
+ },
24
+ disabled: option.disabled
25
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Radios, {
26
+ checked: isSelected
27
+ })), /*#__PURE__*/React.createElement(ListItemText, {
28
+ primary: option.label
29
+ }));
30
+ });
31
+ Component.displayName = "ShareTypeAction-".concat(option.value);
32
+ return function () {
33
+ return {
34
+ name: "shareType-".concat(option.value),
35
+ label: option.label,
36
+ icon: null,
37
+ action: function action() {
38
+ return onSelect(option.value);
39
+ },
40
+ Component: Component
41
+ };
42
+ };
44
43
  };
45
44
 
46
- var Option = function Option(props) {
47
- return /*#__PURE__*/React.createElement(components.Option, props, /*#__PURE__*/React.createElement("div", {
48
- className: cx(styles['select-option'])
49
- }, props.isSelected && /*#__PURE__*/React.createElement(Icon, {
50
- icon: CheckIcon,
51
- color: "var(--primaryColor)"
52
- }), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
53
- className: styles['select-option-label']
54
- }, props.label), /*#__PURE__*/React.createElement("div", {
55
- className: styles['select-option-desc']
56
- }, props.data.desc))));
57
- };
45
+ var ShareTypeSelect = function ShareTypeSelect(_ref2) {
46
+ var _options$find;
58
47
 
59
- var customStyles = {
60
- option: function option(base, state) {
61
- return _objectSpread(_objectSpread({}, base), {}, {
62
- color: 'var(--primaryTextColor)',
63
- backgroundColor: state.isFocused ? 'var(--actionColorHover)' : null,
64
- padding: 0,
65
- borderBottom: state.options.findIndex(function (o) {
66
- return o.value === state.value;
67
- }) === 0 ? '1px solid var(--borderMainColor)' : null
68
- });
69
- },
70
- menu: function menu(base) {
71
- return _objectSpread(_objectSpread({}, base), {}, {
72
- backgroundColor: 'var(--paperBackgroundColor)',
73
- width: '204%'
74
- });
75
- }
76
- };
48
+ var value = _ref2.value,
49
+ options = _ref2.options,
50
+ onChange = _ref2.onChange;
51
+ var buttonRef = useRef();
52
+
53
+ var _useState = useState(false),
54
+ _useState2 = _slicedToArray(_useState, 2),
55
+ isOpen = _useState2[0],
56
+ setOpen = _useState2[1];
57
+
58
+ var open = function open() {
59
+ return setOpen(true);
60
+ };
61
+
62
+ var close = function close() {
63
+ return setOpen(false);
64
+ };
77
65
 
78
- var ShareTypeSelect = function ShareTypeSelect(_ref) {
79
- var options = _ref.options,
80
- _onChange = _ref.onChange;
81
- return /*#__PURE__*/React.createElement("div", {
82
- className: styles['select-wrapper']
83
- }, /*#__PURE__*/React.createElement(SelectBox, {
84
- name: "select",
85
- classNamePrefix: "needsclick react-select",
86
- components: {
87
- DropdownIndicator: DropdownIndicator,
88
- Option: Option
89
- },
90
- styles: customStyles,
91
- defaultValue: options[0],
92
- isSearchable: false,
93
- onChange: function onChange(option) {
94
- _onChange(option.value);
95
- },
96
- options: options,
97
- menuPosition: "fixed"
66
+ var onSelect = function onSelect(nextValue) {
67
+ onChange(nextValue);
68
+ setOpen(false);
69
+ };
70
+
71
+ var selectedOption = (_options$find = options.find(function (option) {
72
+ return option.value === value;
73
+ })) !== null && _options$find !== void 0 ? _options$find : options[0];
74
+ var actions = makeActions(options.map(function (option) {
75
+ return makeShareTypeAction({
76
+ option: option,
77
+ isSelected: option.value === selectedOption.value,
78
+ onSelect: onSelect
79
+ });
80
+ }));
81
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DropdownButton, {
82
+ ref: buttonRef,
83
+ onClick: open,
84
+ textVariant: "body2",
85
+ size: "small"
86
+ }, selectedOption.label), /*#__PURE__*/React.createElement(ActionsMenu, {
87
+ ref: buttonRef,
88
+ open: isOpen,
89
+ actions: actions,
90
+ autoClose: true,
91
+ onClose: close
98
92
  }));
99
93
  };
100
94
 
101
95
  ShareTypeSelect.propTypes = {
96
+ value: PropTypes.string,
102
97
  onChange: PropTypes.func,
103
98
  options: PropTypes.array.isRequired
104
99
  };
@@ -0,0 +1,20 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { useState } from 'react';
3
+ export var usePendingRecipients = function usePendingRecipients() {
4
+ var _useState = useState([]),
5
+ _useState2 = _slicedToArray(_useState, 2),
6
+ pendingRecipients = _useState2[0],
7
+ setPendingRecipients = _useState2[1];
8
+
9
+ var _useState3 = useState('readWrite'),
10
+ _useState4 = _slicedToArray(_useState3, 2),
11
+ selectedOption = _useState4[0],
12
+ setSelectedOption = _useState4[1];
13
+
14
+ return {
15
+ pendingRecipients: pendingRecipients,
16
+ setPendingRecipients: setPendingRecipients,
17
+ selectedOption: selectedOption,
18
+ setSelectedOption: setSelectedOption
19
+ };
20
+ };