@iankibetsh/shframework 1.8.9 → 1.9.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.
@@ -1,36 +1,4 @@
1
1
 
2
- .colored-toast.swal2-icon-success {
3
- background-color: #a5dc86 !important;
4
- }
5
-
6
- .colored-toast.swal2-icon-error {
7
- background-color: #f27474 !important;
8
- }
9
-
10
- .colored-toast.swal2-icon-warning {
11
- background-color: #f8bb86 !important;
12
- }
13
-
14
- .colored-toast.swal2-icon-info {
15
- background-color: #3fc3ee !important;
16
- }
17
-
18
- .colored-toast.swal2-icon-question {
19
- background-color: #87adbd !important;
20
- }
21
-
22
- .colored-toast .swal2-title {
23
- color: white;
24
- }
25
-
26
- .colored-toast .swal2-close {
27
- color: white;
28
- }
29
-
30
- .colored-toast .swal2-html-container {
31
- color: white;
32
- }
33
-
34
2
  .sh-phone{
35
3
  display: flex;
36
4
  width: 100%;
@@ -63,6 +31,38 @@
63
31
  opacity: 0.5;
64
32
  }
65
33
 
34
+ .colored-toast.swal2-icon-success {
35
+ background-color: #a5dc86 !important;
36
+ }
37
+
38
+ .colored-toast.swal2-icon-error {
39
+ background-color: #f27474 !important;
40
+ }
41
+
42
+ .colored-toast.swal2-icon-warning {
43
+ background-color: #f8bb86 !important;
44
+ }
45
+
46
+ .colored-toast.swal2-icon-info {
47
+ background-color: #3fc3ee !important;
48
+ }
49
+
50
+ .colored-toast.swal2-icon-question {
51
+ background-color: #87adbd !important;
52
+ }
53
+
54
+ .colored-toast .swal2-title {
55
+ color: white;
56
+ }
57
+
58
+ .colored-toast .swal2-close {
59
+ color: white;
60
+ }
61
+
62
+ .colored-toast .swal2-html-container {
63
+ color: white;
64
+ }
65
+
66
66
  .permissions-main {
67
67
  background: #edeff2;
68
68
  }
package/dist/library.js CHANGED
@@ -377,6 +377,7 @@ const updateSession = () =>{
377
377
  ShStorage.setItem('last_activity', timeNow);
378
378
  };
379
379
 
380
+ const graphQlEndpoint = 'sh-ql';
380
381
  let apiUrl = undefined.VITE_APP_API_URL;
381
382
  // eslint-disable-next-line no-undef
382
383
  if (process.env.NODE_ENV === 'production') {
@@ -413,24 +414,23 @@ function doPost (endPoint, data) {
413
414
  )
414
415
  }
415
416
  function graphQlQuery(query) {
416
- updateSession();
417
417
  const data = {
418
- query: query
418
+ query
419
419
  };
420
- return axios.get('sh-ql', {
421
- params: data,
422
- crossOrigin: true,
423
- headers: {
424
- Authorization: 'Bearer ' + ShStorage.getItem('access_token')
425
- // 'X-CSRF-TOKEN': 'INVALID'
426
- }
427
- })
420
+ return doGet(graphQlEndpoint,data)
421
+ }
422
+ function graphQlMutate(mutation) {
423
+ const data = {
424
+ query: `mutation ${mutation}`
425
+ };
426
+ return doPost(graphQlEndpoint,data)
428
427
  }
429
428
 
430
429
  var shApis = {
431
430
  doGet,
432
431
  doPost,
433
- graphQlQuery
432
+ graphQlQuery,
433
+ graphQlMutate
434
434
  };
435
435
 
