Initial plugin scaffold: lesson scheduling WordPress plugin
Some checks failed
CI / Coding Standards (push) Failing after 2m31s
CI / PHPStan (push) Failing after 50s
CI / Tests (PHP 8.1) (push) Successful in 50s
CI / Tests (PHP 8.2) (push) Successful in 48s
CI / Tests (PHP 8.3) (push) Successful in 40s
CI / No Debug Code (push) Successful in 2s
Some checks failed
CI / Coding Standards (push) Failing after 2m31s
CI / PHPStan (push) Failing after 50s
CI / Tests (PHP 8.1) (push) Successful in 50s
CI / Tests (PHP 8.2) (push) Successful in 48s
CI / Tests (PHP 8.3) (push) Successful in 40s
CI / No Debug Code (push) Successful in 2s
- Custom DB tables for availability slots and lesson bookings - Instructor (wp-admin) and student (front-end) roles with custom capabilities - REST API under us-scheduler/v1 for availability CRUD and booking - [us_booking] and [us_student_login] shortcodes for student front end - PHPUnit + Brain\Monkey unit test suite (29 tests) - Gitea Actions CI: lint, PHPStan, tests on PHP 8.1/8.2/8.3, no-debug check - Feature docs under docs/features/ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
35
assets/css/frontend.css
Normal file
35
assets/css/frontend.css
Normal file
@@ -0,0 +1,35 @@
|
||||
.us-login-form label {
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.us-login-form input[type="text"],
|
||||
.us-login-form input[type="password"] {
|
||||
width: 100%;
|
||||
max-width: 340px;
|
||||
padding: 8px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.us-error {
|
||||
color: #c00;
|
||||
border-left: 4px solid #c00;
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
#us-booking-app .us-slot {
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
padding: 12px 16px;
|
||||
margin-bottom: 8px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#us-booking-error {
|
||||
color: #c00;
|
||||
margin-top: 8px;
|
||||
}
|
||||
76
assets/js/booking.js
Normal file
76
assets/js/booking.js
Normal file
@@ -0,0 +1,76 @@
|
||||
/* global usScheduler */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
const app = document.getElementById('us-booking-app');
|
||||
if (!app) return;
|
||||
|
||||
const slotList = document.getElementById('us-slot-list');
|
||||
const confirm = document.getElementById('us-booking-confirmation');
|
||||
const errorBox = document.getElementById('us-booking-error');
|
||||
const { restUrl, nonce } = usScheduler;
|
||||
|
||||
function apiFetch(path, options = {}) {
|
||||
return fetch(restUrl + path, {
|
||||
...options,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-WP-Nonce': nonce,
|
||||
...(options.headers || {}),
|
||||
},
|
||||
}).then(async (res) => {
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.message || 'Request failed');
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
errorBox.textContent = message;
|
||||
errorBox.style.display = 'block';
|
||||
}
|
||||
|
||||
function renderSlots(slots) {
|
||||
if (!slots.length) {
|
||||
slotList.innerHTML = '<p>No available lesson slots at this time.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
slotList.innerHTML = slots.map((slot) => `
|
||||
<div class="us-slot">
|
||||
<span>${escHtml(slot.start_dt)} – ${escHtml(slot.end_dt)}</span>
|
||||
<button data-slot-id="${slot.id}" class="us-book-btn">Book</button>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
slotList.querySelectorAll('.us-book-btn').forEach((btn) => {
|
||||
btn.addEventListener('click', () => bookSlot(Number(btn.dataset.slotId)));
|
||||
});
|
||||
}
|
||||
|
||||
function escHtml(str) {
|
||||
return String(str)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
|
||||
function bookSlot(slotId) {
|
||||
errorBox.style.display = 'none';
|
||||
|
||||
apiFetch('bookings', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ slot_id: slotId }),
|
||||
})
|
||||
.then(() => {
|
||||
slotList.style.display = 'none';
|
||||
confirm.style.display = 'block';
|
||||
})
|
||||
.catch((err) => showError(err.message));
|
||||
}
|
||||
|
||||
apiFetch('availability')
|
||||
.then(renderSlots)
|
||||
.catch((err) => showError(err.message));
|
||||
}());
|
||||
Reference in New Issue
Block a user