Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/components/Contentful/JourneyCardCarousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ const props = defineProps({
type: Object,
default: null
},
showPostLendingNextStepsCards: {
type: Boolean,
default: false
},
});

const { isMobile, isMedium, isLarge } = useBreakpoints();
Expand All @@ -285,14 +289,15 @@ const shouldShowEmailMarketingCard = computed(
);
const isEmailUpdatesSlide = slide => slide?.isEmailUpdates === true;

const showLatestLoan = computed(() => props.postLendingNextStepsEnable && props.latestLoan);
const showLatestLoan = computed(() => props.showPostLendingNextStepsCards
&& props.postLendingNextStepsEnable && props.latestLoan);

const showSurveyCard = computed(() => {
const userPreferences = props.userInfo?.userPreferences || {};
const parsedPrefs = JSON.parse(userPreferences.preferences || '{}');
const isFormSubmitted = (parsedPrefs.savedForms || []).some(form => form.formName === MYKIVA_INPUT_FORM_KEY);

return !isFormSubmitted && props.postLendingNextStepsEnable;
return props.showPostLendingNextStepsCards && !isFormSubmitted && props.postLendingNextStepsEnable;
});

const badgesData = computed(() => {
Expand Down
10 changes: 10 additions & 0 deletions src/components/MyKiva/LendingStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
:hide-goal-card="hideCompletedGoalCard"
:post-lending-next-steps-enable="postLendingNextStepsEnable"
:user-info="userInfo"
:show-post-lending-next-steps-cards="showPostLendingNextStepsCards"
@open-goal-modal="showGoalModal = true"
/>
</div>
Expand Down Expand Up @@ -161,6 +162,7 @@
:post-lending-next-steps-enable="postLendingNextStepsEnable"
:latest-loan="latestLoan"
:user-info="userInfo"
:show-post-lending-next-steps-cards="showPostLendingNextStepsCards"
@open-goal-modal="showGoalModal = true"
/>
<GoalSettingModal
Expand Down Expand Up @@ -199,6 +201,7 @@ import SouthAmerica from '#src/assets/images/my-kiva/South America.png';
import useDelayUntilVisible from '#src/composables/useDelayUntilVisible';
import JourneyCardCarousel from '#src/components/Contentful/JourneyCardCarousel';

import { checkPostLendingCardCookie, removePostLendingCardCookie } from '#src/util/myKivaUtils';
import GoalSettingModal from './GoalSettingModal';

export default {
Expand Down Expand Up @@ -281,6 +284,7 @@ export default {
isGoalSet: false,
recordedGoalSet: false,
newGoalPrefs: null,
showPostLendingNextStepsCards: false,
};
},
computed: {
Expand Down Expand Up @@ -359,6 +363,12 @@ export default {
}, [this.$refs.loanRegionsElement]);
this.disconnectRegionWatcher = disconnect;
}

// Show post-lending next steps cards in My Kiva
if (checkPostLendingCardCookie(this.cookieStore)) {
this.showPostLendingNextStepsCards = true;
removePostLendingCardCookie(this.cookieStore);
}
},
beforeUnmount() {
if (this.interval) clearInterval(this.interval);
Expand Down
8 changes: 7 additions & 1 deletion src/components/Thanks/ThanksPageSingleVersion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ import GoalSettingModal from '#src/components/MyKiva/GoalSettingModal';
import GoalInProgress from '#src/components/Thanks/SingleVersion/GoalInProgress';
import useGoalData, { GOAL_STATUS } from '#src/composables/useGoalData';
import useBadgeData from '#src/composables/useBadgeData';
import { setGuestAssignmentCookie } from '#src/util/myKivaUtils';
import { setGuestAssignmentCookie, setPostLendingCardCookie } from '#src/util/myKivaUtils';

const EVENT_CATEGORY = 'post-checkout';

Expand Down Expand Up @@ -198,6 +198,10 @@ const props = defineProps({
type: Array,
default: () => ([]),
},
postLendingNextStepsEnable: {
type: Boolean,
default: false,
}
});

const badgeAchievedIds = ref(props.badgesAchieved.map(b => b.achievementId));
Expand Down Expand Up @@ -416,6 +420,8 @@ onMounted(async () => {
'all-achievements-earned',
);
}

setPostLendingCardCookie(cookieStore, props.postLendingNextStepsEnable);
});
</script>

Expand Down
4 changes: 4 additions & 0 deletions src/graphql/query/thanksPage.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ query thanksPage {
key
value
}
post_lending_next_steps_enable: uiConfigSetting(key: "mykiva_post_lending_next_steps_enable") {
key
value
}
}
}
4 changes: 4 additions & 0 deletions src/pages/Thanks/ThanksPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:goals-v2-enabled="goalsV2Enabled"
:total-loans="totalLoanCount"
:tiered-achievements="achievements"
:post-lending-next-steps-enable="postLendingNextStepsEnable"
/>
</template>
<template v-if="activeView === DONATION_ONLY_VIEW">
Expand Down Expand Up @@ -111,6 +112,7 @@ const hasDepositBeforeCookie = 'kvu_db';
const CHALLENGE_HEADER_EXP = 'filters_challenge_header';
const NEXT_STEPS_EXP_KEY = 'mykiva_next_steps';
const THANK_YOU_PAGE_GOALS_ENABLE_KEY = 'thankyou_page_goals_enable';
const POST_LENDING_NEXT_STEPS_KEY = 'post_lending_next_steps_enable';

