Skip to content

Commit

Permalink
[Issue-1799] Add condition OS version, App version for MKT campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
dominhquang committed Sep 23, 2024
1 parent 0a9a3dc commit febdd65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
14 changes: 6 additions & 8 deletions src/hooks/static-content/useHandleAppBannerMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,27 @@ export const useHandleAppBannerMap = () => {

const filteredData = useMemo(() => {
return appBannerData.filter(({ locations, comparison_operator, ios_version_range, app_version_range }) => {
let isValidLocation = true;
let isValidIosVersion = true;
let isValidAppVersion = true;
const validConditionArr = [];
if (locations && locations.length) {
const countryId = getCountry();
const locationIds = locations.map(item => item.split('_')[1]);
isValidLocation = locationIds.includes(countryId);
validConditionArr.push(locationIds.includes(countryId));
}

if (ios_version_range && Platform.OS === 'ios') {
const iosVersion = getIosVersion();
isValidIosVersion = satisfies(iosVersion, ios_version_range);
validConditionArr.push(satisfies(iosVersion, ios_version_range));
}

if (app_version_range) {
const appVersion = getVersion();
isValidAppVersion = satisfies(appVersion, app_version_range);
validConditionArr.push(satisfies(appVersion, app_version_range));
}

if (comparison_operator === 'AND') {
return isValidLocation && isValidIosVersion && isValidAppVersion;
return validConditionArr.every(c => c);
} else {
return isValidLocation || isValidIosVersion || isValidAppVersion;
return validConditionArr.some(c => c);
}
});
}, [appBannerData]);
Expand Down
14 changes: 6 additions & 8 deletions src/hooks/static-content/useHandleAppPopupMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,27 @@ export const useHandleAppPopupMap = () => {

const filteredData = useMemo(() => {
return appPopupData.filter(({ locations, comparison_operator, ios_version_range, app_version_range }) => {
let isValidLocation = true;
let isValidIosVersion = true;
let isValidAppVersion = true;
const validConditionArr = [];
if (locations && locations.length) {
const countryId = getCountry();
const locationIds = locations.map(item => item.split('_')[1]);
isValidLocation = locationIds.includes(countryId);
validConditionArr.push(locationIds.includes(countryId));
}

if (ios_version_range && Platform.OS === 'ios') {
const iosVersion = getIosVersion();
isValidIosVersion = satisfies(iosVersion, ios_version_range);
validConditionArr.push(satisfies(iosVersion, ios_version_range));
}

if (app_version_range) {
const appVersion = getVersion();
isValidAppVersion = satisfies(appVersion, app_version_range);
validConditionArr.push(satisfies(appVersion, app_version_range));
}

if (comparison_operator === 'AND') {
return isValidLocation && isValidIosVersion && isValidAppVersion;
return validConditionArr.every(c => c);
} else {
return isValidLocation || isValidIosVersion || isValidAppVersion;
return validConditionArr.some(c => c);
}
});
}, [appPopupData]);
Expand Down

0 comments on commit febdd65

Please sign in to comment.