Hi guys ! I created a long and boring code that is perfectly running on preview mode, however I tried live and nothing happen, I don’t understand why. If someone have any idea, I would be glad to offer ice cream <3
More seriously, I am supposed to show the website to my client tuesday, so any help would be really appreciated!
The expected behavior :
When user clicks on button2:
1 - Password, email and phone are stored in the PrivateMemberData → the user is registered
2 - Based on the email of the user, I run a query in order to extract his contactID
3 - I store the contactID with other information related to the user in a new database (Profil patient)
4 - I log the user in
5 - I redirect the user to a welcome lightbox
You can run the code using the following link : https://valentinloppe.wixsite.com/oncopole
You go to “connexion”, then you click on “je n’ai pas encore de compte”
The code :
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import { session } from 'wix-storage';
$w.onReady(function () {
$w('#button2').onClick(() => {
if ($w("#firstName").value === "") {
$w("#text13").text = "Merci de renseigner votre prénom"
$w("#text13").expand()
} else if ($w("#lastName").value === "") {
$w("#text13").text = "Merci de renseigner votre nom de famille"
$w("#text13").expand()
} else if ($w("#cps").value === "") {
$w("#text13").text = "Merci de renseigner votre numéro de CPS"
$w("#text13").expand()
} else if ($w("#datePicker1").value === "") {
$w("#text13").text = "Merci de renseigner votre date de naissance"
$w("#text13").expand()
} else if ($w("#email").value === "") {
$w("#text13").text = "Merci de renseigner votre adresse email"
$w("#text13").expand()
} else if ($w("#password").value === "") {
$w("#text13").text = "Merci de renseigner votre mot de passe"
$w("#text13").expand()
} else if ($w('#checkbox1').checked) {
let emails = [];
let labels = [];
finale()
} else {
$w('#text13').expand();
}
});
});
export function text14_click(event) {
wixWindow.lightbox.close()
wixWindow.openLightbox("Connection")
}
function connection() {
let email = $w('#email').value
let password = $w("#password").value
wixUsers.login(email, password)
.then(() => {
console.log("User is logged in");
session.setItem("prenom", $w('#lastName').value);
wixWindow.openLightbox("Bienvenue")
})
}
function register() {
let emails = [];
emails.push($w('#email').value);
wixUsers.register($w('#email').value, $w('#password').value, {
"contactInfo": {
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,
}
})
.then((result) => {
let resultStatus = result.status;
console.log(result)
console.log(resultStatus)
})
.catch((err) => {
savings();
})
}
function savings() {
wixData.query("Members/PrivateMembersData")
.eq("loginEmail", $w('#email').value)
.find()
.then((results) => {
let Result = results.items[0]
let ResultID = Result._id;
console.log(ResultID)
$w("#dataset1").setFieldValues({
"nom": $w('#firstName').value,
"prenom": $w('#lastName').value,
"cps": $w('#cps').value,
"telephone": $w('#phoneNumber').value,
"email": $w('#email').value,
"dateDeNaissance": $w('#datePicker1').value,
"patientId": ResultID
})
$w("#dataset1").save()
session.setItem("ResultID", ResultID);
console.log("les données sont stockées")
connection()
}).catch((err) => {
console.log(err);
})
}
async function finale() {
await register()
console.log("l'utilisateur est enregistré")
}