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.

214 lines
6.4 KiB

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