436
436
  const countries = [
@@ -3094,7 +3094,7 @@ var script$n = {
3094
3094
  'textAreas',
3095
3095
  'currentData',
3096
3096
  'emails',
3097
- 'phones','numbers','selects','dates'
3097
+ 'phones','numbers','selects','dates','gqlMutation'
3098
3098
  ],
3099
3099
  emits: ['success'],
3100
3100
  setup(__props, { emit }) {
@@ -3189,30 +3189,54 @@ const submitForm = e => {
3189
3189
  e.preventDefault();
3190
3190
  loading.value = true;
3191
3191
  const data = {};
3192
- formFields.value.map(field=>data[field.field] = field.value);
3193
- shApis.doPost(props.action,data).then(res=>{
3194
- loading.value = false;
3195
- emit('formSubmitted',res.data);
3196
- emit('success',res.data);
3197
- props.successMessage && shRepo.showToast(props.successMessage);
3198
- props.successCallback && props.successCallback(res.data);
3199
- !props.retainDataAfterSubmission && formFields.value.map(field=>field.value = null);
3200
- closeModal();
3201
- }).catch(reason=>{
3202
- console.log(reason);
3203
- loading.value = false;
3204
- const httpStatus = reason.response ? reason.response.status:0;
3205
- formError.value = httpStatus === 422 ? formError.value = null:reason.message ?? null;
3206
- let httpErrors = {};
3207
- httpStatus === 422 && typeof reason.response.data.errors === 'object' && (httpErrors = reason.response.data.errors);
3208
- if(httpErrors && reason.response){
3209
- Object.keys(httpErrors).map(key=>validationErrors.value[key] = typeof httpErrors[key] === 'string' ? httpErrors[key]:httpErrors[key][0]);
3210
- }
3211
- (httpStatus !== 422 && formError.value) && shRepo.showToast(formError.value,'error');
3212
- validationErrors.value;
3192
+ formFields.value.map(field=>{
3193
+ data[field.field] = field.value;
3213
3194
  });
3195
+ if(props.gqlMutation) {
3196
+ let args = `(`;
3197
+ let selectFields = Object.keys(data);
3198
+ selectFields.forEach(key=>{
3199
+ if(data[key]) {
3200
+ args +=`${key}: "${data[key]}",`;
3201
+ }
3202
+ });
3203
+ args+=`)`;
3204
+ args = args.replace(',)',')');
3205
+ if(args == '()') {
3206
+ args = '';
3207
+ }
3208
+ const mutation = `{\n${props.gqlMutation} ${args} {\n${selectFields.join(`\n`)}\n}\n}`;
3209
+ console.log(mutation);
3210
+ shApis.graphQlMutate(mutation).then(res=>handleSuccessRequest(res)).catch(reason=>handlefailedRequest(reason));
3211
+ } else {
3212
+ shApis.doPost(props.action,data).then(res=>handleSuccessRequest(res)).catch(reason=>handlefailedRequest(reason));
3213
+ }
3214
3214
  return false
3215
3215
  };
3216
+
3217
+ const handleSuccessRequest = res=>{
3218
+ loading.value = false;
3219
+ emit('formSubmitted',res.data);
3220
+ emit('success',res.data);
3221
+ props.successMessage && shRepo.showToast(props.successMessage);
3222
+ props.successCallback && props.successCallback(res.data);
3223
+ !props.retainDataAfterSubmission && formFields.value.map(field=>field.value = null);
3224
+ closeModal();
3225
+ };
3226
+
3227
+ const handlefailedRequest = reason=>{
3228
+ console.log(reason);
3229
+ loading.value = false;
3230
+ const httpStatus = reason.response ? reason.response.status:0;
3231
+ formError.value = httpStatus === 422 ? formError.value = null:reason.message ?? null;
3232
+ let httpErrors = {};
3233
+ httpStatus === 422 && typeof reason.response.data.errors === 'object' && (httpErrors = reason.response.data.errors);
3234
+ if(httpErrors && reason.response){
3235
+ Object.keys(httpErrors).map(key=>validationErrors.value[key] = typeof httpErrors[key] === 'string' ? httpErrors[key]:httpErrors[key][0]);
3236
+ }
3237
+ (httpStatus !== 422 && formError.value) && shRepo.showToast(formError.value,'error');
3238
+ validationErrors.value;
3239
+ };
3216
3240
  const submitBtnWidth = vue.ref(null);
3217
3241
  const setExistingData = (existingData)=>{
3218
3242
  if (props.currentData) {
@@ -5616,7 +5640,7 @@ vue.watch(() => route.query.popup, pop => {
5616
5640
  const component = route.query.comp || '';
5617
5641
  PopupComponent.value = vue.defineAsyncComponent({
5618
5642
  // the loader function
5619
- loader: () => (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(`/src/views/popups/${component}Popup.vue`),
5643
+ loader: () => (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(/* @vite-ignore */ `/src/views/popups/${component}Popup.vue`),
5620
5644
 
5621
5645
  // A component to use while the async component is loading
5622
5646
  loadingComponent: script$8,
package/dist/library.mjs CHANGED
@@ -347,6 +347,7 @@ const updateSession = () =>{
347
347
  ShStorage.setItem('last_activity', timeNow);
348
348
  };
349
349
 
350
+ const graphQlEndpoint = 'sh-ql';
350
351
  let apiUrl = import.meta.env.VITE_APP_API_URL;
351
352
  // eslint-disable-next-line no-undef
352
353
  if (process.env.NODE_ENV === 'production') {
@@ -383,24 +384,23 @@ function doPost (endPoint, data) {
383
384
  )
384
385
  }
385
386
  function graphQlQuery(query) {
386
- updateSession();
387
387
  const data = {
388
- query: query
388
+ query
389
389
  };
390
- return axios.get('sh-ql', {
391
- params: data,
392
- crossOrigin: true,
393
- headers: {
394
- Authorization: 'Bearer ' + ShStorage.getItem('access_token')
395
- // 'X-CSRF-TOKEN': 'INVALID'
396
- }
397
- })
390
+ return doGet(graphQlEndpoint,data)
391
+ }
392
+ function graphQlMutate(mutation) {
393
+ const data = {
394
+ query: `mutation ${mutation}`
395
+ };
396
+ return doPost(graphQlEndpoint,data)
398
397
  }
399
398
 
400
399
  var shApis = {
401
400
  doGet,
402
401
  doPost,
403
- graphQlQuery
402
+ graphQlQuery,
403
+ graphQlMutate
404
404
  };
405
405
 
406
406
  const countries = [
@@ -3064,7 +3064,7 @@ var script$n = {
3064
3064
  'textAreas',
3065
3065
  'currentData',
3066
3066
  'emails',
3067
- 'phones','numbers','selects','dates'
3067
+ 'phones','numbers','selects','dates','gqlMutation'
3068
3068
  ],
3069
3069
  emits: ['success'],
3070
3070
  setup(__props, { emit }) {
@@ -3159,30 +3159,54 @@ const submitForm = e => {
3159
3159
  e.preventDefault();
3160
3160
  loading.value = true;
3161
3161
  const data = {};
3162
- formFields.value.map(field=>data[field.field] = field.value);
3163
- shApis.doPost(props.action,data).then(res=>{
3164
- loading.value = false;
3165
- emit('formSubmitted',res.data);
3166
- emit('success',res.data);
3167
- props.successMessage && shRepo.showToast(props.successMessage);
3168
- props.successCallback && props.successCallback(res.data);
3169
- !props.retainDataAfterSubmission && formFields.value.map(field=>field.value = null);
3170
- closeModal();
3171
- }).catch(reason=>{
3172
- console.log(reason);
3173
- loading.value = false;
3174
- const httpStatus = reason.response ? reason.response.status:0;
3175
- formError.value = httpStatus === 422 ? formError.value = null:reason.message ?? null;
3176
- let httpErrors = {};
3177
- httpStatus === 422 && typeof reason.response.data.errors === 'object' && (httpErrors = reason.response.data.errors);
3178
- if(httpErrors && reason.response){
3179
- Object.keys(httpErrors).map(key=>validationErrors.value[key] = typeof httpErrors[key] === 'string' ? httpErrors[key]:httpErrors[key][0]);
3180
- }
3181
- (httpStatus !== 422 && formError.value) && shRepo.showToast(formError.value,'error');
3182
- validationErrors.value;
3162
+ formFields.value.map(field=>{
3163
+ data[field.field] = field.value;
3183
3164
  });
3165
+ if(props.gqlMutation) {
3166
+ let args = `(`;
3167
+ let selectFields = Object.keys(data);
3168
+ selectFields.forEach(key=>{
3169
+ if(data[key]) {
3170
+ args +=`${key}: "${data[key]}",`;
3171
+ }
3172
+ });
3173
+ args+=`)`;
3174
+ args = args.replace(',)',')');
3175
+ if(args == '()') {
3176
+ args = '';
3177
+ }
3178
+ const mutation = `{\n${props.gqlMutation} ${args} {\n${selectFields.join(`\n`)}\n}\n}`;
3179
+ console.log(mutation);
3180
+ shApis.graphQlMutate(mutation).then(res=>handleSuccessRequest(res)).catch(reason=>handlefailedRequest(reason));
3181
+ } else {
3182
+ shApis.doPost(props.action,data).then(res=>handleSuccessRequest(res)).catch(reason=>handlefailedRequest(reason));
3183
+ }
3184
3184
  return false
3185
3185
  };
3186
+
3187
+ const handleSuccessRequest = res=>{
3188
+ loading.value = false;
3189
+ emit('formSubmitted',res.data);
3190
+ emit('success',res.data);
3191
+ props.successMessage && shRepo.showToast(props.successMessage);
3192
+ props.successCallback && props.successCallback(res.data);
3193
+ !props.retainDataAfterSubmission && formFields.value.map(field=>field.value = null);
3194
+ closeModal();
3195
+ };
3196
+
3197
+ const handlefailedRequest = reason=>{
3198
+ console.log(reason);
3199
+ loading.value = false;
3200
+ const httpStatus = reason.response ? reason.response.status:0;
3201
+ formError.value = httpStatus === 422 ? formError.value = null:reason.message ?? null;
3202
+ let httpErrors = {};
3203
+ httpStatus === 422 && typeof reason.response.data.errors === 'object' && (httpErrors = reason.response.data.errors);
3204
+ if(httpErrors && reason.response){
3205
+ Object.keys(httpErrors).map(key=>validationErrors.value[key] = typeof httpErrors[key] === 'string' ? httpErrors[key]:httpErrors[key][0]);
3206
+ }
3207
+ (httpStatus !== 422 && formError.value) && shRepo.showToast(formError.value,'error');
3208
+ validationErrors.value;
3209
+ };
3186
3210
  const submitBtnWidth = ref(null);
3187
3211
  const setExistingData = (existingData)=>{
3188
3212
  if (props.currentData) {
@@ -5586,7 +5610,7 @@ watch(() => route.query.popup, pop => {
5586
5610
  const component = route.query.comp || '';
5587
5611
  PopupComponent.value = defineAsyncComponent({
5588
5612
  // the loader function
5589
- loader: () => import(`/src/views/popups/${component}Popup.vue`),
5613
+ loader: () => import(/* @vite-ignore */ `/src/views/popups/${component}Popup.vue`),
5590
5614
 
5591
5615
  // A component to use while the async component is loading
5592
5616
  loadingComponent: script$8,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/shframework",
3
- "version": "1.8.9",
3
+ "version": "1.9.0",
4
4
  "description": "Vue library for handling laravel backend",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.mjs",