Intake.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div class="search">
  3. <h1>Intake Form</h1>
  4. <form class="form-horizontal" @submit.prevent="submitIntakeForm()">
  5. <!-- TODO: Change these to readonly values from the statefilter. -->
  6. <FormFieldSelect
  7. v-bind:label="'Team'"
  8. v-bind:error="errors.team"
  9. v-bind:id="'team'"
  10. v-bind:data="currentUser.teams"
  11. v-bind:value="intake.team"
  12. @update="val => (intake.team = val)"
  13. />
  14. <FormFieldSelect
  15. v-bind:label="'Assign to'"
  16. v-bind:error="errors.user"
  17. v-bind:id="'user'"
  18. v-bind:data="runtimevals.users"
  19. v-bind:value="intake.user"
  20. @update="val => (intake.user = val)"
  21. />
  22. <FormFieldInput
  23. v-bind:label="'Subject'"
  24. v-bind:error="errors.subject"
  25. v-bind:id="'subject'"
  26. v-bind:type="'text'"
  27. v-bind:value="intake.subject"
  28. @update="val => (intake.subject = val)"
  29. />
  30. <FormFieldInput
  31. v-bind:label="'Given/First Name'"
  32. v-bind:error="errors.first_name"
  33. v-bind:id="'first_name'"
  34. v-bind:type="'text'"
  35. v-bind:value="intake.first_name"
  36. @update="val => (intake.first_name = val)"
  37. />
  38. <FormFieldInput
  39. v-bind:label="'Surname/Last Name'"
  40. v-bind:error="errors.last_name"
  41. v-bind:id="'last_name'"
  42. v-bind:type="'text'"
  43. v-bind:value="intake.last_name"
  44. @update="val => (intake.last_name = val)"
  45. />
  46. <FormFieldInput
  47. v-bind:label="'Email'"
  48. v-bind:error="errors.email"
  49. v-bind:id="'email'"
  50. v-bind:type="'text'"
  51. v-bind:value="intake.email"
  52. @update="val => (intake.email = val)"
  53. />
  54. <FormFieldInput
  55. v-bind:label="'Telephone'"
  56. v-bind:error="errors.telephone"
  57. v-bind:id="'telephone'"
  58. v-bind:type="'text'"
  59. v-bind:value="intake.telephone"
  60. @update="val => (intake.telephone = val)"
  61. />
  62. <FormFieldInput
  63. v-bind:label="'Appointment Date'"
  64. v-bind:error="errors.startOnDate"
  65. v-bind:id="'startOnDate'"
  66. v-bind:type="'date'"
  67. v-bind:value="intake.startOnDate"
  68. @update="val => (intake.startOnDate = val)"
  69. />
  70. <FormFieldInput
  71. v-bind:label="'Start Time (Hour:Minute AM/PM)'"
  72. v-bind:error="errors.startOnTime"
  73. v-bind:id="'startOnTime'"
  74. v-bind:type="'time'"
  75. v-bind:value="intake.startOnTime"
  76. @update="val => (intake.startOnTime = val)"
  77. />
  78. <FormFieldInput
  79. v-bind:label="'Duration'"
  80. v-bind:error="errors.startOnDuration"
  81. v-bind:id="'startOnDuration'"
  82. v-bind:type="'number'"
  83. v-bind:value="intake.startOnDuration"
  84. @update="val => (intake.startOnDuration = val)"
  85. />
  86. <br />
  87. <button type="submit" class="btn btn-primary">
  88. Submit Intake Form
  89. </button>
  90. </form>
  91. </div>
  92. </template>
  93. <script>
  94. import FormFieldInput from "@/components/FormFieldInput.vue";
  95. import FormFieldSelect from "@/components/FormFieldSelect.vue";
  96. import { mapGetters } from "vuex";
  97. export default {
  98. name: "Intake",
  99. components: {
  100. FormFieldInput,
  101. FormFieldSelect
  102. },
  103. computed: {
  104. ...mapGetters(["api", "currentUser", "readonly"])
  105. },
  106. data: function() {
  107. return {
  108. intake: "",
  109. errors: "",
  110. runtimevals: {
  111. users: ""
  112. }
  113. };
  114. },
  115. methods: {
  116. submitIntakeForm() {
  117. console.log("TODO");
  118. },
  119. resetForm: function(that, ref) {
  120. that[ref] = {
  121. team: "",
  122. subject: "",
  123. first_name: "",
  124. last_name: "",
  125. email: "",
  126. telephone: "",
  127. startOnDate: "",
  128. startOnTime: "",
  129. startOnDuration: "30",
  130. user: ""
  131. };
  132. }
  133. },
  134. mounted() {
  135. function getData(endpoint, that, bucket, refs, errorPrompt) {
  136. if (endpoint) {
  137. fetch(endpoint)
  138. .then(response => response.json())
  139. .then(json => {
  140. if (json) {
  141. that[bucket][refs] = json;
  142. } else {
  143. that[errorPrompt] = "Response failed.";
  144. }
  145. })
  146. .catch(error => {
  147. that[errorPrompt] = `Request failed. ${error}`;
  148. });
  149. } else {
  150. that[errorPrompt] = "No configuration.";
  151. }
  152. }
  153. getData(this.api.apptUsers, this, "runtimevals", "users", "errorPrompt");
  154. this.resetForm(this, "intake");
  155. if (this.readonly === true) {
  156. this.$router.push({ name: "Search" });
  157. }
  158. }
  159. };
  160. </script>