Skip to content

Commit

Permalink
Merge pull request #5101 from kiva/ACK-863_attribute_loan_to_team_in_…
Browse files Browse the repository at this point in the history
…cookie

feat: ability to attribute a loan to a team from cookie value
  • Loading branch information
eddieferrer authored Dec 18, 2023
2 parents 8b7c968 + a2548e2 commit 78a4c92
Showing 1 changed file with 44 additions and 3 deletions.
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;
}
});
// 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>

0 comments on commit 78a4c92

Please sign in to comment.