diff --git a/openapi.yaml b/openapi.yaml index 5599cdaf..c804fbc7 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -1244,18 +1244,68 @@ paths: - Departments summary: Remove category from department operationId: removeDepartmentCategory - parameters: - - name: department_id - in: query - required: true - schema: {type: integer} - - name: category_id - in: query - required: true - schema: {type: integer} responses: '200': {description: Success} + /departments/self-serve/enabled: + get: + tags: + - Departments + summary: Get department self-serve status + description: Check if self-serve is enabled for a specific department + operationId: getDepartmentSelfServeEnabled + parameters: + - name: id + in: query + required: true + description: Department ID + schema: + type: integer + responses: + '200': + description: Successfully retrieved status + content: + application/json: + schema: + type: object + properties: + enabled: + type: boolean + '404': + $ref: '#/components/responses/NotFound' + put: + tags: + - Departments + summary: Update department self-serve status + description: Enable or disable self-serve for a specific department + operationId: updateDepartmentSelfServeEnabled + parameters: + - name: id + in: query + required: true + description: Department ID + schema: + type: integer + - name: enabled + in: query + required: true + description: Enabled status (true/false) + schema: + type: string + enum: ['true', 'false'] + responses: + '200': + description: Status updated successfully + content: + application/json: + schema: + type: object + properties: + message: + type: string + '404': + $ref: '#/components/responses/NotFound' + /departments/order/recommended: get: tags: diff --git a/src/components/displays/department/moduleNavigation/DepartmentModulesDisplay.vue b/src/components/displays/department/moduleNavigation/DepartmentModulesDisplay.vue index a879f316..1e02b0e6 100644 --- a/src/components/displays/department/moduleNavigation/DepartmentModulesDisplay.vue +++ b/src/components/displays/department/moduleNavigation/DepartmentModulesDisplay.vue @@ -3,8 +3,12 @@ import {ref, watch} from 'vue'; import { useRouter } from 'vue-router'; import { authenticatedRequest } from "@/components/session/authenticatedRequest.vue"; import {BSwitch} from "buefy"; +import {useToast} from 'vue-toast-notification'; const router = useRouter(); +const toast = useToast(); + +const selfServeEnabled = ref(false); const modules = [ { @@ -74,8 +78,21 @@ const modules = [ }, count: ref(0), hasSwitch: true, - onToggle: (newValue) => { - console.log("Toggle wash lanes to: " + newValue); + switchValue: selfServeEnabled, + onToggle: async (newValue) => { + const departmentId = getDepartmentId(); + if (!departmentId) return; + + try { + await authenticatedRequest(`/departments/self-serve/enabled?id=${departmentId}&enabled=${newValue}`, 'PUT'); + selfServeEnabled.value = newValue; + toast.success(`Selvvask er nu ${newValue ? 'aktiveret' : 'deaktiveret'}`); + } catch (error) { + console.error("Failed to update self-serve status", error); + // Revert switch value on error + selfServeEnabled.value = !newValue; + toast.error("Kunne ikke opdatere selvvask status"); + } } } /** @@ -138,9 +155,25 @@ const getTodaysBookings = async () => { // Get the bookings getTodaysBookings(); +// Get the self-serve status +const getSelfServeStatus = async () => { + const departmentId = getDepartmentId(); + if (!departmentId) return; + + try { + const response = await authenticatedRequest(`/departments/self-serve/enabled?id=${departmentId}`, 'GET'); + selfServeEnabled.value = response.data.enabled; + } catch (error) { + console.error("Failed to fetch self-serve status", error); + } +}; + +getSelfServeStatus(); + // Watch the departmentId watch(() => router.currentRoute.value.params.departmentId, () => { getTodaysBookings(); + getSelfServeStatus(); }); // Update the bookings every 30 seconds @@ -163,7 +196,7 @@ setInterval(() => {