// Thanks views
const DONATION_ONLY_VIEW = 'donation_only';
Expand Down Expand Up @@ -176,6 +178,7 @@ export default {
thanksPageGoalsEntrypointEnable: false,
totalLoanCount: 0,
achievements: [],
postLendingNextStepsEnable: false,
};
},
apollo: {
Expand Down Expand Up @@ -322,6 +325,7 @@ export default {
this.achievements = userAchievements?.userAchievementProgress?.tieredLendingAchievements ?? [];
this.achievementsCompleted = this.allAchievementsCompleted(this.achievements);
this.thanksPageGoalsEntrypointEnable = readBoolSetting(data, `general.${THANK_YOU_PAGE_GOALS_ENABLE_KEY}.value`) ?? false; // eslint-disable-line max-len
this.postLendingNextStepsEnable = readBoolSetting(data, `general.${POST_LENDING_NEXT_STEPS_KEY}.value`) ?? false; // eslint-disable-line max-len
} catch (e) {
logReadQueryError(e, 'Thanks page readQuery failed');
}
Expand Down
33 changes: 33 additions & 0 deletions src/util/myKivaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const GUEST_ASSIGNMENT_COOKIE = 'myKivaGuestAssignment';
export const CONTENTFUL_CAROUSEL_KEY = 'my-kiva-hero-carousel';
export const MY_KIVA_HERO_ENABLE_KEY = 'new_mykiva_hero_enable';
export const TRANSACTION_LOANS_KEY = 'loan_purchase';
export const POST_LENDING_NEXT_STEPS_COOKIE = 'my_kiva_post_lending_next_steps';

/**
* Determines whether the provided loan needs a footnote
Expand Down Expand Up @@ -122,3 +123,35 @@ export const getIsMyKivaEnabled = (apollo, $kvTrackEvent, myKivaFlagEnabled, coo

return false;
};

/**
* Set session cookie for post lending card cookie to show cards in MyKiva
*
* @param cookieStore The cookie store
*/
export const setPostLendingCardCookie = (cookieStore, postLendingEnabled) => {
// Only add the session cookie if the user is a guest and postLendingEnabled is enabled
if (postLendingEnabled) {
cookieStore?.set(POST_LENDING_NEXT_STEPS_COOKIE, 'true', { path: '/' });
}
};

/**
* Checks for existence of session cookie for post lending card cookie
*
* @param cookieStore The cookie store
* @returns Whether the post lending card cookie exists
*/
export const checkPostLendingCardCookie = cookieStore => {
return !!cookieStore?.get(POST_LENDING_NEXT_STEPS_COOKIE);
};

/**
* Checks for existence of session cookie for post lending card cookie
*
* @param cookieStore The cookie store
* @returns Whether the post lending card cookie exists
*/
export const removePostLendingCardCookie = cookieStore => {
return cookieStore?.remove(POST_LENDING_NEXT_STEPS_COOKIE);
};
73 changes: 73 additions & 0 deletions test/unit/specs/util/myKivaUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
checkGuestAssignmentCookie,
GUEST_ASSIGNMENT_COOKIE,
setMyKivaRedirectCookie,
setPostLendingCardCookie,
checkPostLendingCardCookie,
POST_LENDING_NEXT_STEPS_COOKIE,
removePostLendingCardCookie
} from '#src/util/myKivaUtils';
import postCheckoutAchievementsQuery from '#src/graphql/query/postCheckoutAchievements.graphql';
import logReadQueryError from '#src/util/logReadQueryError';
Expand Down Expand Up @@ -335,4 +339,73 @@ describe('myKivaUtils.js', () => {
expect(result).toBe(false);
});
});

describe('setPostLendingCardCookie', () => {
it('should set the post lending card cookie if post lending is enabled', () => {
const cookieStore = {
set: vi.fn(),
};
const postLendingEnabled = true;

setPostLendingCardCookie(cookieStore, postLendingEnabled);

expect(cookieStore.set).toHaveBeenCalledWith(POST_LENDING_NEXT_STEPS_COOKIE, 'true', { path: '/' });
});

it('should not set the post lending card cookie if post lending is not enabled', () => {
const cookieStore = {
set: vi.fn(),
};
const postLendingEnabled = false;

setPostLendingCardCookie(cookieStore, postLendingEnabled);

expect(cookieStore.set).not.toHaveBeenCalled();
});

it('should not throw an error if cookieStore is undefined', () => {
expect(() => setPostLendingCardCookie(undefined, true)).not.toThrow();
});
});

describe('checkPostLendingCardCookie', () => {
it('should return true if the guest assignment cookie exists', () => {
const cookieStore = {
get: vi.fn().mockReturnValue('true'),
};

const result = checkPostLendingCardCookie(cookieStore);

expect(result).toBe(true);
expect(cookieStore.get).toHaveBeenCalledWith(POST_LENDING_NEXT_STEPS_COOKIE);
});

it('should return false if the guest assignment cookie does not exist', () => {
const cookieStore = {
get: vi.fn().mockReturnValue(undefined),
};

const result = checkPostLendingCardCookie(cookieStore);

expect(result).toBe(false);
expect(cookieStore.get).toHaveBeenCalledWith(POST_LENDING_NEXT_STEPS_COOKIE);
});

it('should return false if cookieStore is undefined', () => {
const result = checkPostLendingCardCookie(undefined);

expect(result).toBe(false);
});
});

describe('removePostLendingCardCookie', () => {
it('should remove post lending cookie', () => {
const cookieStore = {
remove: vi.fn(),
};

removePostLendingCardCookie(cookieStore);
expect(cookieStore.remove).toHaveBeenCalledWith(POST_LENDING_NEXT_STEPS_COOKIE);
});
});
});
Loading