fix: Defer agent dashboard data fetching until session is authenticated and update payment success redirect to full page reload.
This commit is contained in:
@@ -62,7 +62,7 @@ const defaultContactInfoData: ContactInfoData = {
|
||||
};
|
||||
|
||||
export default function AgentDashboard() {
|
||||
const { data: session } = useSession();
|
||||
const { data: session, status: sessionStatus } = useSession();
|
||||
const [agentProfile, setAgentProfile] = useState<AgentProfile | null>(null);
|
||||
const [fieldValues, setFieldValues] = useState<FieldValueResponse[]>([]);
|
||||
const [experienceData, setExperienceData] = useState<ExperienceData>(defaultExperience);
|
||||
@@ -89,8 +89,13 @@ export default function AgentDashboard() {
|
||||
return !avatar.startsWith('http') && !avatar.startsWith('/');
|
||||
};
|
||||
|
||||
// Fetch agent profile and field values on mount
|
||||
// Fetch agent profile and field values when session is ready
|
||||
useEffect(() => {
|
||||
// Wait until session is authenticated and tokens are available
|
||||
if (sessionStatus !== 'authenticated') return;
|
||||
const token = typeof window !== 'undefined' ? localStorage.getItem('accessToken') : null;
|
||||
if (!token) return;
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
@@ -164,7 +169,7 @@ export default function AgentDashboard() {
|
||||
};
|
||||
|
||||
fetchData();
|
||||
}, []);
|
||||
}, [sessionStatus]);
|
||||
|
||||
// Handle availability toggle
|
||||
const handleToggleAvailability = async () => {
|
||||
|
||||
@@ -139,7 +139,7 @@ export function PaymentSuccessForm() {
|
||||
{/* Action Buttons */}
|
||||
<div className="flex gap-4 mb-6">
|
||||
<button
|
||||
onClick={() => router.push('/agent/dashboard')}
|
||||
onClick={() => window.location.href = '/agent/dashboard'}
|
||||
className="flex-1 bg-[#e58625] border border-[#e58625] text-white font-fractul font-bold text-[14px] py-4 rounded-[15px] hover:bg-[#d47920] transition-colors flex items-center justify-center gap-2"
|
||||
>
|
||||
<Image
|
||||
|
||||
Reference in New Issue
Block a user