Question:
[Clearly ask your question.]
i want to make a points bar that displays on home page and website header, how can i make this text sell?
Product:
[Which editor or feature is your question most relevant to? e.g. Wix Editor, Wix Studio Editor.]
wix editor
What are you trying to achieve:
[Explain the details of what you are trying to achieve. The more details you provide, the easier it is to understand what you need.]
point program for website members
What have you already tried:
[Share resources, forum topics, articles, or tutorials you’ve already used to try and answer your question.]
loyality program
Additional information:
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]
Which kind of point bar? Like the points counter of each user (like credit points) or static bar? Text or progress bar? Can you clarify more?
sure, i am making a internal training & Management website, that will allow all empolyees to join and i want to show a number that indicates their points (which assigned by me for each employer) just a number that shows in the header below their name and in their profile
and the pointing system includes many sections for completing training and their work profermance, but generally assigned by me
don’t forget please
best regards
Of course. I’ve something to ask. You said points can be assigned by you, so there is a way to update the points using dynamic pages for each users.
Or there is a connected field with jobs or training. If user complete a training, it’s update the points of that user automatically or only assign by you?
Hi Sir,
As you requested.
Here is an example for your code.
Code to update points for admin roles
import wixData from 'wix-data';
import wixUsers from 'wix-users';
$w.onReady(function () {
// Check if the current user is an admin
if (wixUsers.currentUser.role === 'Admin') {
// Populate userDropdown with users from YourCollectionNamecollection
wixData.query("YourCollectionName")
.find()
.then((results) => {
results.items.forEach(user => {
$w("#userDropdown").options.push({
label: user.userRef.nickname, // or any other field representing user
value: user._id
});
});
});
} else {
// Hide admin functionality if not admin
$w("#adminSection").hide();
}
});
export function updatePointsButton_click(event) {
let selectedUserId = $w("#userDropdown").value;
let pointsToUpdate = Number($w("#pointsInput").value);
// Fetch the selected user's record
wixData.get("YourCollectionName", selectedUserId)
.then(userRecord => {
let newPoints = (userRecord.points || 0) + pointsToUpdate; // Assuming points field exists
// Update the points field
userRecord.points = newPoints;
return wixData.update("YourCollectionName", userRecord);
})
.then(() => {
$w("#statusText").text = "Points updated successfully!";
})
.catch((err) => {
console.log("Error updating points: ", err);
});
}
add this in the master.js file to appear in all pages due to the point element is given in the navbar
import wixData from 'wix-data';
import wixUsers from 'wix-users';
$w.onReady(function () {
let currentUser = wixUsers.currentUser;
if (currentUser.loggedIn) {
currentUser.getEmail().then((email) => {
// Query the collection to find the current user's points using their email or ID
wixData.query("YourCollectionName")
.eq("userRef", currentUser.id) // Match the user ID or email in the collection
.find()
.then((results) => {
if (results.items.length > 0) {
let userPoints = results.items[0].points || 0; // Default to 0 if no points
$w("#pointsText").text = `Points: ${userPoints}`;
} else {
$w("#pointsText").text = "Points: 0";
}
});
});
} else {
$w("#pointsText").text = "Please log in to see your points.";
}
});
Hope this will help you.