Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to attribute a loan to a team from cookie value #5101

Merged
merged 2 commits into from
Dec 18, 2023
Merged
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
47 changes: 44 additions & 3 deletions src/components/Checkout/BasketItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
/>
<team-attribution
class="tw-mb-1 tw-mt-0.5"
v-if="teams.length"
:teams="teams"
v-if="combinedTeams.length"
:teams="combinedTeams"
:loan-id="loan.id"
:team-id="loan.team ? loan.team.id : 0"
:team-id="loanTeamAttributionId"
/>
<loan-promo-credits
:applied-promo-credits="appliedPromoCredits"
Expand Down Expand Up @@ -123,6 +123,8 @@ import LoanPrice from '@/components/Checkout/LoanPrice';
import RemoveBasketItem from '@/components/Checkout/RemoveBasketItem';
import TeamAttribution from '@/components/Checkout/TeamAttribution';

const teamChallengeCookieName = 'kv-team-challenge';

export default {
name: 'BasketItem',
components: {
Expand Down Expand Up @@ -157,6 +159,8 @@ export default {
return {
activateTimer: true,
loanVisible: true,
appendedTeams: [],
forceTeamId: null
};
},
computed: {
Expand All @@ -178,6 +182,15 @@ export default {
leftoverCreditAllocationLoanId() {
return this.cookieStore.get('lcaid');
},
combinedTeams() {
return [...this.teams, ...this.appendedTeams];
},
loanTeamAttributionId() {
if (this.forceTeamId) {
return this.forceTeamId;
}
return this.loan.team ? this.loan.team.id : 0;
}
},
methods: {
onLoanUpdate($event) {
Expand All @@ -193,5 +206,33 @@ export default {
this.$emit('validateprecheckout');
}
},
mounted() {
// Team Challenge MVP Code
// If team challenge cookie is present, the user has added a loan to basket from the challenge page
// In that case, append the team info to the list of teams and attribute this loan to that team
if (this.cookieStore.get(teamChallengeCookieName)) {
const teamChallengeLoanData = JSON.parse(this.cookieStore.get(teamChallengeCookieName));
teamChallengeLoanData.forEach(loan => {
if (loan.loanId === this.loan.id) {
// Loan has a different team attribution, we should override the default
// Is team not in the users list, append it
if (!this.combinedTeams.some(team => team.id === loan.teamId)) {
this.appendedTeams.push({
id: loan.teamId,
name: loan.teamName
});
}
this.forceTeamId = loan.teamId;
}
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we cleanup/delete the cookie at this point if it's been used?

// Remove this loan from the cookie object after we've used it
teamChallengeLoanData.splice(
teamChallengeLoanData.findIndex(loan => loan.loanId === this.loan.id),
1
);
// overwrite the cookie with the new data
this.cookieStore.set(teamChallengeCookieName, JSON.stringify(teamChallengeLoanData));
}
}
};
</script>
Loading