Skip to content

Commit

Permalink
fix: newsletter check [WPB-11942] (#18582)
Browse files Browse the repository at this point in the history
* fix: newsletter check

* fix(PropertiesRepository): update marketing consent loading logic
  • Loading branch information
olafsulich authored Jan 14, 2025
1 parent de37c66 commit 54c1432
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/script/auth/page/SetHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ import {
Text,
} from '@wireapp/react-ui-kit';

import {StorageKey} from 'src/script/storage';
import {t} from 'Util/LocalizerUtil';
import {storeValue} from 'Util/StorageUtil';
import {isBackendError} from 'Util/TypePredicateUtil';

import {Page} from './Page';
Expand Down Expand Up @@ -105,6 +107,16 @@ const SetHandleComponent = ({
setHandle(event.target.value);
};

const handleAcceptNewletterConsent = () => {
void updateConsent(ConsentType.MARKETING, 1);
storeValue(StorageKey.INITIAL_MAKRETING_CONSENT_ACCEPTED, true);
};

const handleDeclineNewletterConsent = () => {
void updateConsent(ConsentType.MARKETING, 0);
storeValue(StorageKey.INITIAL_MAKRETING_CONSENT_ACCEPTED, false);
};

if (hasSelfHandle) {
return null;
}
Expand Down Expand Up @@ -143,10 +155,7 @@ const SetHandleComponent = ({
{error && parseError(error)}
</ContainerXS>
{!isFetching && hasUnsetMarketingConsent && (
<AcceptNewsModal
onConfirm={() => updateConsent(ConsentType.MARKETING, 1)}
onDecline={() => updateConsent(ConsentType.MARKETING, 0)}
/>
<AcceptNewsModal onConfirm={handleAcceptNewletterConsent} onDecline={handleDeclineNewletterConsent} />
)}
</Page>
);
Expand Down
6 changes: 5 additions & 1 deletion src/script/properties/PropertiesRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ import {deepMerge} from 'Util/deepMerge';
import {Environment} from 'Util/Environment';
import {replaceLink, t} from 'Util/LocalizerUtil';
import {getLogger, Logger} from 'Util/Logger';
import {loadValue} from 'Util/StorageUtil';

import type {PropertiesService} from './PropertiesService';
import {PROPERTIES_TYPE, UserConsentStatus} from './PropertiesType';

import type {User} from '../entity/User';
import type {SelfService} from '../self/SelfService';
import {StorageKey} from '../storage';
import {isTelemetryEnabledAtCurrentEnvironment} from '../tracking/Telemetry.helpers';
import {ConsentValue} from '../user/ConsentValue';
import {CONVERSATION_TYPING_INDICATOR_MODE} from '../user/TypingIndicatorMode';
Expand Down Expand Up @@ -98,7 +100,9 @@ export class PropertiesRepository {
},
privacy: {
telemetry_data_sharing: undefined,
marketing_consent: PropertiesRepository.CONFIG.WIRE_MARKETING_CONSENT.defaultValue,
marketing_consent:
loadValue(StorageKey.INITIAL_MAKRETING_CONSENT_ACCEPTED) ??
PropertiesRepository.CONFIG.WIRE_MARKETING_CONSENT.defaultValue,
},
sound: {
alerts: AudioPreference.ALL,
Expand Down
1 change: 1 addition & 0 deletions src/script/storage/StorageKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const StorageKey = {
INPUT: {
SHOW_FORMATTING: 'z.storage.StorageKey.INPUT.SHOW_FORMATTING',
},
INITIAL_MAKRETING_CONSENT_ACCEPTED: 'z.storage.StorageKey.INITIAL_MAKRETING_CONSENT_ACCEPTED',
};

export const ROOT_FONT_SIZE_KEY = 'root-font-size';

0 comments on commit 54c1432

Please sign in to comment.