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.

202 lines
5.6 KiB

2 years ago
2 years ago
2 years ago
  1. <template>
  2. <modal name="edit-contact-modal" width="100%" :clickToClose="false">
  3. <div class="tw-p-[40px]">
  4. <div
  5. class="modal-header tw-flex tw-justify-center tw-items-center tw-mb-[40px] md:tw-mb-[40px] xl:tw-justify-between">
  6. <div class="tw-text-[20px] tw-font-bold tw-leading-[26px]">
  7. {{ $t("Edit Contact Info") }}
  8. </div>
  9. <button class="close tw-transition tw-btn-md" @click="$modal.hide('edit-contact-modal')"></button>
  10. </div>
  11. <div class="modal-content tw-grid tw-grid-cols-1 tw-gap-y-[10px] md:tw-grid-cols-2 md:tw-gap-x-[60px]">
  12. <div class="element">
  13. <elementInput :input="{
  14. id: 'FirstName',
  15. label: 'First name',
  16. required: true,
  17. type: 'text',
  18. }" :default="formData.first_name" :validation="validation.first_name"
  19. @change="formData.first_name = $event"></elementInput>
  20. </div>
  21. <div class="element">
  22. <elementInput :input="{
  23. id: 'LastName',
  24. label: 'Last Name',
  25. required: true,
  26. type: 'text',
  27. }" :default="formData.last_name" :validation="validation.last_name" @change="formData.last_name = $event">
  28. </elementInput>
  29. </div>
  30. <div class="element">
  31. <elementInput :input="{
  32. id: 'Email',
  33. label: 'Email',
  34. required: true,
  35. type: 'email',
  36. }" :default="formData.email" :validation="validation.email" @change="formData.email = $event">
  37. </elementInput>
  38. </div>
  39. <div class="element">
  40. <label class="tw-block tw-mb-[10px]"><span>{{ $t("Phone") }}<span class="required">*</span></span></label>
  41. <vue-country-code class="d-none" enabledCountryCode :enabledFlags="false"></vue-country-code>
  42. <vue-phone-number-input color="#EF5A5A" valid-color="#EE9546" :border-radius="5" no-flags no-example
  43. v-model="formData.phone_number"></vue-phone-number-input>
  44. </div>
  45. </div>
  46. <div class="modal-footer tw-flex tw-justify-end tw-items-center tw-mt-[60px]">
  47. <button class="tw-transition tw-btn-md tw-text-primary-1 tw-px-[30px] tw-py-[9.5px] tw-mr-[10px] tw-rounded-2xl"
  48. @click="reset">
  49. {{ $t("Clear") }}
  50. </button>
  51. <button
  52. class="tw-transition tw-btn-md tw-bg-primary-1 tw-px-[30px] tw-py-[9.5px] tw-rounded-2xl hover:tw-bg-primary-2"
  53. @click="save">
  54. {{ $t("Save") }}
  55. </button>
  56. </div>
  57. </div>
  58. </modal>
  59. </template>
  60. <script>
  61. import elementInput from "@/components/newComponent/form/ElementInput";
  62. import is from "is_js";
  63. export default {
  64. name: "EditContactModal",
  65. components: {
  66. elementInput,
  67. is,
  68. },
  69. props: {
  70. contact: {
  71. type: Object,
  72. },
  73. },
  74. data() {
  75. return {
  76. formData: {},
  77. validation: {
  78. first_name: true,
  79. last_name: true,
  80. email: true,
  81. phone_number: true,
  82. },
  83. errors: null,
  84. };
  85. },
  86. mounted() {},
  87. watch: {
  88. contact: {
  89. handler: function () {
  90. // this.formData = JSON.parse(JSON.stringify(this.contact));
  91. },
  92. },
  93. },
  94. methods: {
  95. reset() {
  96. this.formData = {
  97. first_name: "",
  98. last_name: "",
  99. email: "",
  100. country_code: "",
  101. phone_number: "",
  102. };
  103. },
  104. save() {
  105. this.validators();
  106. if (this.validators()) {
  107. const patchData = JSON.parse(JSON.stringify(this.formData));
  108. this.$axios
  109. .patch(
  110. `/member/contacts/${this.formData.contact_uuid}?jwt=${
  111. this.$auth.$storage.getUniversal("jwt").token
  112. }`,
  113. patchData
  114. )
  115. .then((result) => {
  116. console.log(result);
  117. if ((result.status = 200)) {
  118. this.$emit("update", true);
  119. this.$modal.hide("edit-contact-modal");
  120. }
  121. })
  122. .catch((err) => {
  123. console.log(err);
  124. });
  125. }
  126. },
  127. validators() {
  128. if (is.empty(this.formData.first_name)) {
  129. this.validation.first_name = false;
  130. } else {
  131. this.validation.first_name = true;
  132. }
  133. if (is.empty(this.formData.last_name)) {
  134. this.validation.last_name = false;
  135. } else {
  136. this.validation.last_name = true;
  137. }
  138. if (is.empty(this.formData.email) || is.not.email(this.formData.email)) {
  139. this.validation.email = false;
  140. } else {
  141. this.validation.email = true;
  142. }
  143. if (
  144. is.empty(this.formData.phone_number) &&
  145. is.number(this.formData.phone_number)
  146. ) {
  147. this.validation.phone_number = false;
  148. } else {
  149. this.validation.phone_number = true;
  150. }
  151. this.errors = Object.entries(this.validation).filter(
  152. (e) => e[1] == false
  153. );
  154. if (this.errors.length > 0) {
  155. return false;
  156. } else {
  157. return true;
  158. }
  159. },
  160. },
  161. };
  162. </script>
  163. <style lang="scss" scoped>
  164. .close {
  165. position: absolute;
  166. right: 25px;
  167. top: 25px;
  168. background-image: url("~/assets/svg/close.svg");
  169. background-position: center;
  170. background-repeat: no-repeat;
  171. background-size: cover;
  172. width: 14px;
  173. height: 14px;
  174. @media screen and (min-width: 1366px) {
  175. position: relative;
  176. right: initial;
  177. top: initial;
  178. }
  179. }
  180. :deep() {
  181. .v--modal-box {
  182. height: 100vh !important;
  183. @media screen and (min-width: 768px) {
  184. height: max-content !important;
  185. width: max-content;
  186. }
  187. }
  188. .v--modal {
  189. height: 100vh !important;
  190. @media screen and (min-width: 768px) {
  191. height: max-content !important;
  192. width: max-content;
  193. }
  194. }
  195. }
  196. </style>