feat: #45 meta de poupança configurável + conquistas genéricas

- Nova tabela user_settings com savings_goal_pct (default 40%)
- API GET /api/settings, PUT /api/settings
- DashboardService inclui savings_goal_pct no payload
- DashboardHandler dispara savings_checked com goal configurado
- GameService.NotifyAction: checa pct >= goal (sem hardcode de 40%)
- SettingsView: painel META DE POUPANÇA com input configurável
- HomeView: widget mostra meta dinâmica (META: X%) e usa savingsGoal
- stores/settings.ts: store com fetch e update

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
2026-05-28 22:32:08 -03:00
co-authored by Claude Sonnet 4.6
parent 9fada4997a
commit 1d59cb2a0e
15 changed files with 296 additions and 15 deletions
+40
View File
@@ -0,0 +1,40 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { api } from '@/services/api'
export interface UserSettings {
savings_goal_pct: number
}
export const useSettingsStore = defineStore('settings', () => {
const settings = ref<UserSettings>({ savings_goal_pct: 40 })
const loading = ref(false)
const error = ref<string | null>(null)
async function fetch() {
loading.value = true
error.value = null
try {
settings.value = await api.get<UserSettings>('/settings')
} catch (e: any) {
error.value = e.message
} finally {
loading.value = false
}
}
async function update(input: UserSettings) {
loading.value = true
error.value = null
try {
settings.value = await api.put<UserSettings>('/settings', input)
} catch (e: any) {
error.value = e.message
throw e
} finally {
loading.value = false
}
}
return { settings, loading, error, fetch, update }
})
+4 -3
View File
@@ -53,8 +53,9 @@ const xpPct = computed(() => {
if (!p) return 0
return Math.round((p.xp / p.xp_to_next) * 100)
})
const savingsPct = computed(() => dash.data?.savings_pct ?? 0)
const savingsOk = computed(() => savingsPct.value >= 40)
const savingsPct = computed(() => dash.data?.savings_pct ?? 0)
const savingsGoal = computed(() => dash.data?.savings_goal_pct ?? 40)
const savingsOk = computed(() => savingsPct.value >= savingsGoal.value)
const today = new Date()
const isCurrentMonth = computed(() => currentMonth.value === today.toISOString().slice(0, 7))
@@ -142,7 +143,7 @@ async function markLate(id: number) {
</div>
<XPBar :pct="savingsPct" size="lg" :success="savingsOk" :danger="!savingsOk" />
<div class="hero-sub fc-mono">
META: 40% &nbsp;·&nbsp;
META: {{ savingsGoal.toFixed(0) }}% &nbsp;·&nbsp;
<span :class="savingsOk ? 'fc-text-green' : 'fc-text-red'">
{{ savingsOk ? 'META BATIDA ✓' : 'ABAIXO DA META' }}
</span>
+64 -1
View File
@@ -1,11 +1,41 @@
<script setup lang="ts">
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { useSettingsStore } from '@/stores/settings'
import NeonPanel from '@/components/NeonPanel.vue'
const router = useRouter()
const auth = useAuthStore()
const settingsStore = useSettingsStore()
onMounted(() => settingsStore.fetch())
const goalInput = ref<number>(40)
const goalError = ref<string | null>(null)
const goalSuccess = ref(false)
const goalLoading = ref(false)
// sync input after fetch
import { watch } from 'vue'
watch(() => settingsStore.settings.savings_goal_pct, (v) => { goalInput.value = v }, { immediate: true })
async function saveGoal() {
goalError.value = null
goalSuccess.value = false
if (goalInput.value < 1 || goalInput.value > 100) {
goalError.value = 'Meta deve estar entre 1% e 100%'
return
}
goalLoading.value = true
try {
await settingsStore.update({ savings_goal_pct: goalInput.value })
goalSuccess.value = true
} catch (e: any) {
goalError.value = e.message ?? 'Erro ao salvar'
} finally {
goalLoading.value = false
}
}
const currentPassword = ref('')
const newPassword = ref('')
@@ -57,6 +87,31 @@ async function logout() {
<button class="fc-btn fc-btn--danger fc-settings-logout" @click="logout">SAIR</button>
</NeonPanel>
<NeonPanel title="META DE POUPANÇA">
<form class="fc-settings-goal" @submit.prevent="saveGoal">
<div class="fc-settings-goal__row">
<label class="fc-label fc-pixel" style="font-size:9px">META MENSAL (%)</label>
<input
type="number"
v-model.number="goalInput"
min="1"
max="100"
step="1"
class="fc-input fc-settings-goal__input"
:disabled="goalLoading"
/>
<button type="submit" class="fc-btn fc-btn--primary" :disabled="goalLoading">
{{ goalLoading ? '...' : 'SALVAR' }}
</button>
</div>
<p class="fc-settings-goal__hint fc-mono">
Conquistas e quests usam este valor como meta de poupança mensal.
</p>
<p v-if="goalError" class="fc-settings-goal__msg fc-settings-goal__msg--err fc-mono">{{ goalError }}</p>
<p v-if="goalSuccess" class="fc-settings-goal__msg fc-settings-goal__msg--ok fc-mono">Meta atualizada!</p>
</form>
</NeonPanel>
<NeonPanel title="TROCAR SENHA">
<form class="fc-settings-pw" @submit.prevent="changePassword">
<input
@@ -134,4 +189,12 @@ async function logout() {
}
.fc-settings-pw__msg--err { color: var(--fc-red); }
.fc-settings-pw__msg--ok { color: var(--fc-green); }
.fc-settings-goal { display: flex; flex-direction: column; gap: var(--fc-space-2); }
.fc-settings-goal__row { display: flex; align-items: center; gap: var(--fc-space-3); }
.fc-settings-goal__input { width: 80px; }
.fc-settings-goal__hint { font-size: 10px; color: var(--fc-text-dim); margin: 0; }
.fc-settings-goal__msg { font-size: 11px; margin: 0; }
.fc-settings-goal__msg--err { color: var(--fc-red); }
.fc-settings-goal__msg--ok { color: var(--fc-green); }
</style>