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.

278 lines
8.5 KiB

2 years ago
  1. <template>
  2. <modal name="addCompany" :clickToClose="false">
  3. <div class="tw-text-base-primary">
  4. <div class="modal-header tw-w-full tw-mb-[20px] md:tw-mb-[50px]">
  5. <div class="tw-text-[18px] tw-font-bold md:tw-text-[20px]">
  6. {{ $t("userProfile.addCompanyInfo") }}
  7. </div>
  8. <button class="close tw-transition tw-btn-md" @click="$modal.hide('addCompany')"></button>
  9. </div>
  10. <div
  11. class="modal-content tw-grid tw-grid-cols-1 tw-gap-y-[20px] tw-mb-[30px] md:tw-grid-cols-[260px_260px] md:tw-gap-x-[64px] md:tw-mb-[60px]">
  12. <div class="element">
  13. <elementInput :input="{
  14. id: 'CompanyName',
  15. label: 'userProfile.companyName',
  16. required: true,
  17. type: 'text',
  18. }" :default="userCompanyInfo.company_name" :validation="validation.company_name"
  19. @change="userCompanyInfo.company_name = $event"></elementInput>
  20. </div>
  21. <div class="element">
  22. <elementInput :input="{
  23. id: 'TaxNumber',
  24. label: 'userProfile.taxNumber',
  25. required: true,
  26. type: 'tel',
  27. }" :default="userCompanyInfo.company_tax_no" :validation="validation.company_tax_no"
  28. @change="userCompanyInfo.company_tax_no = $event"></elementInput>
  29. </div>
  30. <div class="element md:tw-col-span-2">
  31. <elementAddress :input="{
  32. id: 'StreetAddress',
  33. label: 'userProfile.companyAddress',
  34. required: true,
  35. type: 'street',
  36. }" :default1="userCompanyInfo.company_address1" :default2="userCompanyInfo.company_address2"
  37. :validation1="validation.company_address1" :validation2="validation.company_address2"
  38. @change1="userCompanyInfo.company_address1 = $event" @change2="userCompanyInfo.company_address2 = $event">
  39. </elementAddress>
  40. </div>
  41. <div class="element">
  42. <elementInput :input="{
  43. id: 'City',
  44. label: 'userProfile.companyCity',
  45. required: true,
  46. type: 'text',
  47. }" :default="userCompanyInfo.company_city" :validation="validation.company_city"
  48. @change="userCompanyInfo.company_city = $event"></elementInput>
  49. </div>
  50. <div class="element">
  51. <elementInput :input="{
  52. id: 'State',
  53. label: 'userProfile.stateAndProvince',
  54. required: false,
  55. type: 'text',
  56. }" :default="userCompanyInfo.company_state" :validation="validation.company_state"
  57. @change="userCompanyInfo.company_state = $event"></elementInput>
  58. </div>
  59. <div class="element">
  60. <elementSelect :select="{
  61. id: 'Country',
  62. label: 'userProfile.companyCountry',
  63. required: true,
  64. }" :selectList="countryOptions" :default="userCompanyInfo.company_country"
  65. :validation="validation.company_country" @change="userCompanyInfo.company_country = $event"></elementSelect>
  66. </div>
  67. <div class="element">
  68. <elementInput :input="{
  69. id: 'ZIP',
  70. label: 'userProfile.zipAndPostalCode',
  71. required: true,
  72. type: 'zip',
  73. }" :default="userCompanyInfo.company_zipcode" :validation="validation.company_zipcode"
  74. @change="userCompanyInfo.company_zipcode = $event"></elementInput>
  75. </div>
  76. </div>
  77. <div class="md:tw-flex md:tw-flex-row-reverse">
  78. <button
  79. class="tw-transition tw-btn-md tw-bg-primary-1 tw-text-white tw-w-full tw-py-[13px] tw-rounded-[16px] tw-mb-[10px] md:hover:tw-bg-primary-2 md:tw-w-fit md:tw-px-[24px] md:tw-mb-0"
  80. @click="save()">
  81. {{ $t("userProfile.add") }}
  82. </button>
  83. <button
  84. class="tw-transition tw-btn-md tw-bg-white tw-text-primary-1 tw-w-full tw-py-[13px] tw-rounded-[16px] md:tw-w-fit md:tw-px-[24px] md:tw-mr-[10px]"
  85. @click="reset()">
  86. {{ $t('userProfile.cancel')}}
  87. </button>
  88. </div>
  89. </div>
  90. </modal>
  91. </template>
  92. <script>
  93. import elementInput from "@/components/newComponent/form/ElementInput.vue";
  94. import elementAddress from "@/components/newComponent/form/ElementAddress.vue";
  95. import elementSelect from "@/components/newComponent/form/ElementSelect.vue";
  96. import is from "is_js";
  97. export default {
  98. name: "addCompany",
  99. props: {
  100. countryOptions: {
  101. type: Array,
  102. },
  103. selectList: {
  104. type: Array,
  105. },
  106. },
  107. data() {
  108. return {
  109. userCompanyInfo: {
  110. company_name: "",
  111. company_tax_no: "",
  112. company_address1: "",
  113. company_address2: "",
  114. company_city: "",
  115. company_state: "",
  116. company_country: 0,
  117. company_zipcode: "",
  118. },
  119. validation: {
  120. company_name: true,
  121. company_tax_no: true,
  122. company_address1: true,
  123. company_address2: true,
  124. company_city: true,
  125. company_country: true,
  126. company_state: true,
  127. company_zipcode: true,
  128. },
  129. // valid: false,
  130. errors: null,
  131. };
  132. },
  133. components: {
  134. elementInput,
  135. elementAddress,
  136. elementSelect,
  137. is,
  138. },
  139. methods: {
  140. reset() {
  141. this.userCompanyInfo = {
  142. company_name: "",
  143. company_tax_no: "",
  144. company_address1: "",
  145. company_address2: "",
  146. company_city: "",
  147. company_state: "",
  148. company_country: 0,
  149. company_zipcode: "",
  150. };
  151. this.$modal.hide("addCompany");
  152. },
  153. patchUserData() {
  154. this.$axios
  155. .post(
  156. `/member/company?jwt=${this.$auth.$storage.getUniversal("jwt").token || ""
  157. }`,
  158. this.userCompanyInfo
  159. )
  160. .then((result) => {
  161. this.$emit("refetch-user");
  162. this.$modal.hide("addCompany");
  163. })
  164. .catch((err) => {
  165. console.log(err);
  166. });
  167. },
  168. validators() {
  169. if (is.empty(this.userCompanyInfo.company_name)) {
  170. this.validation.company_name = false;
  171. } else {
  172. this.validation.company_name = true;
  173. }
  174. if (is.empty(this.userCompanyInfo.company_tax_no)) {
  175. this.validation.company_tax_no = false;
  176. } else {
  177. this.validation.company_tax_no = true;
  178. }
  179. if (is.empty(this.userCompanyInfo.company_address1)) {
  180. this.validation.company_address1 = false;
  181. } else {
  182. this.validation.company_address1 = true;
  183. }
  184. if (is.empty(this.userCompanyInfo.company_city)) {
  185. this.validation.company_city = false;
  186. } else {
  187. this.validation.company_city = true;
  188. }
  189. if (this.userCompanyInfo.company_country == 0) {
  190. this.validation.company_country = false;
  191. } else {
  192. this.validation.company_country = true;
  193. }
  194. if (is.empty(this.userCompanyInfo.company_zipcode)) {
  195. this.validation.company_zipcode = false;
  196. } else {
  197. this.validation.company_zipcode = true;
  198. }
  199. this.errors = Object.entries(this.validation).filter(
  200. (e) => e[1] == false
  201. );
  202. if (this.errors.length > 0) {
  203. return false;
  204. } else {
  205. return true;
  206. }
  207. },
  208. save() {
  209. this.validators();
  210. if (this.validators()) {
  211. const patchData = JSON.parse(JSON.stringify(this.userCompanyInfo));
  212. this.$axios
  213. .post(
  214. `/member/company?jwt=${this.$auth.$storage.getUniversal("jwt").token
  215. }`,
  216. patchData
  217. )
  218. .then((result) => {
  219. if (result.status == 200) {
  220. this.$emit("refetch-user");
  221. this.reset();
  222. this.$modal.hide("addCompany");
  223. }
  224. })
  225. .catch((err) => {
  226. console.log(err);
  227. });
  228. }
  229. },
  230. },
  231. };
  232. </script>
  233. <style scoped lang="scss">
  234. .close {
  235. position: absolute;
  236. right: 30px;
  237. top: 30px;
  238. background-image: url("~/assets/svg/close.svg");
  239. background-position: center;
  240. background-repeat: no-repeat;
  241. background-size: cover;
  242. width: 14px;
  243. height: 14px;
  244. @media screen and (min-width: 768px) {
  245. right: 40px;
  246. top: 40px;
  247. }
  248. }
  249. .v--modal-overlay::v-deep {
  250. .v--modal {
  251. padding: 30px;
  252. width: 100% !important;
  253. height: 100vh !important;
  254. @media screen and (min-width: 768px) {
  255. padding: 40px;
  256. width: max-content;
  257. height: max-content !important;
  258. border-radius: 30px;
  259. }
  260. }
  261. .v--modal-box {
  262. height: 100vh !important;
  263. overflow: auto;
  264. @media screen and (min-width: 768px) {
  265. padding: 40px;
  266. width: max-content;
  267. height: max-content !important;
  268. }
  269. }
  270. }
  271. </style>