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.

413 lines
14 KiB

2 years ago
  1. <template>
  2. <modal name="edit-company-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-[20px] 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.editCompanyInfo") }}
  9. </div>
  10. <button class="close tw-transition tw-btn-md" @click="$modal.hide('edit-company-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-[64px] md:tw-mb-[60px]">
  14. <div class="element">
  15. <elementInput :input="{
  16. id: 'CompanyName',
  17. label: 'userProfile.companyName',
  18. required: true,
  19. type: 'text',
  20. }" :default="userCompany.company_name" :validation="validation.company_name"
  21. @change="userCompany.company_name = $event"></elementInput>
  22. </div>
  23. <div class="element">
  24. <elementInput :input="{
  25. id: 'TaxNumber',
  26. label: 'userProfile.taxNumber',
  27. required: true,
  28. type: 'tel',
  29. }" :default="userCompany.company_tax_no" :validation="validation.company_tax_no"
  30. @change="userCompany.company_tax_no = $event"></elementInput>
  31. </div>
  32. <div class="element md:tw-col-span-2">
  33. <elementAddress :input="{
  34. id: 'StreetAddress',
  35. label: 'userProfile.companyAddress',
  36. required: true,
  37. type: 'street',
  38. }" :default1="userCompany.company_address1" :default2="userCompany.company_address2"
  39. :validation1="validation.company_address1" :validation2="validation.company_address2"
  40. @change1="userCompany.company_address1 = $event" @change2="userCompany.company_address2 = $event">
  41. </elementAddress>
  42. </div>
  43. <div class="element">
  44. <elementInput :input="{
  45. id: 'City',
  46. label: 'userProfile.companyCity',
  47. required: true,
  48. type: 'text',
  49. }" :default="userCompany.company_city" :validation="validation.company_city"
  50. @change="userCompany.company_city = $event"></elementInput>
  51. </div>
  52. <div class="element">
  53. <elementInput :input="{
  54. id: 'State',
  55. label: 'userProfile.stateAndProvince',
  56. required: false,
  57. type: 'text',
  58. }" :default="userCompany.company_state" :validation="validation.company_state"
  59. @change="userCompany.company_state = $event"></elementInput>
  60. </div>
  61. <div class="element">
  62. <elementSelect :select="{
  63. id: 'Country',
  64. label: 'userProfile.companyCountry',
  65. required: true,
  66. }" :selectList="countryOptions" :default="userCompany.company_country"
  67. :validation="validation.company_country" @change="userCompany.company_country = $event"></elementSelect>
  68. </div>
  69. <div class="element">
  70. <elementInput :input="{
  71. id: 'ZIP',
  72. label: 'userProfile.zipAndPostalCode',
  73. required: true,
  74. type: 'zip',
  75. }" :default="userCompany.company_zipcode" :validation="validation.company_zipcode"
  76. @change="userCompany.company_zipcode = $event"></elementInput>
  77. </div>
  78. </div>
  79. <div class="md:tw-flex md:tw-flex-row-reverse">
  80. <button
  81. class="tw-text-[18px] tw-bg-primary-1 tw-text-white 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"
  82. @click="save">
  83. {{ $t("userProfile.save") }}
  84. </button>
  85. <button
  86. class="tw-text-[18px] tw-bg-white 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]"
  87. @click="reset">
  88. {{ $t("userProfile.clear") }}
  89. </button>
  90. </div>
  91. </div>
  92. </modal>
  93. <!-- <v-dialog @click:outside="closeDialog" :value="companyEditInfoDialogActive"
  94. :width="$vuetify.breakpoint.mdAndUp ? '49%' : '90%'" style="z-index:500">
  95. <v-card class="border-radius-30 pa-10">
  96. <v-spacer class="d-flex mb-7 align-center">
  97. <span class="font-weight-bold text-size-18">{{ $t("userProfile.companyInfo") }}</span>
  98. <v-spacer></v-spacer>
  99. <v-btn icon @click="closeDialog">
  100. <v-icon>
  101. mdi-close
  102. </v-icon>
  103. </v-btn>
  104. </v-spacer>
  105. <v-form v-model="valid">
  106. <v-spacer :class="$vuetify.breakpoint.smAndUp ? 'd-flex' : ''">
  107. <v-spacer :class="$vuetify.breakpoint.smAndUp ? 'me-8' : ''" class="input-wrap">
  108. <span>{{ $t("userProfile.companyName")+'*' }}</span>
  109. <v-text-field v-model="userCompanyCopy.company_name" dense outlined :rules="[rules.require]"></v-text-field>
  110. </v-spacer>
  111. <v-spacer :class="$vuetify.breakpoint.smAndUp ? 'ms-8' : ''" class="input-wrap">
  112. <span>{{ $t("userProfile.taxNumber")+'*' }}</span>
  113. <v-text-field v-model="userCompanyCopy.company_tax_no" dense outlined :rules="[rules.require]">
  114. </v-text-field>
  115. </v-spacer>
  116. </v-spacer>
  117. <span>{{ $t("userProfile.companyAddress")+'*' }}</span>
  118. <v-spacer>
  119. <v-text-field v-model="userCompanyCopy.company_address1" dense :rules="[rules.require]" outlined>
  120. </v-text-field>
  121. <v-text-field v-model="userCompanyCopy.company_address2" dense :rules="[rules.require]" outlined>
  122. </v-text-field>
  123. </v-spacer>
  124. <v-spacer :class="$vuetify.breakpoint.smAndUp ? 'd-flex' : ''">
  125. <v-spacer :class="$vuetify.breakpoint.smAndUp ? 'me-8' : ''" class="input-wrap">
  126. <span>{{ $t("userProfile.companyCity")+'*' }}</span>
  127. <v-text-field v-model="userCompanyCopy.company_city" dense :rules="[rules.require]" outlined></v-text-field>
  128. </v-spacer>
  129. <v-spacer :class="$vuetify.breakpoint.smAndUp ? 'ms-8' : ''" class="input-wrap">
  130. <span>{{ $t("userProfile.stateAndProvince") }}</span>
  131. <v-text-field v-model="userCompanyCopy.company_state" dense outlined></v-text-field>
  132. </v-spacer>
  133. </v-spacer>
  134. <v-spacer :class="$vuetify.breakpoint.smAndUp ? 'd-flex' : ''">
  135. <v-spacer :class="$vuetify.breakpoint.smAndUp ? 'me-8' : ''" class="input-wrap">
  136. <span>{{ $t("userProfile.companyCountry")+'*' }}</span>
  137. <v-autocomplete v-model="countrySelect" :items="countryOptions" item-text="name" item-value="id" dense
  138. :rules="[rules.require]" outlined></v-autocomplete>
  139. </v-spacer>
  140. <v-spacer :class="$vuetify.breakpoint.smAndUp ? 'ms-8' : ''" class="input-wrap">
  141. <span>{{ $t("userProfile.zipAndPostalCode") }}</span>
  142. <v-text-field v-model="userCompanyCopy.company_zipcode" dense :rules="[rules.require]" outlined>
  143. </v-text-field>
  144. </v-spacer>
  145. </v-spacer>
  146. </v-form>
  147. <v-spacer class="d-flex justify-end">
  148. <v-btn @click="resetUserData" text width="112px" class="text-capitalize primary--text">
  149. {{ $t("userProfile.companyDialogClear") }}
  150. </v-btn>
  151. <v-btn @click="patchUserData" :disabled="!valid" class="border-radius-16 text-capitalize" color="primary"
  152. width="112px">
  153. {{ $t("userProfile.companyDialogAdd") }}
  154. </v-btn>
  155. </v-spacer>
  156. </v-card>
  157. </v-dialog> -->
  158. </template>
  159. <script>
  160. import elementInput from "@/components/newComponent/form/ElementInput";
  161. import elementAddress from "@/components/newComponent/form/ElementAddress";
  162. import elementSelect from "@/components/newComponent/form/ElementSelect";
  163. import is from "is_js";
  164. export default {
  165. name: "EditCompanytModal",
  166. components: {
  167. elementInput,
  168. elementAddress,
  169. elementSelect,
  170. is,
  171. },
  172. model: {
  173. // prop: "companyEditInfoDialogActive",
  174. event: "update:is-company-edit-dialog-active",
  175. },
  176. props: {
  177. companyEditInfoDialogActive: {
  178. type: Boolean,
  179. required: true,
  180. },
  181. userCompany: {
  182. type: Object,
  183. required: true,
  184. },
  185. countryOptions: {
  186. type: Array,
  187. required: true,
  188. },
  189. },
  190. data() {
  191. return {
  192. userCompanyCopy: {},
  193. countrySelect: null,
  194. validation: {
  195. company_name: true,
  196. company_tax_no: true,
  197. company_address1: true,
  198. company_address2: true,
  199. company_city: true,
  200. company_state: true,
  201. company_country: true,
  202. company_zipcode: true,
  203. },
  204. errors: null,
  205. rules: {
  206. require: (value) => !!value || this.$t("Required."),
  207. email: (v) =>
  208. /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(
  209. v
  210. ) || this.$t("Invalid email"),
  211. checkPassword: (v) =>
  212. (/(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(v) &&
  213. v.length >= 8 &&
  214. v.length <= 20) ||
  215. this.$t(
  216. "Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter"
  217. ),
  218. },
  219. valid: false,
  220. };
  221. },
  222. methods: {
  223. patchUserData() {
  224. // if (!this.countrySelect && typeof this.countrySelect === "object") {
  225. // } else {
  226. // this.userCompanyCopy.company_country = this.countrySelect;
  227. // }
  228. this.$axios
  229. .post(
  230. `/member/company?jwt=${this.$auth.$storage.getUniversal("jwt").token || ""
  231. }`,
  232. this.userCompanyCopy
  233. )
  234. .then((result) => {
  235. this.userCompanyCopy = {};
  236. // this.countrySelect = null;
  237. this.$emit("refetch-user");
  238. this.$emit("close-edit-dialog");
  239. })
  240. .catch((err) => {
  241. console.log(err);
  242. });
  243. },
  244. // resetUserData() {
  245. // this.userCompanyInfo = {};
  246. // this.countrySelect = null;
  247. // },
  248. // closeDialog() {
  249. // this.userCompanyInfo = {};
  250. // this.countrySelect = null;
  251. // this.$emit("close-edit-dialog");
  252. // },
  253. validators() {
  254. if (is.empty(this.userCompany.company_name)) {
  255. this.validation.company_name = false;
  256. } else {
  257. this.validation.company_name = true;
  258. }
  259. if (is.empty(this.userCompany.company_tax_no)) {
  260. this.validation.company_tax_no = false;
  261. } else {
  262. this.validation.company_tax_no = true;
  263. }
  264. if (is.empty(this.userCompany.company_address1)) {
  265. this.validation.company_address1 = false;
  266. } else {
  267. this.validation.company_address1 = true;
  268. }
  269. if (is.empty(this.userCompany.company_city)) {
  270. this.validation.company_city = false;
  271. } else {
  272. this.validation.company_city = true;
  273. }
  274. if (this.userCompany.company_country == 0) {
  275. this.validation.company_country = false;
  276. } else {
  277. this.validation.company_country = true;
  278. }
  279. if (is.empty(this.userCompany.company_zipcode)) {
  280. this.validation.company_zipcode = false;
  281. } else {
  282. this.validation.company_zipcode = true;
  283. }
  284. this.errors = Object.entries(this.validation).filter(
  285. (e) => e[1] == false
  286. );
  287. if (this.errors.length > 0) {
  288. return false;
  289. } else {
  290. return true;
  291. }
  292. },
  293. save() {
  294. this.validators();
  295. if (this.validators()) {
  296. const patchData = JSON.parse(JSON.stringify(this.userCompany));
  297. this.$axios
  298. .post(
  299. `/member/company?jwt=${this.$auth.$storage.getUniversal("jwt").token
  300. }`,
  301. patchData
  302. )
  303. .then((result) => {
  304. if ((result.status = 200)) {
  305. this.$emit("refetch-user");
  306. // this.$emit("update", true);
  307. this.$modal.hide("edit-company-modal");
  308. }
  309. })
  310. .catch((err) => {
  311. console.log(err);
  312. });
  313. }
  314. },
  315. reset() {
  316. this.userCompany = {
  317. company_name: "",
  318. company_tax_no: "",
  319. company_address1: "",
  320. company_address2: "",
  321. company_city: "",
  322. company_state: "",
  323. company_country: 0,
  324. company_zipcode: "",
  325. };
  326. },
  327. },
  328. watch: {
  329. companyEditInfoDialogActive: {
  330. handler: function () {
  331. this.userCompanyCopy = { ...this.userCompany };
  332. const country = this.userCompany.company_country || null;
  333. this.countrySelect =
  334. this.countryOptions.filter((item) => item.id === country)[0].id ||
  335. null;
  336. },
  337. },
  338. },
  339. };
  340. </script>
  341. <style scoped lang="scss">
  342. .close {
  343. // position: absolute;
  344. right: 30px;
  345. top: 32px;
  346. background-image: url("~/assets/svg/close.svg");
  347. background-position: center;
  348. background-repeat: no-repeat;
  349. background-size: cover;
  350. width: 14px;
  351. height: 14px;
  352. @media screen and (min-width: 768px) {
  353. right: 40px;
  354. top: 40px;
  355. }
  356. }
  357. .v--modal-overlay::v-deep {
  358. .v--modal {
  359. width: 100% !important;
  360. height: 100vh !important;
  361. @media screen and (min-width: 768px) {
  362. padding: 40px;
  363. width: max-content;
  364. height: max-content !important;
  365. border-radius: 30px;
  366. }
  367. }
  368. .v--modal-box {
  369. height: 100vh !important;
  370. overflow: auto;
  371. @media screen and (min-width: 768px) {
  372. padding: 40px;
  373. width: max-content;
  374. height: max-content !important;
  375. }
  376. }
  377. // :deep() {
  378. // .v-dialog {
  379. // border-radius: 30px !important;
  380. // }
  381. // .v-text-field--outlined fieldset {
  382. // border-color: #e5e5e5;
  383. // }
  384. // .v-select {
  385. // border-color: #e5e5e5;
  386. // }
  387. // }
  388. // .input-wrap {
  389. // @media screen and (max-width: 600px) {
  390. // width: 88%;
  391. // }
  392. // @media screen and (min-width: 600px) and (max-width: 960px) {
  393. // width: 45%;
  394. // }
  395. // @media screen and (min-width: 961px) {
  396. // width: 45%;
  397. // }
  398. // }
  399. }
  400. </style>