interaktivna Tablica radnih sati, db
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
// src/stores/taskStore.js
|
||||
// src/stores/taskStore.js
|
||||
import { atom } from 'nanostores';
|
||||
import { api } from '../services/apiClient';
|
||||
import { showToast } from './toastStore';
|
||||
|
||||
export const $tasks = atom([]);
|
||||
export const $tasksLoading = atom(false);
|
||||
export const $taskTemplates = atom([]);
|
||||
export const $taskTemplatesLoading = atom(false);
|
||||
|
||||
const STATUS_LABELS = {
|
||||
aktivan: 'Aktivan',
|
||||
servis: 'U tijeku',
|
||||
zavrsen: 'Završen',
|
||||
neaktivan: 'Otkazano',
|
||||
};
|
||||
|
||||
@@ -35,6 +38,23 @@ export async function fetchTasks() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchTaskTemplates() {
|
||||
$taskTemplatesLoading.set(true);
|
||||
try {
|
||||
const data = await api.get('tasks/tasks/templates/');
|
||||
const templates = Array.isArray(data) ? data : (data?.results ?? []);
|
||||
$taskTemplates.set(templates);
|
||||
return templates;
|
||||
} catch (error) {
|
||||
if (error?.status !== 401) {
|
||||
showToast('Greška pri dohvatu predložaka zadataka.', 'error');
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
$taskTemplatesLoading.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
export async function createTask(data) {
|
||||
const response = await api.post('tasks/tasks/', data);
|
||||
$tasks.set([response, ...$tasks.get()]);
|
||||
|
||||
Reference in New Issue
Block a user