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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<script>
import { GlDatepicker } from '@gitlab/ui';
import { mapActions } from 'vuex';
import { getDateInFuture } from '~/lib/utils/datetime_utility';
import { s__ } from '~/locale';
export default {
name: 'ExpirationDatepicker',
components: { GlDatepicker },
props: {
member: {
type: Object,
required: true,
},
permissions: {
type: Object,
required: true,
},
},
data() {
return {
selectedDate: null,
busy: false,
};
},
computed: {
minDate() {
// Members expire at the beginning of the day.
// The first selectable day should be tomorrow.
const today = new Date();
const beginningOfToday = new Date(today.setHours(0, 0, 0, 0));
return getDateInFuture(beginningOfToday, 1);
},
disabled() {
return (
this.busy ||
!this.permissions.canUpdate ||
(this.permissions.canOverride && !this.member.isOverridden)
);
},
},
mounted() {
if (this.member.expiresAt) {
this.selectedDate = new Date(this.member.expiresAt);
}
},
methods: {
...mapActions(['updateMemberExpiration']),
handleInput(date) {
this.busy = true;
this.updateMemberExpiration({
memberId: this.member.id,
expiresAt: date,
})
.then(() => {
this.$toast.show(s__('Members|Expiration date updated successfully.'));
this.busy = false;
})
.catch(() => {
this.busy = false;
});
},
handleClear() {
this.busy = true;
this.updateMemberExpiration({
memberId: this.member.id,
expiresAt: null,
})
.then(() => {
this.$toast.show(s__('Members|Expiration date removed successfully.'));
this.selectedDate = null;
this.busy = false;
})
.catch(() => {
this.busy = false;
});
},
},
};
</script>
<template>
<!-- `:target="null"` allows the datepicker to be opened on focus -->
<!-- `:container="null"` renders the datepicker in the body to prevent conflicting CSS table styles -->
<gl-datepicker
v-model="selectedDate"
class="gl-max-w-full"
show-clear-button
:target="null"
:container="null"
:min-date="minDate"
:placeholder="__('Expiration date')"
:disabled="disabled"
@input="handleInput"
@clear="handleClear"
/>
</template>
|