Skip to content

Commit

Permalink
feat: ability to attribute a loan to a team from cookie value
Browse files Browse the repository at this point in the history
  • Loading branch information
eddieferrer committed Dec 14, 2023
1 parent 4e60e76 commit 2812e72
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 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,26 @@ 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;
}
});
}
}
};
</script>

0 comments on commit 2812e72

Please sign in to comment.