You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <template>
  2. <base-card
  3. title="Add Member"
  4. agree-text="Add"
  5. cancel-text="Cancel"
  6. :disabled="!valid"
  7. @agree="create"
  8. @cancel="cancel"
  9. >
  10. <template #content>
  11. <v-form
  12. ref="form"
  13. v-model="valid"
  14. >
  15. <v-autocomplete
  16. v-model="selectedUser"
  17. :items="items"
  18. :loading="isLoading"
  19. :search-input.sync="username"
  20. :rules="userNameRules"
  21. color="white"
  22. hide-no-data
  23. hide-selected
  24. item-text="username"
  25. label="User Search APIs"
  26. placeholder="Start typing to Search"
  27. prepend-icon="mdi-account"
  28. return-object
  29. />
  30. <v-select
  31. v-model="role"
  32. :items="roles"
  33. :rules="roleRules"
  34. label="Role"
  35. prepend-icon="mdi-account-card-details-outline"
  36. />
  37. </v-form>
  38. </template>
  39. </base-card>
  40. </template>
  41. <script>
  42. import BaseCard from '@/components/molecules/BaseCard'
  43. import { userNameRules, roleRules } from '@/rules/index'
  44. export default {
  45. components: {
  46. BaseCard
  47. },
  48. props: {
  49. addMember: {
  50. type: Function,
  51. default: () => {},
  52. required: true
  53. },
  54. items: {
  55. type: Array,
  56. default: () => {},
  57. required: true
  58. }
  59. },
  60. data() {
  61. return {
  62. valid: false,
  63. username: '',
  64. role: null,
  65. isLoading: false,
  66. selectedUser: null,
  67. roles: ['Admin', 'Member'],
  68. userNameRules,
  69. roleRules
  70. }
  71. },
  72. watch: {
  73. username(val) {
  74. this.$emit('search-user', val)
  75. }
  76. },
  77. methods: {
  78. cancel() {
  79. this.$emit('close')
  80. },
  81. validate() {
  82. return this.$refs.form.validate()
  83. },
  84. reset() {
  85. this.$refs.form.reset()
  86. },
  87. create() {
  88. if (this.validate()) {
  89. this.addMember({
  90. userId: this.selectedUser.id,
  91. projectId: this.$route.params.id,
  92. role: this.role
  93. })
  94. this.reset()
  95. this.cancel()
  96. }
  97. }
  98. }
  99. }
  100. </script>