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.

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