refactor: Refactor weekly availability section to use tabs
This commit is contained in:
1 parent
3d8f1f4da7
commit
ea9036ec79
1 file changed
+88
-22
+88
-22
@@ -126,36 +126,52 @@
|
||||
|
||||
<div>
|
||||
<h3 class="text-md font-medium text-gray-800 mb-3">Weekly Availability & Hours</h3>
|
||||
<div class="space-y-4">
|
||||
{% assign days = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday" | split: "," %}
|
||||
{% for day in days %}
|
||||
<div class="bg-gray-50 p-4 rounded-lg shadow-sm">
|
||||
<label for="available-{{ day | downcase }}" class="flex items-center justify-between w-full cursor-pointer">
|
||||
<span class="text-sm font-medium text-gray-900">{{ day }}</span>
|
||||
{% assign days_list = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday" | split: "," %}
|
||||
|
||||
<!-- Day Selector Tab Buttons -->
|
||||
<div class="mb-4">
|
||||
<div class="flex flex-wrap border-b border-gray-300">
|
||||
{% for day_label in days_list %}
|
||||
<button type="button"
|
||||
class="day-tab-button -mb-px py-2 px-4 border-b-2 border-transparent text-sm font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none"
|
||||
data-day-target="{{ day_label | downcase }}">
|
||||
{{ day_label }}
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Content for each day's availability -->
|
||||
{% for day_label in days_list %}
|
||||
<div id="availability-content-{{ day_label | downcase }}" class="day-availability-content hidden">
|
||||
<div class="bg-gray-50 p-4 rounded-lg shadow-sm space-y-4">
|
||||
<label for="available-{{ day_label | downcase }}" class="flex items-center justify-between w-full cursor-pointer">
|
||||
<span class="text-sm font-medium text-gray-900">Available on {{ day_label }}</span>
|
||||
<input type="checkbox"
|
||||
id="available-{{ day | downcase }}"
|
||||
id="available-{{ day_label | downcase }}"
|
||||
name="available_days[]"
|
||||
value="{{ day }}"
|
||||
class="sr-only peer"
|
||||
onchange="toggleTimeSelection('{{ day | downcase }}')">
|
||||
value="{{ day_label }}"
|
||||
class="sr-only peer day-specific-availability-toggle"
|
||||
data-day="{{ day_label | downcase }}"
|
||||
onchange="toggleDayTimeSelection('{{ day_label | downcase }}')">
|
||||
<div class="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-offset-2 peer-focus:ring-indigo-500 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
|
||||
</label>
|
||||
|
||||
<div id="time-selection-{{ day | downcase }}" class="mt-4 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3 hidden">
|
||||
<div id="time-selection-{{ day_label | downcase }}" class="day-specific-time-inputs mt-4 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3 hidden">
|
||||
<div>
|
||||
<label for="start-time-{{ day | downcase }}" class="block text-xs font-medium text-gray-700 mb-1">Open</label>
|
||||
<input type="time" id="start-time-{{ day | downcase }}" name="start_time_{{ day | downcase }}" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-white">
|
||||
<label for="start-time-{{ day_label | downcase }}" class="block text-xs font-medium text-gray-700 mb-1">Open</label>
|
||||
<input type="time" id="start-time-{{ day_label | downcase }}" name="start_time_{{ day_label | downcase }}" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-white">
|
||||
</div>
|
||||
<div>
|
||||
<label for="end-time-{{ day | downcase }}" class="block text-xs font-medium text-gray-700 mb-1">Close</label>
|
||||
<input type="time" id="end-time-{{ day | downcase }}" name="end_time_{{ day | downcase }}" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-white">
|
||||
<label for="end-time-{{ day_label | downcase }}" class="block text-xs font-medium text-gray-700 mb-1">Close</label>
|
||||
<input type="time" id="end-time-{{ day_label | downcase }}" name="end_time_{{ day_label | downcase }}" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-white">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-8 flex justify-between">
|
||||
<button type="button" class="prev-step-btn bg-gray-200 hover:bg-gray-300 text-gray-700 font-semibold py-2 px-6 rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-gray-400 focus:ring-opacity-50 transition-colors">
|
||||
<span aria-hidden="true">←</span> Previous
|
||||
@@ -333,21 +349,71 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
// Availability: Toggle time selection based on day checkbox
|
||||
window.toggleTimeSelection = function(day) {
|
||||
const checkbox = document.getElementById(`available-${day}`);
|
||||
const timeSelectionDiv = document.getElementById(`time-selection-${day}`);
|
||||
const startTimeInput = document.getElementById(`start-time-${day}`);
|
||||
const endTimeInput = document.getElementById(`end-time-${day}`);
|
||||
window.toggleDayTimeSelection = function(day) {
|
||||
const checkbox = document.getElementById(`available-${day}`); // This ID is from the checkbox itself
|
||||
const timeSelectionDiv = document.getElementById(`time-selection-${day}`); // This ID is for the time inputs container
|
||||
|
||||
if (checkbox && timeSelectionDiv) {
|
||||
if (checkbox.checked) {
|
||||
timeSelectionDiv.classList.remove('hidden');
|
||||
} else {
|
||||
timeSelectionDiv.classList.add('hidden');
|
||||
// Optionally clear or disable time inputs when unchecked
|
||||
// Optionally clear time inputs
|
||||
const startTimeInput = document.getElementById(`start-time-${day}`);
|
||||
const endTimeInput = document.getElementById(`end-time-${day}`);
|
||||
if(startTimeInput) startTimeInput.value = '';
|
||||
if(endTimeInput) endTimeInput.value = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Weekly Availability Tabs Logic
|
||||
const dayTabButtons = document.querySelectorAll('.day-tab-button');
|
||||
const dayAvailabilityContents = document.querySelectorAll('.day-availability-content');
|
||||
|
||||
function setActiveDayTab(targetDay) {
|
||||
dayTabButtons.forEach(button => {
|
||||
const isTarget = button.dataset.dayTarget === targetDay;
|
||||
button.classList.toggle('border-indigo-500', isTarget); // Active tab style
|
||||
button.classList.toggle('text-indigo-600', isTarget);
|
||||
button.classList.toggle('font-semibold', isTarget); // Make active tab font bolder
|
||||
button.classList.toggle('text-gray-500', !isTarget); // Inactive tab style
|
||||
button.classList.toggle('hover:border-gray-300', !isTarget); // Corrected hover for inactive
|
||||
button.classList.toggle('border-transparent', !isTarget);
|
||||
});
|
||||
|
||||
dayAvailabilityContents.forEach(content => {
|
||||
content.classList.toggle('hidden', content.id !== `availability-content-${targetDay}`);
|
||||
});
|
||||
|
||||
// Ensure the time selection visibility is correct for the newly shown tab
|
||||
const activeCheckbox = document.querySelector(`#availability-content-${targetDay} .day-specific-availability-toggle`);
|
||||
if (activeCheckbox) {
|
||||
// Call toggleDayTimeSelection to correctly show/hide based on checkbox state
|
||||
toggleDayTimeSelection(targetDay);
|
||||
}
|
||||
}
|
||||
|
||||
dayTabButtons.forEach(button => {
|
||||
button.addEventListener('click', function () {
|
||||
setActiveDayTab(this.dataset.dayTarget);
|
||||
});
|
||||
});
|
||||
|
||||
// Initialize with the first day active (e.g., Monday) or based on existing data if applicable
|
||||
if (dayTabButtons.length > 0) {
|
||||
// Check if any day is already checked (e.g. form reload with validation errors)
|
||||
let initiallySelectedDay = dayTabButtons[0].dataset.dayTarget; // Default to first tab
|
||||
for (let i = 0; i < dayAvailabilityContents.length; i++) {
|
||||
const content = dayAvailabilityContents[i];
|
||||
const checkbox = content.querySelector('.day-specific-availability-toggle');
|
||||
if (checkbox && checkbox.checked) {
|
||||
initiallySelectedDay = checkbox.dataset.day;
|
||||
break;
|
||||
}
|
||||
}
|
||||
setActiveDayTab(initiallySelectedDay);
|
||||
}
|
||||
|
||||
// Form submission
|
||||
const newListingForm = document.getElementById('new-listing-form');
|
||||
|
||||
Reference in new issue
Block a user