Skip to content

Comments

Feat prevent renaming habits with existing logs clone instead#84

Merged
BrayanMQ merged 10 commits intomainfrom
feat-prevent-renaming-habits-with-existing-logs-clone-instead
Jan 14, 2026
Merged

Feat prevent renaming habits with existing logs clone instead#84
BrayanMQ merged 10 commits intomainfrom
feat-prevent-renaming-habits-with-existing-logs-clone-instead

Conversation

@BrayanMQ
Copy link
Owner

📝 Description

Implement soft versioning for habits to prevent data integrity issues when renaming habits with existing logs. When a user attempts to rename a habit that has recorded history, instead of modifying the original habit, the system creates a new habit with the new name and archives the original one, preserving all historical data.

🔗 Related Issue

Closes #83

🏷️ Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Dependency update

🔄 Changes Made

  • Added archived_at column to habits table via SQL migration
  • Modified useHabits hook to filter out archived habits from the main list
  • Added new hooks: useArchivedHabits and useArchiveHabit for managing archived habits
  • Added useHabitHasLogs hook to check if a habit has existing logs before allowing rename
  • Updated EditHabitModal to show confirmation dialog when renaming habits with logs
  • Created ArchivedHabitsSection component with collapsible UI to display archived habits
  • Added archived habits section to the habits management page
  • Added EN/ES translations for all new UI elements

🧪 Testing

  • Manual testing completed
  • Unit tests added/updated
  • Integration tests added/updated

Test steps:

  1. Create a new habit without logs → Edit name → Should update normally
  2. Create a habit and mark it as completed (creates a log) → Edit name → Should show confirmation modal
  3. Confirm the action → Should create new habit and archive the original
  4. Navigate to habits page → Archived section should appear at the bottom with the archived habit

✅ Checklist

  • My code follows the project's code style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (if applicable)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

📸 Screenshots (if applicable)

N/A - UI changes are minimal (collapsible archived section and confirmation modal)

📌 Additional Notes

Database Migration Required:

ALTER TABLE public.habits ADD COLUMN archived_at TIMESTAMPTZ;
CREATE INDEX IF NOT EXISTS idx_habits_archived_at ON public.habits(archived_at);

Run npx supabase db push to apply the migration before testing.

Files Changed:

  • supabase/migrations/20260113100000_add_habits_archived_at.sql (new)
  • types/database.ts
  • hooks/useHabits.ts
  • hooks/useHabitLogs.ts
  • components/habits/EditHabitModal.tsx
  • components/habits/ArchivedHabitsSection.tsx (new)
  • app/dashboard/habits/page.tsx
  • i18n/locales/en.json
  • i18n/locales/es.json
  • Test files updated with archived_at property

- Refactored date validation logic in useHabitLogs to improve error handling for invalid dates.
- Added a new custom hook, useHabitHasLogs, to check if a habit has any logs, facilitating better management of habit-related operations.
…tates

- Added cloning confirmation dialog to handle cases where a habit's title changes and it has associated logs.
- Integrated useCreateHabit hook to facilitate habit creation during cloning.
- Improved loading state management by introducing isProcessing to track ongoing updates and creations.
- Updated UI to reflect new states and ensure a smooth user experience during habit editing and cloning.
- Introduced cloning confirmation dialog in English and Spanish to inform users about the implications of changing a habit's name.
- Added success toast messages for the creation of new habits, ensuring users are notified when their actions are successful.
- Enhanced localization files to support new messages related to habit cloning functionality.
- Introduced an archived_at column to the habits table to support soft versioning, allowing for the archiving of habits when renamed.
- Added an index on the archived_at column for efficient filtering between active and archived habits.
- Included a comment on the archived_at column to clarify its purpose and usage.
- Added an optional archived_at field to the habits table for soft deletion functionality, allowing habits to be archived without permanent removal.
- Updated type definitions to accommodate the new field in Insert and Update operations.
- Added support for managing archived habits through new custom hooks: useArchivedHabits and useArchiveHabit.
- Updated useHabits to filter out archived habits by checking the archived_at field.
- Enhanced data fetching for both active and archived habits, improving user experience in habit management.
- Added useArchiveHabit hook to manage archiving of habits within the EditHabitModal.
- Updated the cloning confirmation logic to archive the original habit after creating a new one, enhancing habit management functionality.
- Improved loading state handling to include archiving processes, ensuring a smoother user experience.
- Introduced ArchivedHabitsSection component to show a collapsible section for archived habits at the bottom of the habits page.
- Integrated useArchivedHabits hook to fetch and manage archived habits, enhancing user experience.
- Added loading and empty states for better feedback when viewing archived habits.
… section

- Modified English and Spanish localization files to reflect changes in habit archiving terminology, clarifying that original habits will be archived rather than unchanged.
- Added new entries for managing archived habits, including titles and messages for empty states, enhancing user experience when viewing archived habits.
- Updated test data in CalendarPage, StatsPage, and HabitCard tests to include the archived_at field, ensuring alignment with recent changes in habit management functionality.
@BrayanMQ BrayanMQ linked an issue Jan 14, 2026 that may be closed by this pull request
5 tasks
@BrayanMQ BrayanMQ merged commit 84073f1 into main Jan 14, 2026
1 check passed
@BrayanMQ BrayanMQ deleted the feat-prevent-renaming-habits-with-existing-logs-clone-instead branch January 14, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent Renaming Habits With Existing Logs (Clone Instead)

1 participant