The whole website is for members only (password protected).
I am on a dynamic page that lists (among some other details) first and last names of a member that has registered to an event (see print-screen of the page and the code below).
If the logged-in member (here are currentFirst and currentLast) is looking at one event he has registered (here are lastName and firstName), I would then need a group of texts and boxes to appear ('cancelationOrRevise').
url is www.shanghaigolfersclub/Registrations/{Date Event}/{Last Name}/{First Name}
Something is wrong with code but I cannot figure out what.
Can you kindly assist?
Thanks a lot
@sgcbooking..
i m having similar requirement.. i am using member login functionality from wix application . now i have also create a database where i am maintaining some email id..now requirement is that i have to compare the login email id of members to the email ids i have maintained in database manually. if both mail id's match then i have to show a container box..
Thanks.
Issue is solved.
import wixUsers from 'wix-users';
import wixData from "wix-data";
import wixLocation from 'wix-location';
$w.onReady(function () {
// Identify what is value of guest1, guest 2 and guest3
$w('#registrationdataset').onReady( () => {
const currentItem = $w('#registrationdataset').getCurrentItem();
const guest1input = currentItem.guest1;
const guest2input = currentItem.guest2;
const guest3input = currentItem.guest3;
//If guest1, 2 or 3 is empty, then corresponding boxes are hidden
if (guest1input === '') {
$w('#guest1').hide();
}
if (guest2input === '') {
$w('#guest2').hide();
}
if (guest3input === '') {
$w('#guest3').hide();
}
});
// Obtaining first and last Names of the participant to the event
let lastName = wixLocation.path[1];
let firstName = wixLocation.path[2];
// Querying DB to obtain email of participant of the event
wixData.query("Directory")
.limit(1000)
.eq("title", lastName)
.eq("firstName", firstName)
.find()
.then ( (result) => {
let currentEmail = result.items[0].email;
// Obtaining email of the logged-in user
let user = wixUsers.currentUser;
user.getEmail()
.then( (email) => {
let userEmail = email; // "user@something.com"
// Comparing both emails and show 'cancelOrRevise' box if similar
if(userEmail === currentEmail) {
$w('#cancelOrRevise').show();
}
});
});
});
Liran,
I managed to solve the problem (I had forgotten to use the dataset onReady) but the result is not the proper one (it seems the CurrentItem is always the same (latest entry in the collection) no matter what the different data of the dynamic page are ...
So I am trying a different approach by comparing email addresses. Please see below code:
$w.onReady(function () {
// Obtaining first and last Names of the participant to the event
let lastName = wixLocation.path[1];
let firstName = wixLocation.path[2];
console.log(lastName);
console.log(firstName);
// Querying DB to obtain email of participant of the event
wixData.query('Directory')
.eq('title', lastName)
.eq('firstName', firstName)
.find()
.then ( (result) => {
let currentEmail = result.item.email;
console.log(result.item);
console.log(currentEmail);
// Obtaining email of the logged-in user
wixUsers.currentUser.getEmail()
.then( (email) => {
// Comparing both emails and show 'cancelOrRevise' box if similar
if(email === currentEmail) {
$w('#cancelOrRevise').show();
}
});
});
});
It seems the query of the Directory collection does not work since I get nothing for the console.log of the result.item and currentEmail.
What do I do wrong here?
Thank you so much
If I console.log(currentItem) or console.log(firstName) or console.log(lastName), nothing happens. Nothing else appears in the console.
I need to know the line of the error, but I'm guessing it will be line 23.
Can you try
console.log(currentItem)
After getCurrentItem() ?
Liran.
Hi Liran,
I actually just managed to do this using wixLocation.path feature. See below.
But I have an error in the console which I cannot solve (see other print-screen).
I confirm that the field key in my Directory DB (through directeorydataset) of First Name is 'firstName'.
Thanks,
Hi Liran,
Before landing to this dynamic page, user has had to click on a table displaying all names of members registered to the event. Hence, the respective values of firstName and lastName (say, Chris Grossick in my example above) are automatically referenced.
How can I define Chris as firstName and Grossick as lastName?
Thanks a lot
Two things here...
first of all, if you're using a dataset to get the current item, you don't need to query the same collection with the email to get the first and last name (they are also a part of the dataset item).
So you can just start with:
const currentItem = $w('directoryDataset').getCurrentItem(); const currentFirst = currentItem.firstName; const currentLast = currentItem.title; //assuming title is the last name.
This saves you from making the first wixData.query.
Then do some code (I can't understand what you're trying to achieve).
And anyway, at the end of the code, when you use 'it', I assume you want to do 'if something and also something else'. It is written that way:
if (firstName === currentFirst && lastName === currentLast)
But also, in order for this to work, you need to put that code inside of your 'then()' callback, and I would put both filters together (I assume you want to filter both first and last name).
But note!!! firstName and lastName are both variables that are never defined!!
Anyway, a skeleton of code:
.then(result => { let items = results.items[0]; items = items.filter(row => { // NOTE!!!! firstName and lastName are both never defined! return row.title === lastName && row.firstName === firstName; }); if (firstName === currentFirst && lastName === currentLast) { } })
Liran.