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.

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