All files / src/components ProfileRouter.vue

0% Statements 0/118
0% Branches 0/1
0% Functions 0/1
0% Lines 0/118

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
<template>
  <div class="profile-router">
    <div v-if="authStore.state.loading" class="loading-state">
      <div class="loading-spinner"></div>
      <p>Loading your profile...</p>
    </div>
 
    <div v-else-if="!authStore.isAuthenticated" class="not-authenticated">
      <h3>Authentication Required</h3>
      <p>Please log in to view your profile.</p>
    </div>
 
    <div v-else-if="!authStore.state.profile" class="no-profile">
      <h3>Profile Not Found</h3>
      <p>Unable to load your profile. Please try refreshing the page.</p>
      <button @click="refreshProfile" class="refresh-btn">
        Refresh Profile
      </button>
    </div>
 
    <div v-else class="profile-content">
      <!-- Admin Profile -->
      <AdminProfile v-if="userRole === 'admin'" @logout="handleLogout" />
 
      <!-- Club Manager Profile -->
      <ClubManagerProfile
        v-else-if="userRole === 'club_manager'"
        @logout="handleLogout"
        @switch-tab="handleSwitchTab"
      />
 
      <!-- Team Manager Profile -->
      <TeamManagerProfile
        v-else-if="userRole === 'team-manager'"
        @logout="handleLogout"
      />
 
      <!-- Player Profile -->
      <PlayerProfile
        v-else-if="userRole === 'team-player'"
        @logout="handleLogout"
      />
 
      <!-- Fan Profile (default) -->
      <FanProfile v-else @logout="handleLogout" @navigate="handleSwitchTab" />
    </div>
 
    <!-- Role Debug Info (only in development) -->
    <div v-if="showDebug" class="debug-info">
      <h4>Debug Information</h4>
      <div class="debug-details">
        <p><strong>User Role:</strong> {{ userRole }}</p>
        <p>
          <strong>Is Authenticated:</strong> {{ authStore.isAuthenticated }}
        </p>
        <p><strong>Profile Loaded:</strong> {{ !!authStore.state.profile }}</p>
        <p><strong>User ID:</strong> {{ authStore.state.user?.id }}</p>
        <p><strong>Email:</strong> {{ authStore.state.user?.email }}</p>
      </div>
      <button @click="showDebug = false" class="close-debug">
        Close Debug
      </button>
    </div>
 
    <!-- Debug Toggle (only in development) -->
    <button
      v-if="isDevelopment && !showDebug"
      @click="showDebug = true"
      class="debug-toggle"
    >
      🐛 Debug
    </button>
  </div>
</template>
 
<script>
import { ref, computed, onMounted } from 'vue';
import { useAuthStore } from '@/stores/auth';
import AdminProfile from './profiles/AdminProfile.vue';
import ClubManagerProfile from './profiles/ClubManagerProfile.vue';
import TeamManagerProfile from './profiles/TeamManagerProfile.vue';
import PlayerProfile from './profiles/PlayerProfile.vue';
import FanProfile from './profiles/FanProfile.vue';
 
export default {
  name: 'ProfileRouter',
  components: {
    AdminProfile,
    ClubManagerProfile,
    TeamManagerProfile,
    PlayerProfile,
    FanProfile,
  },
  emits: ['logout', 'switch-tab'],
  setup(props, { emit }) {
    const authStore = useAuthStore();
    const showDebug = ref(false);
 
    const userRole = computed(() => {
      return authStore.state.profile?.role || 'team-fan';
    });
 
    const isDevelopment = computed(() => {
      return process.env.NODE_ENV === 'development';
    });
 
    const refreshProfile = async () => {
      try {
        await authStore.fetchProfile();
      } catch (error) {
        console.error('Error refreshing profile:', error);
        authStore.setError('Failed to refresh profile');
      }
    };
 
    const handleLogout = () => {
      emit('logout');
    };
 
    const handleSwitchTab = (tabId, filters = null) => {
      emit('switch-tab', tabId, filters);
    };
 
    onMounted(() => {
      // Ensure profile is loaded when component mounts
      if (authStore.isAuthenticated && !authStore.state.profile) {
        refreshProfile();
      }
    });
 
    return {
      authStore,
      userRole,
      isDevelopment,
      showDebug,
      refreshProfile,
      handleLogout,
      handleSwitchTab,
    };
  },
};
</script>
 
<style scoped>
.profile-router {
  min-height: 100vh;
  position: relative;
}
 
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}
 
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top: 4px solid #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}
 
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
 
.loading-state p {
  color: #6b7280;
  font-size: 16px;
  margin: 0;
}
 
.not-authenticated,
.no-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  background-color: #f9fafb;
  border-radius: 8px;
  margin: 20px;
  border: 1px solid #e5e7eb;
}
 
.not-authenticated h3,
.no-profile h3 {
  color: #1f2937;
  margin-bottom: 15px;
  font-size: 24px;
}
 
.not-authenticated p,
.no-profile p {
  color: #6b7280;
  margin-bottom: 20px;
  font-size: 16px;
}
 
.refresh-btn {
  background-color: #3b82f6;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.2s ease;
}
 
.refresh-btn:hover {
  background-color: #2563eb;
}
 
.profile-content {
  min-height: 100vh;
}
 
/* Debug Information Styles */
.debug-info {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: white;
  border: 2px solid #f59e0b;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  max-width: 300px;
  z-index: 1000;
}
 
.debug-info h4 {
  color: #f59e0b;
  margin: 0 0 15px 0;
  font-size: 16px;
  border-bottom: 1px solid #fde68a;
  padding-bottom: 8px;
}
 
.debug-details p {
  margin: 8px 0;
  font-size: 12px;
  color: #374151;
  word-break: break-all;
}
 
.debug-details strong {
  color: #1f2937;
}
 
.close-debug {
  background-color: #f59e0b;
  color: white;
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  margin-top: 10px;
  width: 100%;
}
 
.close-debug:hover {
  background-color: #d97706;
}
 
.debug-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background-color: #f59e0b;
  color: white;
  padding: 10px 15px;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 999;
  transition: all 0.2s ease;
}
 
.debug-toggle:hover {
  background-color: #d97706;
  transform: scale(1.05);
}
 
/* Responsive Design */
@media (max-width: 768px) {
  .debug-info {
    bottom: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
 
  .debug-toggle {
    bottom: 10px;
    right: 10px;
    padding: 8px 12px;
    font-size: 12px;
  }
 
  .loading-state,
  .not-authenticated,
  .no-profile {
    padding: 40px 15px;
  }
 
  .not-authenticated h3,
  .no-profile h3 {
    font-size: 20px;
  }
 
  .not-authenticated p,
  .no-profile p {
    font-size: 14px;
  }
}
 
/* Dark mode support (if needed in the future) */
@media (prefers-color-scheme: dark) {
  .debug-info {
    background: #1f2937;
    border-color: #f59e0b;
    color: #f3f4f6;
  }
 
  .debug-details strong {
    color: #e5e7eb;
  }
 
  .not-authenticated,
  .no-profile {
    background-color: #1f2937;
    border-color: #374151;
  }
 
  .not-authenticated h3,
  .no-profile h3 {
    color: #f3f4f6;
  }
 
  .not-authenticated p,
  .no-profile p {
    color: #9ca3af;
  }
}
</style>