aboutsummaryrefslogtreecommitdiff
path: root/src/components/user_note/user_note.js
blob: dc5b8e7178126c949e58a84ea16314ef6eb17f3b (plain)
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
const UserNote = {
  props: {
    user: Object,
    relationship: Object
  },
  data () {
    return {
      localNote: '',
      editing: false,
      frozen: false
    }
  },
  computed: {
    shouldShow () {
      return this.relationship.note || this.editing
    }
  },
  methods: {
    startEditing () {
      this.localNote = this.relationship.note
      this.editing = true
    },
    cancelEditing () {
      this.editing = false
    },
    finalizeEditing () {
      this.frozen = true

      this.$store.dispatch('editUserNote', {
        id: this.user.id,
        comment: this.localNote
      })
        .then(() => {
          this.frozen = false
          this.editing = false
        })
        .catch(() => {
          this.frozen = false
        })
    }
  }
}

export default UserNote