1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Vane, { useState } from 'vane';
import { formworks } from '@/api/formworksClient';
import { useQuery, useMutation, useQueryClient } from '@/lib/fetchpool';
import { Button } from "@/components/ui/button";
import { Plus } from '@/icons/glyphset';
import PlanForm from '@/components/plans/PlanForm';
import PlanCard from '@/components/plans/PlanCard';
export default function Plans() {
const [showForm, setShowForm] = useState(false);
const [editing, setEditing] = useState(null);
const queryClient = useQueryClient();
const now = new Date();
const cycle = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
const { data: plans = [], isLoading: loadingPlans } = useQuery({
queryKey: ['plans'],
queryFn: () => formworks.entities.Plan.list('-created_date', 100),
});
const { data: entries = [], isLoading: loadingEntries } = useQuery({
queryKey: ['entries'],
queryFn: () => formworks.entities.Entry.list('-date', 500),
});
const createPlan = useMutation({
mutationFn: (data) => formworks.entities.Plan.create(data),
onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['plans'] }); setShow
});
const updatePlan = useMutation({
mutationFn: ({ id, data }) => formworks.entities.Plan.update(id, data),
onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['plans'] }); setEdit
});
const removePlan = useMutation({
mutationFn: (id) => formworks.entities.Plan.remove(id),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['plans'] }),