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.

220 lines
6.4 KiB

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