diff --git a/src/components/dashboard/SettingsSection/UserProfileSettings.tsx b/src/components/dashboard/SettingsSection/UserProfileSettings.tsx index 1ad1487..ae9faaa 100644 --- a/src/components/dashboard/SettingsSection/UserProfileSettings.tsx +++ b/src/components/dashboard/SettingsSection/UserProfileSettings.tsx @@ -35,12 +35,6 @@ export default function UserProfileSettings({ // Use environment variables or props (fallback) const logtoApiEndpoint = envLogtoApiEndpoint || propLogtoApiEndpoint; - // Parse the majors list from the text file and sort alphabetically - const majorsList = allMajors - .split('\n') - .filter(major => major.trim() !== '') - .sort((a, b) => a.localeCompare(b)); - useEffect(() => { const loadUserData = async () => { try { @@ -83,6 +77,7 @@ export default function UserProfileSettings({ // Extract username from Logto data or email if not set const defaultUsername = logtoUser.data?.username || currentUser.email?.split('@')[0] || ''; + // Remove all the major matching logic and just use the server value directly setUser(currentUser); setFormData({ name: currentUser.name || '', @@ -334,11 +329,23 @@ export default function UserProfileSettings({ className="select select-bordered w-full" > - {majorsList.map((major, index) => ( - - ))} + {(() => { + const standardMajors = allMajors + .split('\n') + .filter(major => major.trim() !== '') + .sort((a, b) => a.localeCompare(b)); + + if (formData.major && !standardMajors.includes(formData.major)) { + standardMajors.push(formData.major); + standardMajors.sort((a, b) => a.localeCompare(b)); + } + + return standardMajors.map((major, index) => ( + + )); + })()} diff --git a/src/components/dashboard/universal/DashboardWrapper.tsx b/src/components/dashboard/universal/DashboardWrapper.tsx new file mode 100644 index 0000000..f49a550 --- /dev/null +++ b/src/components/dashboard/universal/DashboardWrapper.tsx @@ -0,0 +1,67 @@ +import { useState, useEffect } from "react"; +import type { ReactNode } from "react"; +import { Authentication } from "../../../scripts/pocketbase/Authentication"; +import type { User } from "../../../schemas/pocketbase/schema"; +import FirstTimeLoginPopup from "./FirstTimeLoginPopup"; + +interface DashboardWrapperProps { + children: ReactNode; + logtoApiEndpoint?: string; +} + +const DashboardWrapper = ({ children, logtoApiEndpoint }: DashboardWrapperProps) => { + const [showOnboarding, setShowOnboarding] = useState(false); + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + const checkUserStatus = async () => { + try { + const auth = Authentication.getInstance(); + if (!auth.isAuthenticated()) { + // Not logged in, so don't show onboarding + setIsLoading(false); + return; + } + + const userData = auth.getCurrentUser() as User | null; + + if (userData) { + // If signed_up is explicitly false, show onboarding + setShowOnboarding(userData.signed_up === false); + } + } catch (error) { + console.error("Error checking user status:", error); + } finally { + setIsLoading(false); + } + }; + + checkUserStatus(); + }, []); + + const handleOnboardingComplete = () => { + setShowOnboarding(false); + }; + + if (isLoading) { + return ( +
+ Welcome to IEEE UCSD! Please complete your profile to continue. +
+