I have two dynamic pages that are setup on my web, “Profile” and “Profile Update”.
I have a button under “Profile” called “Update Profile”. When clicked it takes users to “Profile Update” page corresponding to the user ID. Both pages work properly and show the user profile information.
The issue I have is when user updated the profile by clicking button “updateProfileButton”, the below code is executed. The below code works and the date is updated in the tables properly. After tables are updated I navigate user to their profile page. This profile page still shows the old information. Does not show the latest info. After some time couple of minutes this gets updated.
Any idea how to show the latest information after profile is updated?
export function updateProfileButton_click(event) {
let errorMsg =“”;
//check if user profile is present in GWAP database. If it is present, update it or else create new record.
wixData.query(“GWAP_Member”)
.eq(“_id”, wixUsers.currentUser.id) //$w(“#userEmail”).value)
.find()
.then((results) => {
//Read data from the Site_Member Profile Update form
let newUser = {
title: $w(“#userEmail”).value,
first_name: $w(“#firstName”).value,
last_name: $w(“#lastName”).value,
dateofBirth: $w(“#dob”).value,
gender: $w(“#gender”).value,
address: $w(“#address”).value,
city: $w(“#city”).value,
state: $w(“#state”).value,
zip: $w(“#zip”).value,
phone: $w(“#phone”).value,
//picture: “Mary.jpg”,
rating: $w(“#rating”).value,
usapa_no: Number($w(“#usapaNo”).value),
emergency_contact: $w(“#emergencyContact”).value,
emergency_phone: $w(“#emergencyPhone”).value,
_id: wixUsers.currentUser.id,
paid_member: false
};
console.log(newUser);
//if the user data is not present in the GWAP member database copy data. This data is identical to site_member database
//This allows us to use this data for website
if (results.length === 0) {
wixData.insert(“GWAP_Member”, newUser).then((queryresults) => {
let item = queryresults; //see item below
})
. catch ((err) => {
errorMsg = errorMsg+ “Error:”+ err;
});
}
//if user data is already present update the data once “update profile” button is clicked
else {
console.log(“Data present”);
//wixData.update(“GWAP_Member”, newUser);
wixData.get(“GWAP_Member”, wixUsers.currentUser.id)
.then(() => {
wixData.update(“GWAP_Member”, newUser)
.then((result) => {
// updated object returned so let’s take a look
console.log(result);
})
. catch ((err) => {
errorMsg = errorMsg+ “Error:”+ err;
});
})
. catch ((err) => {
errorMsg = errorMsg+ “Error:”+ err;
});
}
}). catch ((err) => {
errorMsg = err;
});
console.log(errorMsg);
wixLocation.to(/Site-Members/Profile/${wixUsers.currentUser.id}
);
}