Working calender/service
This commit is contained in:
@@ -12,67 +12,48 @@
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<button
|
||||
@click="$emit('close-modal')"
|
||||
type="button"
|
||||
class="absolute top-0 right-0 mt-4 mr-4 text-gray-400 hover:text-gray-600 focus:outline-none"
|
||||
aria-label="Close modal"
|
||||
>
|
||||
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
<button @click="$emit('close-modal')" type="button" class="absolute top-0 right-0 mt-4 mr-4 text-gray-400 hover:text-gray-600 focus:outline-none" aria-label="Close modal">
|
||||
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" /></svg>
|
||||
</button>
|
||||
|
||||
<!-- Form for Editing -->
|
||||
<form @submit.prevent="saveChanges">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<!-- Scheduled Date -->
|
||||
<!-- Scheduled Date Input -->
|
||||
<div class="mb-4">
|
||||
<label for="edit-date" class="block text-sm font-medium text-gray-700">Scheduled Date</label>
|
||||
<input type="date" id="edit-date" v-model="editableService.scheduled_date" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-black">
|
||||
<input type="date" id="edit-date" v-model="editableService.date" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-black">
|
||||
</div>
|
||||
|
||||
<!-- Service Type -->
|
||||
<!-- NEW: Time Input -->
|
||||
<div class="mb-4">
|
||||
<label for="edit-service-type" class="block text-sm font-medium text-gray-700">Type of Service</label>
|
||||
<select id="edit-service-type" v-model.number="editableService.type_service_call" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-black">
|
||||
<option v-for="option in serviceOptions" :key="option.value" :value="option.value">
|
||||
{{ option.text }}
|
||||
</option>
|
||||
<label for="edit-time" class="block text-sm font-medium text-gray-700">Scheduled Time</label>
|
||||
<select id="edit-time" v-model.number="editableService.time" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-black">
|
||||
<option v-for="hour in 24" :key="hour" :value="hour - 1">{{ (hour - 1).toString().padStart(2, '0') }}:00</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Description -->
|
||||
|
||||
<!-- Service Type (Moved to its own row) -->
|
||||
<div class="mb-4">
|
||||
<label for="edit-description" class="block text-sm font-medium text-gray-700">Description</label>
|
||||
<!-- ====================================================== -->
|
||||
<!-- ============== THIS LINE HAS BEEN UPDATED ============== -->
|
||||
<!-- ====================================================== -->
|
||||
<textarea
|
||||
id="edit-description"
|
||||
v-model="editableService.description"
|
||||
rows="4"
|
||||
required
|
||||
class="mt-1 block w-full rounded-md border border-gray-300 shadow-sm text-black focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"
|
||||
></textarea>
|
||||
<!-- ====================================================== -->
|
||||
<!-- ================ END OF UPDATED LINE ================ -->
|
||||
<!-- ====================================================== -->
|
||||
<label for="edit-service-type" class="block text-sm font-medium text-gray-700">Type of Service</label>
|
||||
<select id="edit-service-type" v-model.number="editableService.type_service_call" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-black">
|
||||
<option v-for="option in serviceOptions" :key="option.value" :value="option.value">
|
||||
{{ option.text }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="edit-description" class="block text-sm font-medium text-gray-700">Description</label>
|
||||
<textarea id="edit-description" v-model="editableService.description" rows="4" required class="mt-1 block w-full rounded-md border border-gray-300 shadow-sm text-black focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"></textarea>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="mt-6 flex justify-between items-center">
|
||||
<button @click.prevent="confirmDelete" type="button" class="px-4 py-2 bg-red-600 text-white font-medium rounded-md shadow-sm hover:bg-red-700">
|
||||
Delete Call
|
||||
</button>
|
||||
<button @click.prevent="confirmDelete" type="button" class="px-4 py-2 bg-red-600 text-white font-medium rounded-md shadow-sm hover:bg-red-700">Delete Call</button>
|
||||
<div class="flex space-x-3">
|
||||
<button @click.prevent="$emit('close-modal')" type="button" class="px-4 py-2 bg-gray-200 text-gray-800 font-medium rounded-md shadow-sm hover:bg-gray-300">
|
||||
Cancel
|
||||
</button>
|
||||
<button type="submit" class="px-4 py-2 bg-blue-600 text-white font-medium rounded-md shadow-sm hover:bg-blue-700">
|
||||
Save Changes
|
||||
</button>
|
||||
<button @click.prevent="$emit('close-modal')" type="button" class="px-4 py-2 bg-gray-200 text-gray-800 font-medium rounded-md shadow-sm hover:bg-gray-300">Cancel</button>
|
||||
<button type="submit" class="px-4 py-2 bg-blue-600 text-white font-medium rounded-md shadow-sm hover:bg-blue-700">Save Changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -82,10 +63,11 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, PropType } from 'vue';
|
||||
import dayjs from 'dayjs'; // Import dayjs for easier date/time manipulation
|
||||
|
||||
interface ServiceCall {
|
||||
id: number;
|
||||
scheduled_date: string;
|
||||
scheduled_date: string; // This is an ISO string like "2025-08-26T14:00:00"
|
||||
customer_name: string;
|
||||
customer_address: string;
|
||||
customer_town: string;
|
||||
@@ -93,33 +75,43 @@ interface ServiceCall {
|
||||
description: string;
|
||||
}
|
||||
|
||||
// Define the shape of our local, editable object
|
||||
interface EditableService extends Omit<ServiceCall, 'scheduled_date'> {
|
||||
date: string; // 'YYYY-MM-DD'
|
||||
time: number; // 0-23
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ServiceEditModal',
|
||||
props: {
|
||||
// The prop can be a full ServiceCall or a simplified object from the calendar
|
||||
service: {
|
||||
type: Object as PropType<ServiceCall>,
|
||||
type: Object as PropType<Partial<ServiceCall>>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
editableService: {} as Partial<ServiceCall>,
|
||||
editableService: {} as Partial<EditableService>,
|
||||
serviceOptions: [
|
||||
{ text: 'Tune-up', value: 0 },
|
||||
{ text: 'No Heat', value: 1 },
|
||||
{ text: 'Fix', value: 2 },
|
||||
{ text: 'Tank Install', value: 3 },
|
||||
{ text: 'Other', value: 4 },
|
||||
{ text: 'Tune-up', value: 0 }, { text: 'No Heat', value: 1 }, { text: 'Fix', value: 2 },
|
||||
{ text: 'Tank Install', value: 3 }, { text: 'Other', value: 4 },
|
||||
],
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
service: {
|
||||
handler(newVal) {
|
||||
this.editableService = JSON.parse(JSON.stringify(newVal));
|
||||
if (this.editableService.scheduled_date) {
|
||||
this.editableService.scheduled_date = this.editableService.scheduled_date.split('T')[0];
|
||||
}
|
||||
if (!newVal) return;
|
||||
|
||||
// The date string could be from the DB (full ISO) or from FullCalendar (simpler)
|
||||
const scheduled = dayjs(newVal.scheduled_date || new Date());
|
||||
|
||||
this.editableService = {
|
||||
...newVal,
|
||||
date: scheduled.format('YYYY-MM-DD'),
|
||||
time: scheduled.hour(),
|
||||
};
|
||||
},
|
||||
immediate: true,
|
||||
deep: true,
|
||||
@@ -127,26 +119,33 @@ export default defineComponent({
|
||||
},
|
||||
methods: {
|
||||
saveChanges() {
|
||||
this.$emit('save-changes', this.editableService);
|
||||
// Re-combine date and time into a single ISO string before emitting
|
||||
const date = this.editableService.date;
|
||||
const time = this.editableService.time || 0;
|
||||
const combinedDateTime = dayjs(`${date} ${time}:00`).format('YYYY-MM-DDTHH:mm:ss');
|
||||
|
||||
const finalPayload = {
|
||||
...this.service,
|
||||
...this.editableService,
|
||||
scheduled_date: combinedDateTime,
|
||||
};
|
||||
|
||||
this.$emit('save-changes', finalPayload);
|
||||
},
|
||||
confirmDelete() {
|
||||
if (window.confirm(`Are you sure you want to delete this service call for "${this.service.customer_name}"?`)) {
|
||||
if (this.service.id && window.confirm(`Are you sure you want to delete this service call?`)) {
|
||||
this.$emit('delete-service', this.service.id);
|
||||
}
|
||||
},
|
||||
getServiceTypeName(typeId: number | undefined | null): string {
|
||||
if (typeId === undefined || typeId === null) {
|
||||
return 'Unknown';
|
||||
}
|
||||
if (typeId === undefined || typeId === null) return 'Unknown';
|
||||
const typeMap: { [key: number]: string } = {
|
||||
0: 'Tune-up', 1: 'No Heat', 2: 'Fix', 3: 'Tank Install', 4: 'Other',
|
||||
};
|
||||
return typeMap[typeId] || 'Unknown';
|
||||
},
|
||||
getServiceTypeColor(typeId: number | undefined | null): string {
|
||||
if (typeId === undefined || typeId === null) {
|
||||
return 'gray';
|
||||
}
|
||||
if (typeId === undefined || typeId === null) return 'gray';
|
||||
const colorMap: { [key: number]: string } = {
|
||||
0: 'blue', 1: 'red', 2: 'green', 3: '#B58900', 4: 'black',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user