tons fixes
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
Master Service Calendar
|
||||
</div>
|
||||
|
||||
<!-- This component has no sidebar, so the calendar takes up the full content area -->
|
||||
<div class="flex h-screen font-sans">
|
||||
<div class="flex-1 p-4 overflow-auto">
|
||||
<FullCalendar ref="fullCalendar" :options="calendarOptions" />
|
||||
@@ -28,7 +27,6 @@
|
||||
|
||||
<Footer />
|
||||
|
||||
<!-- Re-using the powerful edit modal for this page -->
|
||||
<ServiceEditModal
|
||||
v-if="selectedServiceForEdit"
|
||||
:service="selectedServiceForEdit"
|
||||
@@ -51,10 +49,10 @@ import ServiceEditModal from './ServiceEditModal.vue';
|
||||
import axios from 'axios';
|
||||
import authHeader from '../../services/auth.header';
|
||||
|
||||
// --- Interfaces ---
|
||||
interface ServiceCall {
|
||||
id: number;
|
||||
scheduled_date: string;
|
||||
customer_id: string;
|
||||
customer_name: string;
|
||||
customer_address: string;
|
||||
customer_town: string;
|
||||
@@ -67,7 +65,7 @@ export default defineComponent({
|
||||
components: { Header, SideBar, Footer, FullCalendar, ServiceEditModal },
|
||||
data() {
|
||||
return {
|
||||
user: null, // For header/sidebar logic if needed
|
||||
user: null,
|
||||
selectedServiceForEdit: null as Partial<ServiceCall> | null,
|
||||
calendarOptions: {
|
||||
plugins: [dayGridPlugin, interactionPlugin],
|
||||
@@ -83,7 +81,6 @@ export default defineComponent({
|
||||
this.fetchEvents();
|
||||
},
|
||||
methods: {
|
||||
// This method fetches ALL events for the master calendar
|
||||
async fetchEvents(): Promise<void> {
|
||||
try {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/service/all`;
|
||||
@@ -94,30 +91,35 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
|
||||
// This opens the modal when a calendar event is clicked
|
||||
// --- THIS IS THE FIX ---
|
||||
handleEventClick(clickInfo: EventClickArg): void {
|
||||
const events = (this.calendarOptions.events as any[]) || [];
|
||||
const originalEvent = events.find(e => e.id == clickInfo.event.id);
|
||||
|
||||
if (originalEvent) {
|
||||
// We "flatten" the nested object from the calendar into the simple,
|
||||
// flat structure that the modal expects.
|
||||
this.selectedServiceForEdit = {
|
||||
id: originalEvent.id,
|
||||
scheduled_date: originalEvent.start,
|
||||
customer_name: originalEvent.title.split(': ')[1] || '',
|
||||
customer_address: '',
|
||||
customer_town: '',
|
||||
customer_id: originalEvent.customer_id,
|
||||
// Extract the customer name from the title
|
||||
customer_name: originalEvent.title.split(': ')[1] || 'Unknown Customer',
|
||||
// Pull the properties out of the nested extendedProps
|
||||
type_service_call: originalEvent.extendedProps.type_service_call,
|
||||
description: originalEvent.extendedProps.description,
|
||||
|
||||
// Add dummy values for other fields the ServiceCall interface expects
|
||||
customer_address: '',
|
||||
customer_town: '',
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
// Closes the modal
|
||||
closeEditModal() {
|
||||
this.selectedServiceForEdit = null;
|
||||
},
|
||||
|
||||
// Saves changes from the modal and refreshes the calendar
|
||||
async handleSaveChanges(updatedService: ServiceCall) {
|
||||
try {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/service/update/${updatedService.id}`;
|
||||
@@ -130,13 +132,12 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
|
||||
// Deletes the service from the modal and refreshes the calendar
|
||||
async handleDeleteService(serviceId: number) {
|
||||
try {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/service/delete/${serviceId}`;
|
||||
const response = await axios.delete(path, { withCredentials: true, headers: authHeader() });
|
||||
if (response.data.ok === true) {
|
||||
await this.fetchEvents(); // Refresh the calendar from the database
|
||||
await this.fetchEvents();
|
||||
this.closeEditModal();
|
||||
} else {
|
||||
console.error("Failed to delete event:", response.data.error);
|
||||
@@ -146,7 +147,6 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
|
||||
// Standard method for user status, e.g., for the header
|
||||
userStatus() {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/auth/whoami';
|
||||
axios({
|
||||
|
||||
@@ -2,58 +2,95 @@
|
||||
<!-- Modal Overlay -->
|
||||
<div class="fixed inset-0 bg-gray-800 bg-opacity-75 flex items-center justify-center z-50">
|
||||
<!-- Modal Content -->
|
||||
<div class="relative bg-white p-6 rounded-lg shadow-xl w-full max-w-lg">
|
||||
<div class="relative bg-base-100 text-base-content p-6 rounded-lg shadow-xl w-full max-w-4xl">
|
||||
|
||||
<!-- Modal Header -->
|
||||
<div class="flex justify-between items-center border-b pb-3 mb-4">
|
||||
<h3 class="text-2xl font-bold text-gray-800">Edit Service Call</h3>
|
||||
<div class="flex justify-between items-center border-b border-gray-700 pb-3 mb-4">
|
||||
<h3 class="text-2xl font-bold">Edit Service Call</h3>
|
||||
<span class="font-bold text-white px-3 py-1 mr-10 rounded" :style="{ backgroundColor: getServiceTypeColor(editableService.type_service_call) }">
|
||||
{{ getServiceTypeName(editableService.type_service_call) }}
|
||||
</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">
|
||||
<button @click="$emit('close-modal')" type="button" class="absolute top-0 right-0 mt-4 mr-4 text-gray-500 hover:text-white 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 -->
|
||||
<!-- Customer & Parts Info Section (Two Columns) -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-4">
|
||||
<!-- Left Column: Customer Info -->
|
||||
<div v-if="customer" class="p-4 bg-base-200 rounded-md">
|
||||
<div class="font-bold text-lg">{{ customer.account_number }}</div>
|
||||
<div class="text-sm">{{ customer.customer_first_name }} {{ customer.customer_last_name }}</div>
|
||||
<div class="text-sm">{{ customer.customer_address }}</div>
|
||||
<div class="text-sm">{{ customer.customer_town }}, {{ customer.customer_state }} {{ customer.customer_zip }}</div>
|
||||
<div class="text-sm mt-1">{{ customer.customer_phone_number }}</div>
|
||||
</div>
|
||||
<div v-else class="p-4 bg-base-200 rounded-md text-center">
|
||||
<p>Loading customer details...</p>
|
||||
</div>
|
||||
|
||||
<!-- ====================================================== -->
|
||||
<!-- ============== SERVICE PARTS (VIEW-ONLY) ============== -->
|
||||
<!-- ====================================================== -->
|
||||
<div v-if="!isLoadingParts && serviceParts" class="p-4 bg-base-200 rounded-md">
|
||||
<h4 class="font-bold text-lg mb-2">Service Parts on File</h4>
|
||||
<div class="grid grid-cols-2 gap-x-4 gap-y-2 text-sm">
|
||||
<div>
|
||||
<label class="block text-xs font-medium opacity-70">Oil Filter</label>
|
||||
<p class="font-semibold">{{ serviceParts.oil_filter || 'N/A' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium opacity-70">Oil Filter 2</label>
|
||||
<p class="font-semibold">{{ serviceParts.oil_filter_2 || 'N/A' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium opacity-70">Oil Nozzle</label>
|
||||
<p class="font-semibold">{{ serviceParts.oil_nozzle || 'N/A' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium opacity-70">Oil Nozzle 2</label>
|
||||
<p class="font-semibold">{{ serviceParts.oil_nozzle_2 || 'N/A' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="p-4 bg-base-200 rounded-md text-center">
|
||||
<p>Loading service parts...</p>
|
||||
</div>
|
||||
<!-- ====================================================== -->
|
||||
<!-- ================ END VIEW-ONLY SECTION =============== -->
|
||||
<!-- ====================================================== -->
|
||||
</div>
|
||||
|
||||
<!-- Form for Editing Service Call Details -->
|
||||
<form @submit.prevent="saveChanges">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<!-- 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.date" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-black">
|
||||
<label for="edit-date" class="block text-sm font-medium">Scheduled Date</label>
|
||||
<input type="date" id="edit-date" v-model="editableService.date" required class="input input-bordered w-full mt-1">
|
||||
</div>
|
||||
|
||||
<!-- NEW: Time Input -->
|
||||
<div class="mb-4">
|
||||
<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">
|
||||
<label for="edit-time" class="block text-sm font-medium">Scheduled Time</label>
|
||||
<select id="edit-time" v-model.number="editableService.time" class="select select-bordered w-full mt-1">
|
||||
<option v-for="hour in 24" :key="hour" :value="hour - 1">{{ (hour - 1).toString().padStart(2, '0') }}:00</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Service Type (Moved to its own row) -->
|
||||
<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-service-type" class="block text-sm font-medium">Type of Service</label>
|
||||
<select id="edit-service-type" v-model.number="editableService.type_service_call" required class="select select-bordered w-full mt-1">
|
||||
<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>
|
||||
<label for="edit-description" class="block text-sm font-medium">Description</label>
|
||||
<textarea id="edit-description" v-model="editableService.description" rows="4" required class="textarea textarea-bordered w-full mt-1"></textarea>
|
||||
</div>
|
||||
|
||||
<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="btn btn-error">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="btn btn-ghost">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -63,36 +100,25 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, PropType } from 'vue';
|
||||
import dayjs from 'dayjs'; // Import dayjs for easier date/time manipulation
|
||||
import dayjs from 'dayjs';
|
||||
import axios from 'axios';
|
||||
import authHeader from '../../services/auth.header';
|
||||
|
||||
interface ServiceCall {
|
||||
id: number;
|
||||
scheduled_date: string; // This is an ISO string like "2025-08-26T14:00:00"
|
||||
customer_name: string;
|
||||
customer_address: string;
|
||||
customer_town: string;
|
||||
type_service_call: number;
|
||||
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
|
||||
}
|
||||
// --- Interfaces ---
|
||||
interface ServiceCall { id: number; scheduled_date: string; customer_id: number; customer_name: string; customer_address: string; customer_town: string; type_service_call: number; description: string; }
|
||||
interface EditableService extends Omit<ServiceCall, 'scheduled_date'> { date: string; time: number; }
|
||||
interface Customer { account_number: string; customer_first_name: string; customer_last_name: string; customer_address: string; customer_town: string; customer_state: number; customer_zip: string; customer_phone_number: string; }
|
||||
interface ServiceParts { customer_id: number; oil_filter: string; oil_filter_2: string; oil_nozzle: string; oil_nozzle_2: string; }
|
||||
|
||||
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<Partial<ServiceCall>>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
props: { service: { type: Object as PropType<Partial<ServiceCall>>, required: true } },
|
||||
data() {
|
||||
return {
|
||||
editableService: {} as Partial<EditableService>,
|
||||
customer: null as Customer | null,
|
||||
serviceParts: null as ServiceParts | null,
|
||||
isLoadingParts: true,
|
||||
serviceOptions: [
|
||||
{ text: 'Tune-up', value: 0 }, { text: 'No Heat', value: 1 }, { text: 'Fix', value: 2 },
|
||||
{ text: 'Tank Install', value: 3 }, { text: 'Other', value: 4 },
|
||||
@@ -103,34 +129,50 @@ export default defineComponent({
|
||||
service: {
|
||||
handler(newVal) {
|
||||
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(),
|
||||
};
|
||||
this.editableService = { ...newVal, date: scheduled.format('YYYY-MM-DD'), time: scheduled.hour() };
|
||||
if (newVal.customer_id) {
|
||||
this.getCustomer(newVal.customer_id);
|
||||
this.getServiceParts(newVal.customer_id);
|
||||
}
|
||||
},
|
||||
immediate: true,
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
saveChanges() {
|
||||
// Re-combine date and time into a single ISO string before emitting
|
||||
getCustomer(customerId: number) {
|
||||
this.customer = null;
|
||||
let path = import.meta.env.VITE_BASE_URL + '/customer/' + customerId;
|
||||
axios.get(path, { headers: authHeader() })
|
||||
.then((response: any) => { this.customer = response.data; })
|
||||
.catch((error: any) => { console.error("Failed to fetch customer details for modal:", error); });
|
||||
},
|
||||
getServiceParts(customerId: number) {
|
||||
this.isLoadingParts = true;
|
||||
this.serviceParts = null;
|
||||
let path = `${import.meta.env.VITE_BASE_URL}/service/parts/customer/${customerId}`;
|
||||
axios.get(path, { headers: authHeader() })
|
||||
.then((response: any) => { this.serviceParts = response.data; })
|
||||
.catch((error: any) => { console.error("Failed to fetch service parts:", error); })
|
||||
.finally(() => { this.isLoadingParts = false; });
|
||||
},
|
||||
// --- UPDATED: Simplified saveChanges method ---
|
||||
async saveChanges() {
|
||||
// This method now only saves the service call itself.
|
||||
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 };
|
||||
|
||||
const finalPayload = {
|
||||
...this.service,
|
||||
...this.editableService,
|
||||
scheduled_date: combinedDateTime,
|
||||
};
|
||||
|
||||
this.$emit('save-changes', finalPayload);
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/service/update/${finalPayload.id}`;
|
||||
try {
|
||||
await axios.put(path, finalPayload, { headers: authHeader(), withCredentials: true });
|
||||
this.$emit('save-changes', finalPayload);
|
||||
} catch (error) {
|
||||
console.error("Failed to save changes:", error);
|
||||
alert("An error occurred while saving. Please check the console.");
|
||||
}
|
||||
},
|
||||
confirmDelete() {
|
||||
if (this.service.id && window.confirm(`Are you sure you want to delete this service call?`)) {
|
||||
@@ -139,16 +181,12 @@ export default defineComponent({
|
||||
},
|
||||
getServiceTypeName(typeId: number | undefined | null): string {
|
||||
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',
|
||||
};
|
||||
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';
|
||||
const colorMap: { [key: number]: string } = {
|
||||
0: 'blue', 1: 'red', 2: 'green', 3: '#B58900', 4: 'black',
|
||||
};
|
||||
const colorMap: { [key: number]: string } = { 0: 'blue', 1: 'red', 2: 'green', 3: '#B58900', 4: 'black' };
|
||||
return colorMap[typeId] || 'gray';
|
||||
}
|
||||
},
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
<p>No service calls found.</p>
|
||||
</div>
|
||||
|
||||
<!-- ============================================= -->
|
||||
<!-- ============== UPDATED TABLE SECTION ============== -->
|
||||
<!-- ============================================= -->
|
||||
<div v-else class="overflow-x-auto rounded-lg">
|
||||
<table class="min-w-full divide-y divide-gray-700">
|
||||
<thead class="bg-base-200">
|
||||
@@ -46,11 +43,13 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-base-100 divide-y divide-gray-700">
|
||||
<!-- The hover color is now a slightly lighter shade of the background -->
|
||||
<tr v-for="service in services" :key="service.id" @click="openEditModal(service)" class="hover:bg-base-300 cursor-pointer">
|
||||
<td class="px-6 py-4 whitespace-nowrap">{{ formatDate(service.scheduled_date) }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">{{ formatTime(service.scheduled_date) }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">{{ service.customer_name }}</td>
|
||||
|
||||
<td class="px-6 py-4 whitespace-nowrap hover:text-blue-600">{{ service.customer_name }}</td>
|
||||
|
||||
|
||||
<td class="px-6 py-4 whitespace-nowrap">{{ service.customer_address }}, {{ service.customer_town }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap font-medium" :style="{ color: getServiceTypeColor(service.type_service_call) }">
|
||||
{{ getServiceTypeName(service.type_service_call) }}
|
||||
@@ -60,9 +59,6 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- ============================================= -->
|
||||
<!-- ============== END UPDATED SECTION ============== -->
|
||||
<!-- ============================================= -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -91,6 +87,7 @@ import dayjs from 'dayjs'; // Import dayjs to handle date/time formatting
|
||||
interface ServiceCall {
|
||||
id: number;
|
||||
scheduled_date: string;
|
||||
customer_id: number;
|
||||
customer_name: string;
|
||||
customer_address: string;
|
||||
customer_town: string;
|
||||
|
||||
@@ -42,15 +42,13 @@ import Header from '../../../layouts/headers/headerauth.vue';
|
||||
import FullCalendar from '@fullcalendar/vue3';
|
||||
import dayGridPlugin from '@fullcalendar/daygrid';
|
||||
import interactionPlugin from '@fullcalendar/interaction';
|
||||
// --- FIX: Removed 'EventApi' as it's no longer used ---
|
||||
import { CalendarOptions, EventClickArg } from '@fullcalendar/core';
|
||||
import EventSidebar from './EventSidebar.vue';
|
||||
import ServiceEditModal from '../ServiceEditModal.vue';
|
||||
import ServiceEditModal from '../../service/ServiceEditModal.vue';
|
||||
import axios from 'axios';
|
||||
import authHeader from '../../../services/auth.header';
|
||||
|
||||
// --- Interfaces (no changes) ---
|
||||
interface ServiceCall { id: number; scheduled_date: string; customer_name: string; customer_address: string; customer_town: string; type_service_call: number; description: string; }
|
||||
interface ServiceCall { id: number; scheduled_date: string; customer_id: string; customer_name: string; customer_address: string; customer_town: string; type_service_call: number; description: string; }
|
||||
interface Customer { id: number; customer_last_name: string; customer_first_name: string; customer_town: string; customer_state: number; customer_zip: string; customer_phone_number: string; customer_address: string; customer_home_type: number; customer_apt: string; }
|
||||
|
||||
export default defineComponent({
|
||||
@@ -60,12 +58,11 @@ export default defineComponent({
|
||||
return {
|
||||
isLoading: false,
|
||||
selectedServiceForEdit: null as Partial<ServiceCall> | null,
|
||||
// --- FIX: Define calendarOptions directly here to resolve "unused variable" warnings ---
|
||||
calendarOptions: {
|
||||
plugins: [dayGridPlugin, interactionPlugin],
|
||||
initialView: 'dayGridMonth',
|
||||
weekends: true,
|
||||
events: [] as any[], // Start with a typed empty array
|
||||
events: [] as any[],
|
||||
eventClick: this.handleEventClick,
|
||||
} as CalendarOptions,
|
||||
customer: null as Customer | null,
|
||||
@@ -80,29 +77,35 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
created() {
|
||||
// The created hook is now only responsible for fetching data
|
||||
this.fetchEvents();
|
||||
},
|
||||
methods: {
|
||||
// --- THIS IS THE FIX ---
|
||||
// The logic from ServiceCalendar.vue is now correctly applied here.
|
||||
handleEventClick(clickInfo: EventClickArg): void {
|
||||
const events = (this.calendarOptions.events as any[]) || [];
|
||||
const originalEvent = events.find(e => e.id == clickInfo.event.id);
|
||||
|
||||
if (originalEvent) {
|
||||
// We "flatten" the nested object from the calendar into the simple,
|
||||
// flat structure that the modal expects, ensuring customer_id is included.
|
||||
this.selectedServiceForEdit = {
|
||||
id: originalEvent.id,
|
||||
scheduled_date: originalEvent.start,
|
||||
customer_name: originalEvent.title.split(': ')[1] || '',
|
||||
customer_address: '',
|
||||
customer_town: '',
|
||||
customer_id: originalEvent.customer_id, // This was the missing piece
|
||||
customer_name: originalEvent.title.split(': ')[1] || 'Unknown Customer',
|
||||
type_service_call: originalEvent.extendedProps.type_service_call,
|
||||
description: originalEvent.extendedProps.description,
|
||||
customer_address: '',
|
||||
customer_town: '',
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
closeEditModal() {
|
||||
this.selectedServiceForEdit = null;
|
||||
},
|
||||
|
||||
async handleSaveChanges(updatedService: ServiceCall) {
|
||||
try {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/service/update/${updatedService.id}`;
|
||||
@@ -114,10 +117,22 @@ export default defineComponent({
|
||||
alert("An error occurred while saving. Please check the console.");
|
||||
}
|
||||
},
|
||||
|
||||
async handleDeleteService(serviceId: number) {
|
||||
await this.handleEventDelete(String(serviceId));
|
||||
this.closeEditModal();
|
||||
try {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/service/delete/${serviceId}`;
|
||||
const response = await axios.delete(path, { withCredentials: true, headers: authHeader() });
|
||||
if (response.data.ok === true) {
|
||||
await this.fetchEvents();
|
||||
this.closeEditModal();
|
||||
} else {
|
||||
console.error("Failed to delete event:", response.data.error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error deleting event:", error);
|
||||
}
|
||||
},
|
||||
|
||||
async getCustomer(customerId: string): Promise<void> {
|
||||
this.isLoading = true;
|
||||
this.customer = null;
|
||||
@@ -133,6 +148,7 @@ export default defineComponent({
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async fetchEvents(): Promise<void> {
|
||||
try {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/service/all`;
|
||||
@@ -142,6 +158,7 @@ export default defineComponent({
|
||||
console.error("Error fetching all calendar events:", error);
|
||||
}
|
||||
},
|
||||
|
||||
async handleEventScheduled(eventData: any): Promise<void> {
|
||||
if (!this.customer) {
|
||||
alert("Error: A customer must be loaded in the sidebar to create a new event.");
|
||||
@@ -154,7 +171,6 @@ export default defineComponent({
|
||||
};
|
||||
const path = import.meta.env.VITE_BASE_URL + "/service/create";
|
||||
const response = await axios.post(path, payload, { withCredentials: true, headers: authHeader() });
|
||||
|
||||
if (response.data.ok === true) {
|
||||
await this.fetchEvents();
|
||||
} else {
|
||||
@@ -164,20 +180,10 @@ export default defineComponent({
|
||||
console.error("Error creating event:", error);
|
||||
}
|
||||
},
|
||||
|
||||
async handleEventDelete(eventId: string): Promise<void> {
|
||||
try {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/service/delete/${eventId}`;
|
||||
const response = await axios.delete(path, { withCredentials: true, headers: authHeader() });
|
||||
if (response.data.ok === true) {
|
||||
const calendarApi = (this.$refs.fullCalendar as any).getApi();
|
||||
const eventToRemove = calendarApi.getEventById(eventId);
|
||||
if (eventToRemove) eventToRemove.remove();
|
||||
} else {
|
||||
console.error("Failed to delete event:", response.data.error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error deleting event:", error);
|
||||
}
|
||||
// This is a simple alias now, as handleDeleteService is more specific
|
||||
await this.handleDeleteService(Number(eventId));
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user