Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor useBackupReminder hook #528

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

danditomaso
Copy link
Collaborator

@danditomaso danditomaso commented Mar 20, 2025

Description

This PR refactors the useBackupReminder hook to use localStorage for persistence instead of relying on cookies (js-cookie). This change improves the reliability of storing reminder state, and will allow a single dismiss action to be read across domains (local dev vs live)

Using cookies limited persistence to the specific domain and environment where the reminder was dismissed. By moving to localStorage, the dismissed state can now persist across local development and live environments (when the same storage is accessible), improving the developer experience and preventing repeated backup reminders between local development and live.

Changes Made

  • Replaced the useCookie hook with a custom useLocalStorage hook.
  • Persisted the reminder state (suppressed and lastShown values) in localStorage under the key key_backup_reminder.
  • Added option to dismiss the reminder forever (10 years).
  • Preserved existing functionality:
    Displays the backup reminder toast based on the last shown date and suppression state.
    Allows users to dismiss the reminder forever (10 years), take action, dismiss for one week.

Testing Done

Tests have been added for useToast and useLocalStorage hooks, including the Toast component

Screenshots (if applicable)

(the size of the dialog has remained the same fyi)
before:
Screenshot 2025-03-21 at 10 56 14 am

after:
Screenshot 2025-03-20 at 2 39 29 pm

Checklist

  • Code follows project style guidelines
  • Tests have been added or updated
  • All CI checks pass

Additional Notes

@danditomaso danditomaso requested review from Hunter275 and KomelT March 20, 2025 15:50
Copy link

vercel bot commented Mar 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
web-test ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 22, 2025 3:34am

@danditomaso danditomaso force-pushed the add-dismiss-to-key-reminder branch from fb67e90 to 22dbfbc Compare March 20, 2025 18:40
@danditomaso danditomaso changed the title Refactor Backup Reminder Hook to Use LocalStorage Instead of Cookies Refactor useBackupReminder hook Mar 20, 2025
@dzienisz
Copy link
Contributor

and will allow a single dismiss action to be read across domains (local dev vs live) - is this a good change?

@danditomaso
Copy link
Collaborator Author

and will allow a single dismiss action to be read across domains (local dev vs live) - is this a good change?

I believe it is, the only people who access both local dev and live are developers. This is really a DX improvement without any downside for users.

>
Remind me in {reminderInDays} days
</Button>
<div className="flex flex-col gap-2">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ This could/should be a form for better semantics/accessibility

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be an interesting "future" thing to see if this could be converted to the new(ish) popover stuff

suppressReminder(reminderInDays);
}}
>
Remind me in {reminderInDays} days
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe

Suggested change
Remind me in {reminderInDays} days
Remind me in {reminderInDays} day{reminderInDays > 1 ? 's' : ''}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, I added this into the refactor I did based on this feedback. Thanks

);
setReminderState({
suppressed: true,
lastShown: new Date().toISOString(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean to do this?

Suggested change
lastShown: new Date().toISOString(),
lastShown: new Date().toISOString(),
expires: expiryDate.toISOString()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this, I'm not sure why I thought I needed this extra logic, I did a small refactor using expires instead of supressed and lastShown props.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants