-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edit.vue
102 lines (95 loc) · 2.53 KB
/
Edit.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<template>
<div class="edit-item">
<ValidationObserver v-slot="{ handleSubmit }">
<form @submit.prevent="handleSubmit(createItem)">
<ValidationProvider
v-slot="{ errors }"
name="To Do"
:rules="'min:3|max:255'"
slim
>
<BField
:type="{ 'is-danger': errors[0] }"
:message="errors"
:expanded="true"
>
<BInput v-model="content" placeholder="To Do" :expanded="true" />
</BField>
<to-do-priority-selector
v-bind:defaultPriority="priority"
v-on:buttonSelected = "buttonSelected"
></to-do-priority-selector>
</ValidationProvider>
<section>
<div class="buttons are-medium">
<BButton native-type="submit" type="is-primary" class="control">
Save
</BButton>
<BButton @click="$router.back()">
Cancel
</BButton>
</div>
</section>
</form>
</ValidationObserver>
<BLoading :is-full-page="false" :active.sync="isLoading" />
</div>
</template>
<script lang="ts">
import { Component, Vue, Prop } from "vue-property-decorator";
import { ValidationProvider, ValidationObserver } from "vee-validate";
import gql from "graphql-tag";
import ToDoPrioritySelector from '@/components/ToDoPrioritySelector.vue';
@Component({
components: {
ValidationProvider,
ValidationObserver,
ToDoPrioritySelector
}
})
export default class Edit extends Vue {
@Prop({ required: true }) item: any;
// @Prop({ required: true }) id: any;
// @Prop({ required: true }) originalContent: any;
isLoading = false;
content = "";
priority = "";
mounted()
{
this.content = this.item.content;
this.priority = this.item.priority;
}
buttonSelected(e:string)
{
this.priority = e;
}
createItem() {
this.isLoading = true;
this.$apollo
.mutate({
mutation: gql`
mutation($input: UpdateToDoItemInput!) {
updateToDoItem(input: $input) {
toDoItem {
content
createdDate
id
status
priority
}
}
}
`,
variables: {
input: {
id: this.item.id,
content: this.content,
priority: this.priority
}
}
})
.then(() => this.$router.back())
.finally(() => (this.isLoading = false));
}
}
</script>