diff --git a/apps/web/src/stores/categories.ts b/apps/web/src/stores/categories.ts index e19795f..3319698 100644 --- a/apps/web/src/stores/categories.ts +++ b/apps/web/src/stores/categories.ts @@ -8,6 +8,7 @@ export interface Category { color: string is_default: boolean is_tax: boolean + monthly_budget: number | null created_at: string updated_at: string } @@ -29,14 +30,14 @@ export const useCategoriesStore = defineStore('categories', () => { } } - async function create(name: string, color: string, isTax = false) { - const cat = await api.post('/categories', { name, color, is_tax: isTax }) + async function create(name: string, color: string, isTax = false, monthlyBudget: number | null = null) { + const cat = await api.post('/categories', { name, color, is_tax: isTax, monthly_budget: monthlyBudget }) categories.value.push(cat) return cat } - async function update(id: number, name: string, color: string, isTax = false) { - const cat = await api.put(`/categories/${id}`, { name, color, is_tax: isTax }) + async function update(id: number, name: string, color: string, isTax = false, monthlyBudget: number | null = null) { + const cat = await api.put(`/categories/${id}`, { name, color, is_tax: isTax, monthly_budget: monthlyBudget }) const idx = categories.value.findIndex((c) => c.id === id) if (idx !== -1) categories.value[idx] = cat return cat diff --git a/apps/web/src/views/CategoriesView.vue b/apps/web/src/views/CategoriesView.vue index 0429715..cb5c8e9 100644 --- a/apps/web/src/views/CategoriesView.vue +++ b/apps/web/src/views/CategoriesView.vue @@ -6,19 +6,19 @@ import NeonPanel from '@/components/NeonPanel.vue' const store = useCategoriesStore() onMounted(() => store.fetchAll()) -const form = ref({ name: '', color: '#a855f7', is_tax: false }) +const form = ref({ name: '', color: '#a855f7', is_tax: false, monthly_budget: null as number | null }) const editId = ref(null) const formError = ref(null) -function startEdit(id: number, name: string, color: string, isTax: boolean) { +function startEdit(id: number, name: string, color: string, isTax: boolean, budget: number | null) { editId.value = id - form.value = { name, color, is_tax: isTax } + form.value = { name, color, is_tax: isTax, monthly_budget: budget } formError.value = null } function cancelEdit() { editId.value = null - form.value = { name: '', color: '#a855f7', is_tax: false } + form.value = { name: '', color: '#a855f7', is_tax: false, monthly_budget: null } formError.value = null } @@ -26,11 +26,11 @@ async function submit() { formError.value = null try { if (editId.value !== null) { - await store.update(editId.value, form.value.name, form.value.color, form.value.is_tax) + await store.update(editId.value, form.value.name, form.value.color, form.value.is_tax, form.value.monthly_budget) cancelEdit() } else { - await store.create(form.value.name, form.value.color, form.value.is_tax) - form.value = { name: '', color: '#a855f7', is_tax: false } + await store.create(form.value.name, form.value.color, form.value.is_tax, form.value.monthly_budget) + form.value = { name: '', color: '#a855f7', is_tax: false, monthly_budget: null } } } catch (e: any) { formError.value = e.message @@ -66,6 +66,17 @@ async function remove(id: number, name: string) { IMPOSTO +
+ + +

{{ formError }}

@@ -89,8 +100,11 @@ async function remove(id: number, name: string) { {{ cat.name }} PADRÃO IMPOSTO + + R$ {{ cat.monthly_budget.toLocaleString('pt-BR', { minimumFractionDigits: 0, maximumFractionDigits: 0 }) }} +
- +