I tweaked the code from the Quick booking and pending appoints example.
(https://www.wix.com/velo/example/quick-book-and-pending-appointments)
To only move data from the requests repeater to the approved or dismissed repeater, when you click the approve or decline buttons.
Nothing happens when i click the buttons. I have set up the repeaters exactly like the example this is just the published view
please help!!!
//-------------Imports-------------//
// Import the wix-data module for working with collections.
import wixData from "wix-data";
import wixBookings from 'wix-bookings';
// Import the wix-location module for sending emails for dismissed appointments.
import wixLocation from "wix-location";
//-------------Page Setup-------------//
$w.onReady(function () {
// When the pending requests dataset is ready:
$w("#pendingRequestsDataset").onReady(() => {
// If there are no pending requests:
if ($w("#pendingRequestsDataset").getTotalCount() === 0) {
// Show the no pending requests message.
$w("#noPendingRequests").show();
}
});
});
//-------------Repeater Setup-------------//
// Set up each item in the requests repeater as it is loaded.
export function requestsRepeater_itemReady($item, itemData, index) {
// Populate the date field with the slot's start date.
$item("#date").text = getDate;
$item("#email").text
// Set the dismiss button to dismiss the appointment request when clicked.
$item("#dismissButton").onClick(async () => {
// Disable the dismiss and approve buttons.
$item("#dismissButton").disable();
$item("#approveButton").disable();
// Dismiss the appointment request.
await dismissRequest(itemData, index, $w);
});
// Set the approve button to approve the appointment request when clicked.
$item("#approveButton").onClick(async () => {
// Disable the dismiss and approve buttons.
$item("#dismissButton").disable();
$item("#approveButton").disable();
// Approve the appointment request.
await approveRequest(itemData, index);
});
}
// Set up each item in the dismissed requests repeater as it is loaded.
export function dismissedRequests_itemReady($item, itemData, index) {
// Set the contact button to create an email to the user whose request was dismissed.
$item("#emailButton").onClick(() => {
const subject = "Thanks For Getting in Touch";
wixLocation.to(`mailto:${itemData.email}?subject=${subject}`);
});
}
// Set up each item in the approved requests repeater as it is loaded.
export function approvedRequests_itemReady($item, itemData, index) {
// Set the contact button to create an email to the user whose request was dismissed.
$item("#emailButton2").onClick(() => {
const subject = "Thank you for Booking";
wixLocation.to(`mailto:${itemData.email}?subject=${subject}`);
});
}
//-------------Request Dismissal-------------//
// Dismiss the requested appointment.
async function dismissRequest(pendingRequest, index, $w) {
// Dismiss the requested appointment.
// Set the requested appointment's status to dismissed.
pendingRequest.status = "DISMISSED";
// Update the requested appointment in the pendingAppointments collection.
await wixData.update("Customers", pendingRequest);
// Refresh the page's data and update page elements.
}
// Approve the requested appointment.
async function approveRequest(pendingRequest, index, $w) {
// Dismiss the requested appointment.
// Set the requested appointment's status to dismissed.
pendingRequest.status = "APPROVED";
// Update the requested appointment in the pendingAppointments collection.
await wixData.update("Customers", pendingRequest);
// Refresh the page's data and update page elements.
refreshData();
//-------------Page Update-------------//
// Refresh the page's datasets and update all the elements that are connected to them.
function refreshData() {
// Refresh the pending requests dataset and update all the elements that are connected to it.
$w("#pendingRequestsDataset").refresh().then(() => {
// If there are no pending requests:
if ($w("#pendingRequestsDataset").getTotalCount() === 0) {
// Show the no pending requests message.
$w("#noPendingRequests").show();
}
});
// Refresh the dismissed requests dataset and update all the elements that are connected to it.
$w("#dismissedRequestsDataset").refresh();
}
// Refresh the approved requests dataset and update all the elements that are connected to it.
$w("#approvedRequestsDataset").refresh();
}
//-------------Date Helpers-------------//
// Get the time of the given date formatted as HH:MM am/pm.
function getTimeOfDay(date) {
return date.toLocaleTimeString("en-GB", {hour: "2-digit", minute:"2-digit", hour12: true});
}
// Get the date of the given date formatted as DD/MM/YYYY.
function getDate(date) {
return date.toLocaleDateString("en-GB", {day: "numeric", month: "numeric", year: "numeric" });
}
v/r
Kee