Open-source personal finance manager. Self-hosted, privacy-first.
fix(goals): allow reactivating completed/archived goals and confirm deletion (#418)
Tássio Noronhaf1ed021a69f6
diff --git a/backend/tests/test_goals_api.py b/backend/tests/test_goals_api.pyindex 5e830027..9f97f1f7 100644--- a/backend/tests/test_goals_api.py+++ b/backend/tests/test_goals_api.py@@ -230,6 +230,73 @@ async def test_update_goal_status(client: AsyncClient, auth_headers: dict, test_assert response.json()["status"] == "archived"[email protected]("from_status", ["completed", "archived"])+async def test_reactivate_goal(+ client: AsyncClient, auth_headers: dict, test_user: User, from_status: str+):+ """A completed or archived goal can be sent back to active."""+ resp = await client.post(+ "/api/goals",+ json={"name": "Revivable Goal", "target_amount": "1000.00", "tracking_type": "manual"},+ headers=auth_headers,+ )+ goal_id = resp.json()["id"]++ response = await client.patch(+ f"/api/goals/{goal_id}",+ json={"status": from_status},+ headers=auth_headers,+ )+ assert response.status_code == 200+ assert response.json()["status"] == from_status++ response = await client.patch(+ f"/api/goals/{goal_id}",+ json={"status": "active"},+ headers=auth_headers,+ )+ assert response.status_code == 200+ assert response.json()["status"] == "active"+++async def test_reactivate_goal_preserves_account_tracking(+ client: AsyncClient, auth_headers: dict, test_user: User, test_account: Account+):+ """Archiving and reactivating must not drop the goal's tracking link."""+ resp = await client.post(+ "/api/goals",+ json={+ "name": "Tracked Goal",+ "target_amount": "5000.00",+ "currency": "BRL",+ "tracking_type": "account",+ "account_id": str(test_account.id),+ },+ headers=auth_headers,+ )+ goal_id = resp.json()["id"]++ await client.patch(+ f"/api/goals/{goal_id}",+ json={"status": "archived"},+ headers=auth_headers,+ )+ response = await client.patch(+ f"/api/goals/{goal_id}",+ json={"status": "active"},+ headers=auth_headers,+ )++ assert response.status_code == 200+ data = response.json()+ assert data["status"] == "active"+ assert data["tracking_type"] == "account"+ assert data["account_id"] == str(test_account.id)+ assert float(data["current_amount"]) == 1500.00++@pytest.mark.asyncioasync def test_update_goal_tracking_type(client: AsyncClient, auth_headers: dict, test_user: User):resp = await client.post(diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.jsonindex 6350ef3d..363221e1 100644--- a/frontend/src/locales/de.json+++ b/frontend/src/locales/de.json@@ -717,6 +717,9 @@"resume": "Fortsetzen","complete": "Als abgeschlossen markieren","archive": "Archivieren",+ "reactivate": "Reaktivieren",+ "confirmDeleteTitle": "Ziel löschen?",+ "confirmDeleteDesc": "\"{{name}}\" wird endgültig gelöscht. Diese Aktion kann nicht rückgängig gemacht werden.","viewAll": "Alle Ziele anzeigen","dashboardTitle": "Fortschritt der Ziele","noTargetDate": "Keine Frist",diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.jsonindex 2c113e45..e0c9b901 100644--- a/frontend/src/locales/en.json+++ b/frontend/src/locales/en.json@@ -717,6 +717,9 @@"resume": "Resume","complete": "Mark Complete","archive": "Archive",+ "reactivate": "Reactivate",+ "confirmDeleteTitle": "Delete goal?",+ "confirmDeleteDesc": "\"{{name}}\" will be permanently deleted. This action is irreversible.","viewAll": "View all goals","dashboardTitle": "Goals Progress","noTargetDate": "No deadline",diff --git a/frontend/src/locales/es.json b/frontend/src/locales/es.jsonindex cd9491ff..e29adea3 100644--- a/frontend/src/locales/es.json+++ b/frontend/src/locales/es.json@@ -717,6 +717,9 @@"resume": "Reanudar","complete": "Marcar como completado","archive": "Archivar",+ "reactivate": "Reactivar",+ "confirmDeleteTitle": "¿Eliminar objetivo?",+ "confirmDeleteDesc": "\"{{name}}\" se eliminará permanentemente. Esta acción es irreversible.","viewAll": "Ver todos los objetivos","dashboardTitle": "Progreso de objetivos","noTargetDate": "Sin fecha límite",diff --git a/frontend/src/locales/it.json b/frontend/src/locales/it.jsonindex e78b4cd2..b70a04d1 100644--- a/frontend/src/locales/it.json+++ b/frontend/src/locales/it.json@@ -717,6 +717,9 @@"resume": "Riprendi","complete": "Segna come completato","archive": "Archivia",+ "reactivate": "Riattiva",+ "confirmDeleteTitle": "Eliminare l'obiettivo?",+ "confirmDeleteDesc": "\"{{name}}\" verrà eliminato definitivamente. Questa azione è irreversibile.","viewAll": "Visualizza tutti gli obiettivi","dashboardTitle": "Progresso obiettivi","noTargetDate": "Nessuna scadenza",diff --git a/frontend/src/locales/pl.json b/frontend/src/locales/pl.jsonindex 8b32998a..ad41fae3 100644--- a/frontend/src/locales/pl.json+++ b/frontend/src/locales/pl.json@@ -759,6 +759,9 @@"resume": "Wznów","complete": "Oznacz jako ukończony","archive": "Archiwizuj",+ "reactivate": "Reaktywuj",+ "confirmDeleteTitle": "Usunąć cel?",+ "confirmDeleteDesc": "„{{name}}” zostanie trwale usunięty. Ta operacja jest nieodwracalna.","viewAll": "Zobacz wszystkie cele","dashboardTitle": "Postęp celów","noTargetDate": "Brak terminu",diff --git a/frontend/src/locales/pt-BR.json b/frontend/src/locales/pt-BR.jsonindex 7d897239..36bbe401 100644--- a/frontend/src/locales/pt-BR.json+++ b/frontend/src/locales/pt-BR.json@@ -717,6 +717,9 @@"resume": "Retomar","complete": "Marcar Concluída","archive": "Arquivar",+ "reactivate": "Reativar",+ "confirmDeleteTitle": "Excluir meta?",+ "confirmDeleteDesc": "\"{{name}}\" será excluída permanentemente. Esta ação é irreversível.","viewAll": "Ver todas as metas","dashboardTitle": "Progresso das Metas","noTargetDate": "Sem prazo",diff --git a/frontend/src/locales/ru.json b/frontend/src/locales/ru.jsonindex f196ac58..534017a6 100644--- a/frontend/src/locales/ru.json+++ b/frontend/src/locales/ru.json@@ -717,6 +717,9 @@"resume": "Возобновить","complete": "Отметить выполненной","archive": "Архивировать",+ "reactivate": "Активировать",+ "confirmDeleteTitle": "Удалить цель?",+ "confirmDeleteDesc": "«{{name}}» будет удалена безвозвратно. Это действие необратимо.","viewAll": "Посмотреть все цели","dashboardTitle": "Прогресс целей","noTargetDate": "Без срока",diff --git a/frontend/src/locales/uk.json b/frontend/src/locales/uk.jsonindex efb7b0ce..26d86a5f 100644--- a/frontend/src/locales/uk.json+++ b/frontend/src/locales/uk.json@@ -717,6 +717,9 @@"resume": "Відновити","complete": "Позначити виконаною","archive": "Архівувати",+ "reactivate": "Активувати",+ "confirmDeleteTitle": "Видалити ціль?",+ "confirmDeleteDesc": "«{{name}}» буде видалено назавжди. Ця дія незворотна.","viewAll": "Переглянути всі цілі","dashboardTitle": "Прогрес цілей","noTargetDate": "Без терміну",diff --git a/frontend/src/pages/goals.tsx b/frontend/src/pages/goals.tsxindex 7d08f2b4..44649acd 100644--- a/frontend/src/pages/goals.tsx+++ b/frontend/src/pages/goals.tsx@@ -23,7 +23,7 @@ import {} from '@/components/ui/popover'import type { Account, Asset, AssetGroup, Goal } from '@/types'import {- Pencil, Trash2, Plus, Pause, Play, CheckCircle2, Archive, Target,+ Pencil, Trash2, Plus, Pause, Play, CheckCircle2, Archive, ArchiveRestore, Target,ChevronDown,} from 'lucide-react'import { ICON_MAP } from '@/lib/category-icons'@@ -149,6 +149,7 @@ export default function GoalsPage() {const [editing, setEditing] = useState<Goal | null>(null)const [trackingType, setTrackingType] = useState('manual')const [statusFilter, setStatusFilter] = useState<string>('active')+ const [deletingGoal, setDeletingGoal] = useState<Goal | null>(null)const [selectedIcon, setSelectedIcon] = useState('target')const [selectedColor, setSelectedColor] = useState('#3B82F6')const [targetDate, setTargetDate] = useState('')@@ -204,8 +205,10 @@ export default function GoalsPage() {mutationFn: (id: string) => goalsApi.delete(id),onSuccess: () => {queryClient.invalidateQueries({ queryKey: ['goals'] })+ setDeletingGoal(null)toast.success(t('goals.deleted'))},+ onError: () => toast.error(t('common.error')),})const statusMutation = useMutation({@@ -387,6 +390,15 @@ export default function GoalsPage() {<Archive size={13} /></button>)}+ {(goal.status === 'completed' || goal.status === 'archived') && (+ <button+ className="p-1.5 rounded-md text-muted-foreground hover:text-emerald-500 hover:bg-emerald-50 dark:hover:bg-emerald-500/10 transition-colors"+ onClick={() => statusMutation.mutate({ id: goal.id, status: 'active' })}+ title={t('goals.reactivate')}+ >+ <ArchiveRestore size={13} />+ </button>+ )}<buttonclassName="p-1.5 rounded-md text-muted-foreground hover:text-primary hover:bg-primary/5 transition-colors"onClick={() => openEditDialog(goal)}@@ -396,8 +408,7 @@ export default function GoalsPage() {</button><buttonclassName="p-1.5 rounded-md text-muted-foreground hover:text-rose-500 hover:bg-rose-50 dark:hover:bg-rose-500/10 transition-colors"- onClick={() => deleteMutation.mutate(goal.id)}- disabled={deleteMutation.isPending}+ onClick={() => setDeletingGoal(goal)}title={t('common.delete')}><Trash2 size={13} />@@ -617,6 +628,30 @@ export default function GoalsPage() {</form></DialogContent></Dialog>++ {/* Confirm delete dialog */}+ <Dialog open={!!deletingGoal} onOpenChange={() => setDeletingGoal(null)}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>{t('goals.confirmDeleteTitle')}</DialogTitle>+ </DialogHeader>+ <p className="text-sm text-muted-foreground">+ {t('goals.confirmDeleteDesc', { name: deletingGoal?.name })}+ </p>+ <DialogFooter>+ <Button variant="outline" onClick={() => setDeletingGoal(null)}>+ {t('common.cancel')}+ </Button>+ <Button+ variant="destructive"+ onClick={() => deletingGoal && deleteMutation.mutate(deletingGoal.id)}+ disabled={deleteMutation.isPending}+ >+ {deleteMutation.isPending ? t('common.loading') : t('common.delete')}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog></div>)}