From 6ca289deb0498c0a44ecf3530ac1aaa84b27ce2d Mon Sep 17 00:00:00 2001 From: Diyar Akhgar Date: Sun, 8 Jun 2025 02:59:17 +0330 Subject: [PATCH] fix team page // fix meeting page API --- .../src/components/BuySubscription.vue | 146 ++--- .../src/components/CreateMeetingModal.vue | 437 ++++++++++---- xroom-dashboard/src/components/Membership.vue | 189 +++--- .../src/components/RoomSelectionModal.vue | 152 ++--- .../src/components/SidebarMenu.vue | 38 +- .../src/components/TeamDetails.vue | 145 ++--- xroom-dashboard/src/components/TeamUser.vue | 134 +++-- .../src/pages/dashboard/Meeting.vue | 99 +--- xroom-dashboard/src/pages/dashboard/team.vue | 543 +++++------------- 9 files changed, 846 insertions(+), 1037 deletions(-) diff --git a/xroom-dashboard/src/components/BuySubscription.vue b/xroom-dashboard/src/components/BuySubscription.vue index c80e7d9..39d1cd0 100644 --- a/xroom-dashboard/src/components/BuySubscription.vue +++ b/xroom-dashboard/src/components/BuySubscription.vue @@ -1,66 +1,40 @@ @@ -94,18 +64,11 @@ import axios from 'axios'; export default { name: 'BuySubscription', props: { - memberCount: { - type: Number, - default: 5, - }, - availableMemberOptions: { - type: Array, - default: () => [5, 10, 20, 100], - }, - baseUrl: { - type: String, - required: true, - }, + memberCount: { type: Number, default: 5 }, + availableMemberOptions: { type: Array, default: () => [5, 10, 20, 100] }, + baseUrl: { type: String, required: true }, + hasActiveSubscription: { type: Boolean, default: false }, + hasExpiredSubscription: { type: Boolean, default: false }, // جدید }, data() { return { @@ -121,67 +84,60 @@ export default { updateMemberCount(event) { const newCount = Number(event.target.value); this.$emit('update:memberCount', newCount); - if (this.selectedPlan) { - this.selectPlan( - this.selectedPlan.name === 'هفتگی' ? 'weekly' : this.selectedPlan.name === 'ماهانه' ? 'monthly' : 'yearly' - ); - } + if (this.selectedPlan) this.selectPlan(this.selectedPlan.name.toLowerCase()); }, selectPlan(planKey) { const plan = this.plans[planKey]; if (!plan) return; - const base = plan.price * this.memberCount; const tax = Math.round(base * 0.09); - - this.selectedPlan = { - ...plan, - basePrice: base, - tax, - total: base + tax, - }; - this.$emit('plan-selected', this.selectedPlan); + this.selectedPlan = { ...plan, basePrice: base, tax, total: base + tax }; }, async pay() { - if (!this.selectedPlan) { - alert('لطفاً ابتدا یک طرح اشتراک انتخاب کنید.'); + if (this.hasActiveSubscription) { + alert('شما اشتراک فعالی دارید و نمی‌توانید اشتراک دیگری خریداری کنید.'); + return; + } + if (this.hasExpiredSubscription) { + alert('شما یکبار اشتراک تهیه کردید و نمی‌توانید دوباره اشتراک تهیه کنید.'); + return; + } + if (!this.selectedPlan) { + alert('لطفاً یک طرح اشتراک انتخاب کنید.'); return; } - try { const startTime = new Date().toISOString(); - let endTime; - if (this.selectedPlan.name === 'هفتگی') { - endTime = new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000).toISOString(); - } else if (this.selectedPlan.name === 'ماهانه') { - endTime = new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000).toISOString(); - } else if (this.selectedPlan.name === 'سالانه') { - endTime = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000).toISOString(); - } - + const endTime = this.calculateEndTime(this.selectedPlan.name); const subscriptionData = { user_count: this.memberCount, license_number: `ABC-${Math.random().toString(36).substr(2, 6).toUpperCase()}-XYZ`, - startTime: startTime, - endTime: endTime, + startTime, + endTime, price: this.selectedPlan.total, }; - const token = localStorage.getItem('token'); - await axios.post(`${this.baseUrl}/add_subscription/`, subscriptionData, { - headers: { - Authorization: `Token ${token}`, - 'Content-Type': 'application/json', - }, + if (!token) throw new Error('توکن احراز هویت یافت نشد.'); + const response = await axios.post(`${this.baseUrl}/add_subscription/`, subscriptionData, { + headers: { Authorization: `Token ${token}`, 'Content-Type': 'application/json' }, }); - - alert(`پرداخت با موفقیت انجام شد برای ${this.memberCount} کاربر`); + this.$emit('payment-success', { subscriptionId: response.data.subscription_id }); this.selectedPlan = null; - this.$emit('payment-success'); } catch (error) { + console.error('Error registering subscription:', error); alert('خطا در ثبت اشتراک. لطفاً دوباره تلاش کنید.'); } }, + calculateEndTime(planName) { + const now = new Date(); + if (planName === 'هفتگی') { + return new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000).toISOString(); + } else if (planName === 'ماهانه') { + return new Date(now.getTime() + 30 * 24 * 60 * 60 * 1000).toISOString(); + } else { + return new Date(now.getTime() + 365 * 24 * 60 * 60 * 1000).toISOString(); + } + }, }, }; diff --git a/xroom-dashboard/src/components/CreateMeetingModal.vue b/xroom-dashboard/src/components/CreateMeetingModal.vue index 342bdbc..eec79fe 100644 --- a/xroom-dashboard/src/components/CreateMeetingModal.vue +++ b/xroom-dashboard/src/components/CreateMeetingModal.vue @@ -1,9 +1,9 @@