Advertisement
kirya_shkolnik

Wix Velo Patient form

Aug 6th, 2021
1,543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // API Reference: https://www.wix.com/velo/reference/api-overview/introduction
  2. // “Hello, World!” Example: https://learn-code.wix.com/en/article/1-hello-world
  3. import wixUsers from 'wix-users';
  4. import {getUser} from 'backend/usersInfo';
  5. import wixData from 'wix-data';
  6.  
  7. function createApplication(id) {
  8.   getUser(id)
  9.     .then((user) => {
  10.       let toInsert = {
  11.              "name": $w('#input8').value,
  12.              "patientID": user['slug'],
  13.              "dateOfSubmissionOfTheForm": $w('#datePicker7').value,
  14.              "birtday": $w('#datePicker4').value,
  15.              "address": $w('#input9').value,
  16.              "email": $w('#input10').value,
  17.              "phone": $w('#input11').value,
  18.              "type": $w('#checkboxGroup4').value,
  19.              "sex": $w('#radioGroup4').value,
  20.              "vaccinated": $w('#radioGroup5').value,
  21.              "vaccineManufacter": $w('#radioGroup6').value,
  22.              "1stVaccineShot": $w('#datePicker5').value,
  23.              "2ndVaccineShot": $w('#datePicker6').value,
  24.              "recentlyTraveled": $w('#radioGroup7').value,
  25.              "previousCovidPositive": $w('#radioGroup8').value,
  26.              "symptomsLast14Days": $w('#checkboxGroup1').value,
  27.              "speakingLanguage": $w('#input12').value,
  28.              "race": $w('#radioGroup9').value,
  29.              "ethnicity": $w('#radioGroup10').value,
  30.              "insuranceName": $w('#input13').value,
  31.              "insuranceId": $w('#input14').value,
  32.              "document": $w('#input15').value,
  33.              "agree": $w('#checkbox1').value,
  34.         };
  35.       wixData.insert("Covid_Collection", toInsert)
  36.         .then((results) => {
  37.             console.log('success');
  38.             let item = results;
  39.             $w('#text34').show();
  40.             $w('#image5').hide();
  41.         })
  42.         .catch((err) => {
  43.                     let errorMsg = err;
  44.                     console.log(errorMsg);
  45.                     $w('#text35').text = errorMsg;
  46.                     $w('#text35').show();
  47.                     $w('#image5').hide();
  48.         });
  49.  
  50.     })
  51.         .catch((err) => {
  52.                     let errorMsg = err;
  53.                     console.log(errorMsg);
  54.                     $w('#text35').text = errorMsg;
  55.                     $w('#text35').show();
  56.                     $w('#image5').hide();
  57.         });
  58. }
  59. $w.onReady(function () {
  60.     $w('#button3').onClick(function() {
  61. //   if($w('#input8').value.length != 0 && $w('#input10').value.length != 0 && $w('#datePicker4').value){
  62.    if ($w('#input8').value.length != 0 && $w('#input10').value.length != 0 && $w('#checkboxGroup4').value.length != 0 && $w('#input9').value.length != 0 && $w('#input11').value.length != 0 && $w('#radioGroup4').value.length != 0) {
  63.     $w('#image5').show();
  64.     $w('#button3').disable();
  65.     $w('#text34').hide();
  66.     $w('#text35').hide();
  67.     $w('#text139').hide();
  68.  
  69.  
  70.     createApplication(wixUsers.currentUser.id);
  71.     $w('#image5').hide();
  72.     $w('#button3').enable();
  73.  
  74.  
  75.     // if (!wixUsers.currentUser.loggedIn) {
  76.     //   let name = $w('#input8').value;
  77.     //   let email = $w('#input10').value;
  78.     //   let birthday = $w('#datePicker4').value;
  79.     //   wixUsers.register(email, birthday.toLocaleDateString('en-US'))
  80.     //     .then((result) => {
  81.     //       let user = result.user;
  82.     //              $w('#text139').text = "​The account was created.\nLogin:"+email+"\nPassword:"+birthday.toLocaleDateString('en-US');
  83.     //              $w('#text139').show();
  84.     //       createApplication(user['id']);
  85.     //    $w('#button3').enable();
  86.     //     })
  87.     //     .catch((err) => {
  88.     //       let errorMsg = err;
  89.     //    console.log('register error');
  90.     //       console.log(errorMsg);
  91.     //   $w('#text35').text = errorMsg.substr(0,  errorMsg.indexOf(']') + 1) + " already exists";
  92.     //  // $w('#text35').text = errorMsg.substr(0, 10) + "already exists";
  93.     //  $w('#text35').show();
  94.     //  $w('#image5').hide();
  95.     //  $w('#button3').enable();
  96.  
  97.     //     });
  98.  
  99.     // }
  100.     //  else{
  101.     //      createApplication(wixUsers.currentUser.id);
  102.     //      $w('#image5').hide();
  103.     //      $w('#button3').enable();
  104.     //  }
  105.   }
  106.     else{
  107.         $w('#text35').text = "Fill in the required fields";
  108.         $w('#text35').show();
  109.         $w('#image5').hide();
  110.         $w('#button3').enable();
  111.     }
  112.  
  113. });
  114. });
  115.  
  116. wixUsers.onLogin( () => {
  117.  
  118. } );
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement