@cocreate/users 1.19.9 → 1.21.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [1.21.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.20.0...v1.21.0) (2023-05-10)
2
+
3
+
4
+ ### Features
5
+
6
+ * added @cocreate/form ([2fb6c2b](https://github.com/CoCreate-app/CoCreate-users/commit/2fb6c2b635f7bb6cc7d527f0d6c439eaa95cf19d))
7
+
8
+ # [1.20.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.19.9...v1.20.0) (2023-05-10)
9
+
10
+
11
+ ### Features
12
+
13
+ * if !dbUrl use indexeddb ([ba86800](https://github.com/CoCreate-app/CoCreate-users/commit/ba8680066b01ffa8df02dfeb260d229d2081fc44))
14
+
1
15
  ## [1.19.9](https://github.com/CoCreate-app/CoCreate-users/compare/v1.19.8...v1.19.9) (2023-05-07)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/users",
3
- "version": "1.19.9",
3
+ "version": "1.21.0",
4
4
  "description": "A simple users component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "users",
@@ -63,6 +63,7 @@
63
63
  "@cocreate/crud-client": "^1.20.4",
64
64
  "@cocreate/docs": "^1.7.8",
65
65
  "@cocreate/element-prototype": "^1.8.7",
66
+ "@cocreate/form": "^1.14.6",
66
67
  "@cocreate/local-storage": "^1.6.8",
67
68
  "@cocreate/render": "^1.24.8"
68
69
  }
package/src/client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /*globals CustomEvent, btoa*/
2
2
  import crud from '@cocreate/crud-client';
3
3
  import action from '@cocreate/actions';
4
+ import form from '@cocreate/form';
4
5
  import render from '@cocreate/render';
5
6
  import '@cocreate/element-prototype';
6
7
  import './index.css';
@@ -15,24 +16,6 @@ const CoCreateUser = {
15
16
 
16
17
  initSocket: function() {
17
18
  const self = this;
18
- // crud.listen('signUp', function(data) {
19
- // self.setDocumentId('users', data.document[0]._id);
20
-
21
- // render.data({
22
- // selector: "[template='signUp']",
23
- // data: {
24
- // type: 'signUp',
25
- // message: 'Succesfully Signed Up',
26
- // success: true
27
- // }
28
- // });
29
-
30
- // document.dispatchEvent(new CustomEvent('signUp', {
31
- // detail: data
32
- // }));
33
- // });
34
-
35
- crud.listen('signIn', (data) => self.signInResponse(data));
36
19
  crud.listen('updateUserStatus', (data) => self.updateUserStatus(data));
37
20
  },
38
21
 
@@ -45,12 +28,8 @@ const CoCreateUser = {
45
28
 
46
29
  inputs.forEach((input) => {
47
30
  const name = input.getAttribute('name');
48
- let value = input.value;
49
- if (input.type == 'password') {
50
- value = btoa(value);
51
- }
31
+ const value = input.getValue();
52
32
  collection = input.getAttribute('collection') || collection;
53
-
54
33
  query.push({name, value, operator: '$eq'})
55
34
  });
56
35
 
@@ -66,7 +45,7 @@ const CoCreateUser = {
66
45
  }
67
46
 
68
47
  const socket = crud.socket.getSockets()
69
- if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
48
+ if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine || crud.socket.dbUrl == false || crud.socket.organization == false) {
70
49
  crud.updateDocument(request).then((response) => {
71
50
  response['success'] = false
72
51
  response['status'] = "signIn failed"
@@ -79,9 +58,10 @@ const CoCreateUser = {
79
58
  }
80
59
  })
81
60
  } else {
82
- // ToDo: can be depreciated if we have another means of token generation
83
61
  request.broadcastBrowser = false
84
- crud.socket.send('signIn', request);
62
+ crud.socket.send('signIn', request).then((response) => {
63
+ this.signInResponse(data)
64
+ })
85
65
  }
86
66
  },
87
67
 
@@ -139,61 +119,36 @@ const CoCreateUser = {
139
119
  },
140
120
 
141
121
  signUp: function(btn) {
142
- let form = btn.closest("form");
143
- if (!form) return;
144
- let org_id = "";
145
- let elements = form.querySelectorAll("[collection='users'][name]");
146
- let orgIdElement = form.querySelector("input[collection='organizations'][name='_id']");
147
-
148
- if (orgIdElement)
149
- org_id = orgIdElement.value;
150
- else
151
- org_id = crud.socket.config.organization_id;
152
-
153
- let data = {document: {}};
154
- elements.forEach(el => {
155
- let name = el.getAttribute('name');
156
- let value = el.getValue();
157
- if (!name || !value) return;
158
- data.document[name] = value;
159
- });
122
+ let formEl = btn.closest("form");
123
+ if (!formEl) return;
124
+
125
+ let organization_id = crud.socket.config.organization_id;
126
+ let data = form.getData(formEl, 'users')
160
127
  data['collection'] = 'users'
161
- data.document['current_org'] = org_id;
162
- data.document['connected_orgs'] = [org_id];
128
+ data.document['current_org'] = organization_id;
129
+ data.document['connected_orgs'] = [organization_id];
130
+ data.organization_id = [organization_id];
163
131
 
164
132
  // const socket = crud.socket.getSockets()
165
133
  // if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
166
- // ToDo: can use updateDocument with filter query
167
- crud.createDocument(data).then((response) => {
168
- self.setDocumentId('users', response.document_id);
169
- data.database = org_id
170
- data.document['_id'] = response.document_id
171
- data.organization_id = org_id
172
- crud.createDocument(request).then((response) => {
173
- render.data({
174
- selector: "[template='signUp']",
175
- data: {
176
- type: 'signUp',
177
- message: 'Succesfully Signed Up',
178
- success: true
179
- }
180
- });
134
+ // ToDo: can use updateDocument with filter query
135
+ crud.createDocument(data).then((response) => {
136
+ form.setDocumentId(formEl, response)
137
+
138
+ render.data({
139
+ selector: "[template='signUp']",
140
+ data: {
141
+ type: 'signUp',
142
+ message: 'Succesfully Signed Up',
143
+ success: true
144
+ }
145
+ });
146
+
147
+ document.dispatchEvent(new CustomEvent('signUp', {
148
+ detail: response
149
+ }));
181
150
 
182
- document.dispatchEvent(new CustomEvent('signUp', {
183
- detail: response
184
- }));
185
-
186
- })
187
- })
188
- // } else {
189
- // // ToDo: creates user in platformdb
190
- // crud.socket.send('signUp', {
191
- // collection: 'users',
192
- // ...data,
193
- // orgDB: org_id,
194
- // broadcastBrowser: false
195
- // });
196
- // }
151
+ })
197
152
  },
198
153
 
199
154
  updateUserStatus: function(data) {
@@ -287,23 +242,7 @@ const CoCreateUser = {
287
242
  });
288
243
  }
289
244
  }
290
- },
291
-
292
- // ToDo: variations of setDocumentId exists in a few components
293
- setDocumentId: function(collection, id) {
294
- let orgIdElements = document.querySelectorAll(`[collection='${collection}']`);
295
- if (orgIdElements && orgIdElements.length > 0) {
296
- orgIdElements.forEach((el) => {
297
- if (!el.getAttribute('document_id')) {
298
- el.setAttribute('document_id', id);
299
- }
300
- if (el.getAttribute('name') == "_id") {
301
- el.value = id;
302
- }
303
- });
304
- }
305
- }
306
-
245
+ }
307
246
  };
308
247
 
309
248