diff --git a/src/router/modules/admin.js b/src/router/modules/admin.js index 3674ff2e9..646adfe59 100644 --- a/src/router/modules/admin.js +++ b/src/router/modules/admin.js @@ -13,7 +13,6 @@ import CreateFromTemplate from '@/views/admin/CreateFromTemplateView.vue' import FinalReportView from '@/views/admin/FinalReportView' import Profile from '@/views/admin/ProfileView.vue' import Notification from '@/views/admin/NotificationPage.vue' -import EditProfile from '@/views/admin/EditProfile.vue' export default [ { @@ -28,12 +27,6 @@ export default [ meta: { authorize: [1] }, component:Profile, }, - { - path: '/editprofile', - name: 'EditProfile', - meta: { authorize: [1] }, - component: EditProfile, - }, { path: '/notifications', name: 'notifications', diff --git a/src/views/admin/EditProfile.vue b/src/views/admin/EditProfile.vue deleted file mode 100644 index 5af6d14ce..000000000 --- a/src/views/admin/EditProfile.vue +++ /dev/null @@ -1,174 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/views/admin/ProfileView.vue b/src/views/admin/ProfileView.vue index 1e3237b9a..ade27255b 100644 --- a/src/views/admin/ProfileView.vue +++ b/src/views/admin/ProfileView.vue @@ -1,13 +1,14 @@ @@ -132,6 +163,7 @@ import { getAuth, reauthenticateWithCredential, EmailAuthProvider, + updatePassword, } from 'firebase/auth' import { getFirestore, @@ -141,7 +173,8 @@ import { getDocs, doc, deleteDoc, - getDoc + getDoc, + updateDoc } from 'firebase/firestore' export default { @@ -155,9 +188,13 @@ export default { contactNo: null, country: null }, + editProfileData: { + username: null, + contactNo: null, + country: null + }, displayMissingInfo: 'INFO MISSING', - loading:true, - showDeleteModal: false, + loading: true, valid: false, newPassword: '', confirmPassword: '', @@ -170,14 +207,23 @@ export default { confirmPasswordRules: [ v => !!v || 'Confirm password is required', v => v === this.newPassword || 'Passwords must match' - ] + ], + editProfileDialog: false, + deleteAccountDialog: false, + isSmallScreen: false } }, async created() { await this.fetchUserProfile() + this.checkScreenSize() + window.addEventListener('resize', this.checkScreenSize) }, - + + beforeDestroy() { + window.removeEventListener('resize', this.checkScreenSize) + }, + computed: { user() { return this.$store.getters.user || { email: '' } @@ -185,6 +231,10 @@ export default { }, methods: { + checkScreenSize() { + this.isSmallScreen = window.innerWidth < 960 // Adjust breakpoint as needed + }, + async fetchUserProfile() { try { const auth = getAuth() @@ -207,8 +257,45 @@ export default { } catch (error) { console.error('Error fetching profile:', error) this.$toast.error('Failed to load profile data') - }finally{ - this.loading = false; + } finally { + this.loading = false + } + }, + + openEditProfileDialog() { + this.editProfileData = { + username: this.userprofile.username, + contactNo: this.userprofile.contactNo, + country: this.userprofile.country + } + this.editProfileDialog = true + }, + + async saveProfile() { + try { + const auth = getAuth() + const user = auth.currentUser + + if (user) { + const db = getFirestore() + const userDocRef = doc(db, 'users', user.uid) + await updateDoc(userDocRef, { + username: this.editProfileData.username, + contactNo: this.editProfileData.contactNo, + country: this.editProfileData.country + }) + this.userprofile = { + ...this.userprofile, + username: this.editProfileData.username, + contactNo: this.editProfileData.contactNo, + country: this.editProfileData.country + } + this.$toast.success('Profile updated successfully') + this.editProfileDialog = false + } + } catch (error) { + console.error('Error updating profile:', error) + this.$toast.error('Failed to update profile') } }, @@ -222,7 +309,6 @@ export default { await updatePassword(user, this.newPassword) this.$toast.success('Password changed successfully') - // Reset form this.newPassword = '' this.confirmPassword = '' this.$refs.passwordForm.reset() @@ -294,14 +380,6 @@ export default { .catch((error) => {console.log(error)}) }) }, - - editProfile() { - this.$router.push('/editprofile'); - console.log("Edit profile clicked"); - }, - suspendAccount() { - console.log("Suspend account clicked"); - }, }, } @@ -320,7 +398,12 @@ export default { background-color: #f8f9fe !important; border-radius: 8px !important; height: 100%; - margin-left: -120px !important; +} + +.password-card { + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); + border-radius: 10px; + padding: 20px; } .v-btn { @@ -329,39 +412,12 @@ export default { letter-spacing: 0 !important; } -.v-text-field ::v-deep(.class-name) .v-input__slot, +.v-text-field ::v-deep(.v-input__slot), .v-select ::v-deep .v-input__slot { min-height: 40px !important; box-shadow: none !important; } -.form-section label { - color: #666 !important; -} - -/* Adjustments for the layout */ -.profile-card { - width: 100%; - margin-bottom: 2rem; - height: 100vh; /* Ensures the profile card covers the full screen height */ -} - -.v-tabs { - margin-bottom: 2rem; -} - -.v-tab { - text-transform: none !important; - letter-spacing: 0 !important; -} - -.v-card { - border-radius: 20px !important; - margin-left: -200px; - -} - - .v-list-item { min-height: 40px !important; } @@ -370,42 +426,19 @@ export default { color: #666 !important; } -.v-btn.edit-button { - background-color: #007bff; - color: white !important; - border-radius: 8px; - font-weight: 500; - padding: 8px 16px; - letter-spacing: 0.5px; - box-shadow: 0 4px 6px rgba(0, 123, 255, 0.3); - transition: background-color 0.3s ease, box-shadow 0.3s ease; +.missing-info { + color: #ff5252 !important; + font-style: italic; } -.v-btn.edit-button:hover { - background-color: #0056b3; - box-shadow: 0 6px 10px rgba(0, 123, 255, 0.5); -} +@media (max-width: 960px) { + .container { + flex-direction: column; + } -.v-btn.suspend-button { - background-color: #dc3545; - color: white !important; - border-radius: 8px; - font-weight: 500; - padding: 8px 16px; - letter-spacing: 0.5px; - box-shadow: 0 4px 6px rgba(220, 53, 69, 0.3); - transition: background-color 0.3s ease, box-shadow 0.3s ease; + .profile-card { + max-width: 100%; + min-width: 100%; + } } - -.v-btn.suspend-button:hover { - background-color: #c82333; - box-shadow: 0 6px 10px rgba(220, 53, 69, 0.5); -} - -.password-card { - box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); - border-radius: 10px; - padding: 20px; -} - - + \ No newline at end of file