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.

412 lines
15 KiB

2 years ago
  1. <template>
  2. <div class="setting xl:tw-max-w-[1246px] xl:tw-mx-auto">
  3. <div class="xl:tw-flex xl:tw-justify-between xl:tw-items-start">
  4. <userSidebar :userData="userData" :firstName="firstName" :lastName="lastName" class="tw-hidden xl:tw-block">
  5. </userSidebar>
  6. <!-- <div class="xl:tw-hidden"></div> -->
  7. <div class="tw-bg-white xl:tw-p-[30px] xl:tw-rounded-[20px] xl:tw-min-w-[900px] xl:tw-max-w-[900px]">
  8. <div class="tw-text-[20px] tw-font-bold tw-text-base-primary tw-mb-[20px] md:t24 md:tw-mb-[30px]">
  9. <two-dots class="tw-mr-[30px]"></two-dots>{{ $t("userProfile.setting") }}
  10. </div>
  11. <div class="tw-mb-[30px] md:tw-max-w-[392px]">
  12. <div class="tw-body-2 tw-font-bold tw-text-base-primary tw-mb-[15px] md:t16">
  13. {{ $t('userProfile.account') }}
  14. </div>
  15. <input type="text"
  16. class="tw-h-[40px] tw-w-full tw-border tw-bg-white tw-border-neutral-200 tw-border-solid tw-px-[20px] tw-py-[10px] tw-rounded-[5px] disabled:tw-text-base-disable"
  17. :value="userData.account" disabled />
  18. </div>
  19. <Transition name="bounce">
  20. <div v-show="SSOShow == 2" :class="['tw-mb-[50px] md:tw-mb-[30px]',SSOShow == 2 ? '':'tw-hidden']">
  21. <div class="tw-body-2 tw-font-medium tw-text-base-primary tw-mb-[15px] md:t16">
  22. {{ $t('userProfile.manageSSO')}}
  23. </div>
  24. <div class="md:tw-flex md:tw-flex-row">
  25. <div
  26. class="tw-w-full tw-border tw-border-solid tw-border-neutral-200 tw-rounded-[10px] tw-grid tw-grid-cols-[auto_71px] tw-items-center tw-gap-[50px] tw-px-[30px] tw-py-[14px] tw-mb-[20px] md:tw-mb-0 md:tw-mr-[20px] md:tw-py-[30px]">
  27. <div class="tw-text-[16px] tw-text-base-primary md:tw-text-[14px]">
  28. Facebook
  29. </div>
  30. <button v-if="facebook.social_schema" @click="openModal('facebook')"
  31. class="tw-bg-warning-background tw-text-warning-default tw-rounded-[12px] tw-px-[16px] tw-py-[9px] tw-whitespace-nowrap">
  32. {{$t('userProfile.SSOUnLink')}}
  33. </button>
  34. <button v-else @click="facebookLogin"
  35. class="tw-bg-warning-default tw-text-white tw-rounded-[12px] tw-px-[16px] tw-py-[9px]">
  36. {{$t('userProfile.SSOLink')}}
  37. </button>
  38. </div>
  39. <div
  40. class="tw-w-full tw-border tw-border-solid tw-border-neutral-200 tw-rounded-[10px] tw-grid tw-grid-cols-[auto_90px] tw-items-center tw-gap-[50px] tw-px-[30px] tw-py-[14px] md:tw-py-[30px]">
  41. <div class="tw-text-[16px] tw-text-base-primary md:tw-text-[14px]">
  42. Google
  43. </div>
  44. <button v-if="google.social_schema" @click.prevent="openModal('google')"
  45. class="tw-bg-warning-background tw-text-warning-default tw-rounded-[12px] tw-px-[16px] tw-py-[9px]">
  46. {{$t('userProfile.SSOUnLink')}}
  47. </button>
  48. <button v-else @click="googleLogin"
  49. class="tw-bg-warning-default tw-text-white tw-rounded-[12px] tw-px-[16px] tw-py-[9px]">
  50. {{$t('userProfile.SSOLink')}}
  51. </button>
  52. </div>
  53. </div>
  54. </div>
  55. </Transition>
  56. <Transition name="bounce">
  57. <div v-show="SSOShow == 1">
  58. <div class="tw-body-2 tw-font-bold tw-text-base-primary tw-mb-[20px] md:t16 md:tw-mb-[15px]">
  59. {{$t('userProfile.resetPassword')}}
  60. </div>
  61. <div class="tw-mb-[20px] md:tw-max-w-[392px] md:tw-mb-[15px]">
  62. <div class="tw-text-[16px] tw-text-base-primary tw-mb-[6px] md:tw-text-[14px]">
  63. {{$t('userProfile.oldPassword')}}
  64. </div>
  65. <input v-model="userPass.user_old_pass" type="password"
  66. class="tw-h-[40px] tw-w-full tw-border tw-border-neutral-200 tw-border-solid tw-px-[20px] tw-py-[10px] tw-rounded-[5px]" />
  67. </div>
  68. <div class="tw-mb-[20px] md:tw-max-w-[392px] md:tw-mb-[15px]">
  69. <!-- <div
  70. class="tw-text-[16px] tw-text-base-primary tw-mb-[6px] md:tw-text-[14px]"
  71. >
  72. New password
  73. </div>
  74. <input
  75. type="text"
  76. class="tw-h-[40px] tw-w-full tw-border tw-border-neutral-200 tw-border-solid tw-px-[20px] tw-py-[10px] tw-rounded-[5px] tw-mb-[6px]"
  77. /> -->
  78. <div>
  79. <div class="tw-text-[16px] tw-text-base-primary tw-mb-[6px] md:tw-text-[14px]">
  80. {{$t('userProfile.newPassword')}}
  81. </div>
  82. <v-text-field v-model="userPass.user_new_pass" :append-icon="showPass ? 'mdi-eye' : 'mdi-eye-off'"
  83. @click:append="showPass = !showPass" @blur="checkPassword($event)"
  84. :type="showPass ? 'text' : 'password'" :rules="[rules.checkPassword, rules.require]" hide-details
  85. dense outlined validate-on-blur></v-text-field>
  86. </div>
  87. <div v-show="!isNewPassValid" class="tw-footer-body tw-w-full tw-leading-none tw-pt-1" :class="
  88. isNewPassValid
  89. ? 'tw-text-neutrals-400'
  90. : 'tw-text-error-default'
  91. ">
  92. {{ $t('userProfile.passwordsHint') }}
  93. </div>
  94. </div>
  95. <div class="tw-mb-[20px] md:tw-max-w-[392px] md:tw-mb-[15px]">
  96. <div>
  97. <div class="tw-text-[16px] tw-text-base-primary tw-mb-[6px] md:tw-text-[14px]">
  98. {{$t('userProfile.confirmPassword')}}
  99. </div>
  100. <v-text-field v-model="confirmPass" :append-icon="showConfirmPass ? 'mdi-eye' : 'mdi-eye-off'"
  101. @click:append="showConfirmPass = !showConfirmPass" :type="showConfirmPass ? 'text' : 'password'"
  102. :rules="[rules.checkConfirmPassword, rules.require]" dense outlined validate-on-blur></v-text-field>
  103. </div>
  104. <!-- <div
  105. class="tw-text-[16px] tw-text-base-primary tw-mb-[6px] md:tw-text-[14px]"
  106. >
  107. Confirm password
  108. </div>
  109. <input
  110. type="text"
  111. class="tw-h-[40px] tw-w-full tw-border tw-border-neutral-200 tw-border-solid tw-px-[20px] tw-py-[10px] tw-rounded-[5px] tw-mb-[6px]"
  112. />
  113. <img
  114. src="~/assets/svg/hidepassword.svg"
  115. class="tw-absolute tw-top-[717px] tw-right-[20px] md:tw-top-[621px] md:tw-left-[359px] xl:tw-left-[777px] xl:tw-top-[650px]"
  116. alt=""
  117. /> -->
  118. </div>
  119. </div>
  120. </Transition>
  121. <Transition name="bounce">
  122. <div v-show="SSOShow == 1"
  123. :lass="['tw-mb-[64px] md:tw-flex md:tw-flex-row md:tw-items-center md:tw-mb-[40px]']">
  124. <button @click="resetPassword"
  125. class="tw-text-white tw-bg-primary-1 tw-text-[18px] tw-rounded-[16px] tw-w-full tw-py-[13px] tw-mb-[15px] md:tw-text-[16px] md:tw-w-fit md:tw-px-[16px] md:tw-py-[10px] md:tw-mr-[20px] md:tw-mb-0">
  126. {{$t('userProfile.resetPassword')}}
  127. </button>
  128. <button
  129. class="tw-text-primary-1 tw-bg-white tw-text-[18px] tw-rounded-[16px] tw-w-full tw-py-[13px] md:tw-text-[16px] md:tw-w-fit md:tw-px-[16px] md:tw-py-[10px]">
  130. {{$t('userProfile.cancel')}}
  131. </button>
  132. </div>
  133. </Transition>
  134. <button @click="openDeleteModal()"
  135. class="tw-text-error-default tw-text-[16px] tw-underline tw-mt-[44px] md:tw-mt-[99px] xl:tw-mt-[39px]">
  136. {{$t('userProfile.deleteAccount')}}
  137. </button>
  138. </div>
  139. </div>
  140. <Transition name="bounce">
  141. <unLinkModal></unLinkModal>
  142. </Transition>
  143. <Transition name="bounce">
  144. <deleteAccountModal></deleteAccountModal>
  145. </Transition>
  146. </div>
  147. </template>
  148. <script>
  149. import SavedExhibitions from "../../components/user/savedExhibitions.vue";
  150. import SavedExhibitionsDialog from "../../components/user/savedExhibitionsDialog.vue";
  151. import Setting from "../../components/user/Setting.vue";
  152. import SettingDialog from "../../components/user/settingDialog.vue";
  153. import CropImageDialog from "../../components/user/cropImageDialog.vue";
  154. import CompanyInfo from "../../components/user/companyInfo.vue";
  155. import CompanyInfoDialog from "../../components/user/companyInfoDialog.vue";
  156. import ContactInfo from "../../components/user/contactInfo.vue";
  157. import vClickOutside from "v-click-outside";
  158. import BookingList from "../../components/user/bookingList.vue";
  159. import TwoDots from "@/components/TwoDots";
  160. import userSidebar from "@/components/user/userSidebar.vue";
  161. import unLinkModal from "@/components/newComponent/modal/unLinkModal.vue";
  162. import deleteAccountModal from "@/components/newComponent/modal/deleteAccountModal.vue";
  163. export default {
  164. name: "setting",
  165. layout: "profile",
  166. directives: {
  167. clickOutside: vClickOutside.directive,
  168. },
  169. components: {
  170. SavedExhibitions,
  171. SavedExhibitionsDialog,
  172. Setting,
  173. SettingDialog,
  174. CropImageDialog,
  175. CompanyInfo,
  176. CompanyInfoDialog,
  177. ContactInfo,
  178. BookingList,
  179. TwoDots,
  180. userSidebar,
  181. unLinkModal,
  182. deleteAccountModal,
  183. },
  184. data() {
  185. return {
  186. google: {},
  187. facebook: {},
  188. deleteDialogActive: false,
  189. valid: false,
  190. showPass: false,
  191. showConfirmPass: false,
  192. userPass: {
  193. user_old_pass: "",
  194. user_new_pass: "",
  195. },
  196. isNewPassValid: true,
  197. firstName: "",
  198. lastName: "",
  199. userData: {},
  200. SSOShow: 0,
  201. confirmPass: "",
  202. deleteAccountImg: require("~/assets/img/deleteAccount.png"),
  203. rules: {
  204. require: (value) => !!value || this.$t("Required."),
  205. email: (v) =>
  206. /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(
  207. v
  208. ) || this.$t("Invalid email"),
  209. checkPassword: (v) =>
  210. (/(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(v) &&
  211. v.length >= 8 &&
  212. v.length <= 20) ||
  213. this.$t(
  214. "Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter"
  215. ),
  216. checkConfirmPassword: (v) =>
  217. this.confirmPass === this.userPass.user_new_pass ||
  218. this.$t("Your password and confirmation password do not match"),
  219. },
  220. };
  221. },
  222. created() {
  223. //this.fetchUserData();
  224. if (process.browser) {
  225. window.addEventListener("resize", this.handleResize);
  226. }
  227. //this.handleResize();
  228. },
  229. mounted() {
  230. this.$nextTick(() => {
  231. window.addEventListener("resize", this.onResize);
  232. });
  233. },
  234. destroyed() {
  235. if (process.browser) {
  236. window.removeEventListener("resize", this.handleResize);
  237. }
  238. },
  239. computed: {
  240. windowWidth() {
  241. if (process.client) {
  242. this.width = window.innerWidth;
  243. }
  244. return this.width;
  245. },
  246. },
  247. methods: {
  248. handleResize() {
  249. if (process.browser) {
  250. this.width = window.innerWidth;
  251. }
  252. },
  253. fetchUserData() {
  254. this.$axios
  255. .get(
  256. `/member/users/${this.$auth.$storage.getUniversal("jwt").user_id
  257. }?jwt=${this.$auth.$storage.getUniversal("jwt").token}`
  258. )
  259. .then((res) => {
  260. this.userData = res.data;
  261. this.firstName = res.data.first_name;
  262. this.lastName = res.data.last_name;
  263. this.facebook =
  264. res.data.UserSocialRelation.filter(
  265. (item) => item.social_schema === "facebook"
  266. )[0] || {};
  267. this.google =
  268. res.data.UserSocialRelation.filter(
  269. (item) => item.social_schema === "google"
  270. )[0] || {};
  271. this.checkSSO();
  272. })
  273. .catch((err) => {
  274. console.log(err);
  275. });
  276. },
  277. removeSocialRelation(schema) {
  278. delete schema.social_id;
  279. this.$axios
  280. .put(
  281. `/member/users/social?jwt=${this.$auth.$storage.getUniversal("jwt").token || ""
  282. }`,
  283. schema
  284. )
  285. .then((result) => {
  286. this.$emit("refetch-user");
  287. })
  288. .catch((err) => {
  289. console.log(err);
  290. });
  291. this.$nextTick(() => {
  292. schema.social_schema === "google"
  293. ? (this.google = {})
  294. : (this.facebook = {});
  295. });
  296. },
  297. facebookLogin() {
  298. this.$auth.loginWith("facebook");
  299. },
  300. googleLogin() {
  301. this.$auth.loginWith("google");
  302. },
  303. resetPassword() {
  304. if (
  305. this.isNewPassValid &&
  306. this.userPass.user_old_pass !== this.userPass.user_new_pass
  307. ) {
  308. this.$axios
  309. .post(
  310. `/member/users/pass?jwt=${this.$auth.$storage.getUniversal("jwt").token || ""
  311. }`,
  312. this.userPass
  313. )
  314. .then((result) => {
  315. this.$auth.$storage.removeUniversal("jwt");
  316. this.$auth.$storage.removeUniversal("userPicture");
  317. this.$auth.$storage.removeUniversal("userLastName");
  318. this.$notify({
  319. type: "success",
  320. title: "Awesome!",
  321. text: "Your password has been updated successfully.",
  322. });
  323. setTimeout(() => {
  324. this.$auth.logout();
  325. this.$router.push(this.localePath("/user"));
  326. }, 4000)
  327. })
  328. .catch((err) => {
  329. console.log(err);
  330. });
  331. }
  332. },
  333. checkPassword(v) {
  334. const pass = v.target.value;
  335. this.isNewPassValid =
  336. /(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(pass) &&
  337. pass.length >= 8 &&
  338. pass.length <= 20;
  339. },
  340. checkSSO() {
  341. if (Object.keys(this.facebook).length == 0 && Object.keys(this.google).length == 0) {
  342. this.SSOShow = 1;
  343. } else {
  344. this.SSOShow = 2;
  345. }
  346. },
  347. openModal(type) {
  348. if (type == 'google') {
  349. if (Object.keys(this.facebook).length == 0) {
  350. this.$modal.show('unLinkModal');
  351. } else {
  352. this.removeSocialRelation(this.google);
  353. }
  354. }
  355. if (type == 'facebook') {
  356. if (Object.keys(this.google).length == 0) {
  357. this.$modal.show('unLinkModal');
  358. } else {
  359. this.removeSocialRelation(this.facebook);
  360. }
  361. }
  362. },
  363. openDeleteModal() {
  364. this.$modal.show('deleteAccountModal');
  365. }
  366. },
  367. };
  368. </script>
  369. <style scoped lang="scss">
  370. :deep(.v-text-field.v-text-field--enclosed .v-text-field__details) {
  371. padding: 0;
  372. margin: 0;
  373. }
  374. :deep(.v-messages__message) {
  375. font-size: 14px;
  376. }
  377. .v-text-field--outlined::v-deep {
  378. fieldset {
  379. border-color: #e5e5e5;
  380. }
  381. }
  382. .bounce-enter-active {
  383. animation: bounce-in 0.3s ease-out;
  384. }
  385. .bounce-leave-active {
  386. animation: bounce-in 0.3s cubic-bezier(1, 0.5, 0.8, 1) reverse;
  387. }
  388. @keyframes bounce-in {
  389. 0% {
  390. opacity: 0;
  391. transform: translateY(-10px);
  392. }
  393. 50% {
  394. opacity: 0.5;
  395. transform: translateY(-5px);
  396. }
  397. 100% {
  398. opacity: 1;
  399. transform: translateY(0);
  400. }
  401. }
  402. </style>