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.

230 lines
6.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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.FirstName" :validation="validation.FirstName" @change="formData.FirstName = $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.LastName" :validation="validation.LastName" @change="formData.LastName = $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
  44. class="d-none"
  45. enabledCountryCode
  46. :enabledFlags="false"
  47. @onSelect="showCode"
  48. v-model="formData.PhoneCountryCode"
  49. ></vue-country-code>
  50. <vue-phone-number-input
  51. color="#e5e5e5"
  52. :border-radius="5"
  53. error-color="#ef5a5a"
  54. valid-color="#e5e5e5"
  55. :error="error"
  56. required
  57. no-flags
  58. no-example
  59. :validation="validation.PhoneNo"
  60. v-model="formData.PhoneNo"
  61. ></vue-phone-number-input>
  62. </div>
  63. </div>
  64. <div class="modal-footer md:tw-flex md:tw-flex-row-reverse md:tw-justify-start md:tw-items-center">
  65. <button
  66. 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"
  67. @click="save">
  68. {{ $t("userProfile.add") }}
  69. </button>
  70. <button
  71. 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]"
  72. @click="reset">
  73. {{ $t("Clear") }}
  74. </button>
  75. </div>
  76. </div>
  77. </modal>
  78. </template>
  79. <script>
  80. import elementInput from "@/components/newComponent/form/ElementInput";
  81. import Swal from "sweetalert2";
  82. import is from "is_js";
  83. export default {
  84. name: "AddContactModal",
  85. components: {
  86. elementInput,
  87. },
  88. data() {
  89. return {
  90. formData: {
  91. FirstName: "",
  92. LastName: "",
  93. Email: "",
  94. PhoneCountryCode: "",
  95. PhoneNo: "",
  96. },
  97. validation: {
  98. FirstName: true,
  99. LastName: true,
  100. Email: true,
  101. PhoneNo: true,
  102. },
  103. isValid: true,
  104. countryCode: "",
  105. phoneValid: false,
  106. errors: null,
  107. error: false,
  108. };
  109. },
  110. mounted() { },
  111. methods: {
  112. reset() {
  113. this.formData = {
  114. FirstName: "",
  115. LastName: "",
  116. Email: "",
  117. PhoneCountryCode: "",
  118. PhoneNo: "",
  119. };
  120. },
  121. getPhoneData(phoneData) {
  122. this.formData.PhoneCountryCode = phoneData.countryCode;
  123. },
  124. showCode(object) {
  125. this.formData.PhoneCountryCode = object.dialCode;
  126. },
  127. save() {
  128. this.validators();
  129. if (this.validators()) {
  130. const patchData = JSON.parse(JSON.stringify(this.formData));
  131. this.$axios
  132. .post(
  133. `/trending/api/Members/Contact`, patchData
  134. )
  135. .then((response) => {
  136. console.log(JSON.stringify(response));
  137. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  138. let data = response.data.DATA.rel
  139. if(data){
  140. this.$emit("update", true);
  141. this.reset();
  142. this.$modal.hide("add-contact-modal");
  143. }
  144. }
  145. })
  146. .catch((error) => {
  147. console.log(error);
  148. });
  149. }
  150. },
  151. validators() {
  152. if (is.empty(this.formData.FirstName)) {
  153. this.validation.FirstName = false;
  154. } else {
  155. this.validation.FirstName = true;
  156. }
  157. if (is.empty(this.formData.LastName)) {
  158. this.validation.LastName = false;
  159. } else {
  160. this.validation.LastName = true;
  161. }
  162. if (is.empty(this.formData.Email) || is.not.email(this.formData.Email)) {
  163. this.validation.Email = false;
  164. } else {
  165. this.validation.Email = true;
  166. }
  167. if (this.formData.PhoneNo == null
  168. ) {
  169. this.validation.PhoneNo = false;
  170. this.error = true;
  171. } else {
  172. this.validation.PhoneNo = true;
  173. this.error = false;
  174. }
  175. this.errors = Object.entries(this.validation).filter(
  176. (e) => e[1] == false
  177. );
  178. if (this.errors.length > 0) {
  179. return false;
  180. } else {
  181. return true;
  182. }
  183. },
  184. },
  185. };
  186. </script>
  187. <style lang="scss" scoped>
  188. .close {
  189. // position: absolute;
  190. right: 30px;
  191. top: 32px;
  192. background-image: url("~/assets/svg/close.svg");
  193. background-position: center;
  194. background-repeat: no-repeat;
  195. background-size: cover;
  196. width: 14px;
  197. height: 14px;
  198. @media screen and (min-width: 768px) {
  199. right: 40px;
  200. top: 40px;
  201. }
  202. }
  203. .v--modal-overlay::v-deep {
  204. .v--modal {
  205. width: 100% !important;
  206. height: 100vh !important;
  207. @media screen and (min-width: 768px) {
  208. padding: 40px;
  209. width: max-content;
  210. height: max-content !important;
  211. border-radius: 30px;
  212. }
  213. }
  214. .v--modal-box {
  215. height: 100vh !important;
  216. overflow: auto;
  217. @media screen and (min-width: 768px) {
  218. padding: 40px;
  219. width: max-content;
  220. height: max-content !important;
  221. }
  222. }
  223. }
  224. </style>