import { defineStore } from 'pinia' import { Inertia } from '@inertiajs/inertia' export const useShiftStore = defineStore('ShiftStore', { state: () => ({ endpoints: { index: '/dashboard/shifts', claim: (id) => `/dashboard/shifts/${id}`, release: (id) => `/dashboard/shifts/${id}`, }, processingId: null, }), actions: { async claim(id) { this.processingId = id try { await window.axios.patch(this.endpoints.claim(id)) Inertia.get(this.endpoints.index) } catch (error) { throw new Error(error.response?.data?.errors?.shift?.[0] ?? 'خطا در انتخاب شیفت') } finally { this.processingId = null } }, async release(id) { this.processingId = id try { await window.axios.delete(this.endpoints.release(id)) Inertia.get(this.endpoints.index) } catch (error) { throw new Error(error.response?.data?.errors?.shift?.[0] ?? 'خطا در لغو شیفت') } finally { this.processingId = null } }, }, })