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.

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