diff --git a/app/assets/javascripts/components/AccountMenu/Protections.tsx b/app/assets/javascripts/components/AccountMenu/Protections.tsx index 2b4049974..fbc180566 100644 --- a/app/assets/javascripts/components/AccountMenu/Protections.tsx +++ b/app/assets/javascripts/components/AccountMenu/Protections.tsx @@ -14,7 +14,7 @@ const Protections: FunctionalComponent = ({ application }) => { application.clearProtectionSession(); }; - const hasProtections = application.hasProtectionSources(); + const [hasProtections, setHasProtections] = useState(() => application.hasProtectionSources()); const getProtectionsDisabledUntil = useCallback((): string | null => { const protectionExpiry = application.getProtectionSessionExpiryDate(); @@ -51,8 +51,16 @@ const Protections: FunctionalComponent = ({ application }) => { ApplicationEvent.ProtectionSessionExpiryDateChanged ); + const removeKeyStatusChangedObserver = application.addEventObserver( + async () => { + setHasProtections(application.hasProtectionSources()); + }, + ApplicationEvent.KeyStatusChanged + ); + return () => { removeProtectionSessionExpiryDateChangedObserver(); + removeKeyStatusChangedObserver(); }; }, [application, getProtectionsDisabledUntil]);