This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcd-dashboard-dojo-anniversary.vue
83 lines (79 loc) · 2.61 KB
/
cd-dashboard-dojo-anniversary.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<template>
<div class="cd-dashboard__anniversaries">
<div v-for="dojo in filteredDojos" class="cd-dashboard__anniversary">
<span class="cd-dashboard__anniversary-popper">🎉</span>
<a :href="formUrl(dojo)">{{ $t('{dojoName}, your Dojo anniversary is approaching! Apply now for your FREE birthday pack to celebrate', { dojoName: dojo.name }) }}</a>
</div>
</div>
</template>
<script>
import moment from 'moment';
export default {
name: 'cd-dashboard-dojo-anniversary',
props: ['dojos', 'dojoAdmins'],
data() {
return {
filteredDojos: [],
};
},
computed: {
baseUrl() {
return `${window.location.protocol}//${window.location.hostname}`;
},
},
methods: {
formUrl(dojo) {
const url = `${this.baseUrl}/dojos/${dojo.urlSlug}`;
return `https://docs.google.com/forms/d/e/1FAIpQLScNDxfs7MP4aOA9f8iZPTuNl6NVO2RHpIch5VGwUDiupaGOxA/viewform?entry.803640143=${dojo.name}&entry.2104926148=${url}`;
},
hasAnniversary(dojo) {
const now = moment();
const referenceDate = moment(dojo.created);
referenceDate.year(now.year());
const timeToAnniversary = now.diff(referenceDate, 'months');
// Note: this won't be exact due to the user's tz and the creation date being in IST
return timeToAnniversary >= -2 && timeToAnniversary <= 0 && now <= referenceDate;
},
championOfDojos(dojos, dojoAdmins) {
return dojoAdmins.reduce((acc, membership) => {
if (dojos[membership.dojoId]) acc.push(dojos[membership.dojoId]);
return acc;
}, []);
},
isOld(dojo) {
const difference = moment(dojo.created).diff(moment(), 'month');
return difference <= -10;
},
dojosWithUpcomingAnniversary(dojos) {
// Note: that could also be filtered with a modulo of 12 months
return dojos.filter(dojo => this.hasAnniversary(dojo) && this.isOld(dojo));
},
},
created() {
const isChampionOfDojos = this.championOfDojos(this.dojos, this.dojoAdmins);
this.filteredDojos = this.dojosWithUpcomingAnniversary(isChampionOfDojos);
},
};
</script>
<style scoped lang="less">
@import "~@coderdojo/cd-common/common/_colors";
@import "../common/variables";
.cd-dashboard{
&__anniversary {
text-align: center;
margin-bottom: @margin;
a {
color: @cd-white;
text-decoration: underline;
font-size: @font-size-medium;
i {
margin-right: 8px;
}
}
&-popper {
color: @cd-orange;
font-size: 1.5em;
}
}
}
</style>