Hi Guys,
The code below will be standard for advanced wix code users and therefore explain itself I think so.
import wixUsers from 'wix-users'; import wixData from 'wix-data'; import wixLocation from 'wix-location'; $w.onReady( () => { if(wixUsers.currentUser.loggedIn) { $w("#button12").label = "Logout"; $w("#button14").show(); } else { $w("#button12").label = "Login"; $w("#button14").hide(); } } ); export function button12_click() { // user is logged in if(wixUsers.currentUser.loggedIn) { // log the user out wixUsers.logout() .then( () => { // update buttons accordingly $w("#button12").label = "Login"; $w("#button14").hide(); } ); } // user is logged out else { let userId; let userEmail; // prompt the user to log in wixUsers.promptLogin( {"mode": "login"} ) .then( (user) => { wixLocation.to('*the member login page link will be stated here*); userId = user.id; return user.getEmail(); } ) .then( (email) => { // check if there is an item for the user in the collection userEmail = email; return wixData.query("Free1") .eq("_id", userId) .find(); } ) .then( (results) => { // if an item for the user is not found if (results.items.length === 0) { // create an item const toInsert = { "_id": userId, "email": userEmail }; // add the item to the collection wixData.insert("Free1", toInsert) .catch( (err) => { console.log(err); } ); } // update buttons accordingly $w("#button12").label = "Logout"; $w("#button14").show(); } ) .catch( (err) => { console.log(err); } ); } } export function button14_click() { wixLocation.to(`/Free1/${wixUsers.currentUser.id}`); } button 14 will direct users to a form they can fill in. Afterwards, their own personal page will be created. However, I would like to add another button (button 15) where visitors can view this personal page.
In practical, with button 14 they can make changes afterwards in the form and with button 15 they can view the result of these changes on their personal page.
I know how to add button 15 (show() etc.) in the code and use the export function to direct to their personal page. But I would like to display button 15 only when a user has already fill in the form. The code should check in the database free1 the ID of the filled in form.
Does anybody know how to insert the code, that will display button 15 only when an user has filled in the form, into the above code?
Thank you for your help!
Vincent
bump
Dear Mike,
Do you also know how to correctly insert your code into my existing code?
I am trying different things but it's nog yet working.
Thank you!
search Free1 for their user ID
wixData.query("Free1") .eq("_id", userId) .find(); } ) .then( (results) => { // if an item for the user is found if (results.items.length !== 0) {
$w("#button15").show();
}
})