Skip to content

Commit e57ec00

Browse files
authored
fix: enhance activation code modal visibility logic (#1733)
Updated the visibility logic in the activation code modal store to include a check for the presence of an activation code. The modal will now be shown if it is not explicitly hidden, the installation is fresh, there is no callback data, and an activation code is present. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Activation modal visibility refined: it now appears only when an activation code is available, it’s a fresh install, the modal isn’t hidden, and there’s no callback data. Prevents unnecessary prompts. * **Tests** * Expanded coverage to include activation code presence/absence and combined scenarios with fresh install and hidden states, ensuring accurate visibility logic. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 84f4a72 commit e57ec00

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

web/__test__/store/activationCodeModal.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('ActivationCodeModal Store', () => {
2525
let store: ReturnType<typeof useActivationCodeModalStore>;
2626
let mockIsHidden: ReturnType<typeof ref>;
2727
let mockIsFreshInstall: ReturnType<typeof ref>;
28+
let mockActivationCode: ReturnType<typeof ref>;
2829
let mockCallbackData: ReturnType<typeof ref>;
2930

3031
beforeEach(() => {
@@ -38,11 +39,13 @@ describe('ActivationCodeModal Store', () => {
3839

3940
mockIsHidden = ref(null);
4041
mockIsFreshInstall = ref(false);
42+
mockActivationCode = ref(null);
4143
mockCallbackData = ref(null);
4244

4345
vi.mocked(useSessionStorage).mockReturnValue(mockIsHidden);
4446
vi.mocked(useActivationCodeDataStore).mockReturnValue({
4547
isFreshInstall: mockIsFreshInstall,
48+
activationCode: mockActivationCode,
4649
} as unknown as ReturnType<typeof useActivationCodeDataStore>);
4750
vi.mocked(useCallbackActionsStore).mockReturnValue({
4851
callbackData: mockCallbackData,
@@ -56,6 +59,7 @@ describe('ActivationCodeModal Store', () => {
5659
vi.resetAllMocks();
5760
mockIsHidden.value = null;
5861
mockIsFreshInstall.value = false;
62+
mockActivationCode.value = null;
5963
mockCallbackData.value = null;
6064
});
6165

@@ -86,6 +90,7 @@ describe('ActivationCodeModal Store', () => {
8690
it('should be visible when fresh install and not explicitly hidden', () => {
8791
mockIsHidden.value = null;
8892
mockIsFreshInstall.value = true;
93+
mockActivationCode.value = { code: '12345' };
8994
mockCallbackData.value = null;
9095

9196
expect(store.isVisible).toBe(true);
@@ -104,9 +109,18 @@ describe('ActivationCodeModal Store', () => {
104109
expect(store.isVisible).toBe(false);
105110
});
106111

112+
it('should not be visible when activation code is missing', () => {
113+
mockIsHidden.value = null;
114+
mockIsFreshInstall.value = true;
115+
mockActivationCode.value = null;
116+
117+
expect(store.isVisible).toBe(false);
118+
});
119+
107120
it('should not be visible when callback data exists', () => {
108121
mockIsHidden.value = null;
109122
mockIsFreshInstall.value = true;
123+
mockActivationCode.value = { code: '12345' };
110124
mockCallbackData.value = { someData: 'test' };
111125

112126
expect(store.isVisible).toBe(false);

web/src/components/Activation/store/activationCodeModal.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useCallbackActionsStore } from '~/store/callbackActions';
1010
export const useActivationCodeModalStore = defineStore('activationCodeModal', () => {
1111
const isHidden = useSessionStorage<boolean | null>(ACTIVATION_CODE_MODAL_HIDDEN_STORAGE_KEY, null);
1212

13-
const { isFreshInstall } = storeToRefs(useActivationCodeDataStore());
13+
const { isFreshInstall, activationCode } = storeToRefs(useActivationCodeDataStore());
1414
const { callbackData } = storeToRefs(useCallbackActionsStore());
1515

1616
const setIsHidden = (value: boolean | null) => {
@@ -30,8 +30,13 @@ export const useActivationCodeModalStore = defineStore('activationCodeModal', ()
3030
if (isHidden.value === false) {
3131
return true;
3232
}
33-
// Default visibility logic (show if not explicitly hidden AND fresh install AND no callback data)
34-
return isHidden.value === null && isFreshInstall.value && !callbackData.value;
33+
// Default visibility logic (show if not explicitly hidden AND fresh install AND no callback data AND activation code is present)
34+
return (
35+
isHidden.value === null &&
36+
isFreshInstall.value &&
37+
!callbackData.value &&
38+
Boolean(activationCode.value?.code)
39+
);
3540
});
3641

3742
/**

0 commit comments

Comments
 (0)