refactor(reporting-layout): streamline sidebar and content layout
- Replaced the existing sidebar implementation with a new ReportingSider component that accepts collapse state and toggle function as props. - Simplified the ReportingCollapsedButton component for better readability and functionality. - Updated layout styles to enhance responsiveness and maintain consistent margins. - Removed unused CSS styles related to the sidebar for cleaner code.
This commit is contained in:
49
worklenz-frontend/src/hooks/useSurveyStatus.ts
Normal file
49
worklenz-frontend/src/hooks/useSurveyStatus.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { surveyApiService } from '@/api/survey/survey.api.service';
|
||||
import logger from '@/utils/errorLogger';
|
||||
|
||||
export interface UseSurveyStatusResult {
|
||||
hasCompletedSurvey: boolean | null;
|
||||
loading: boolean;
|
||||
error: Error | null;
|
||||
refetch: () => Promise<void>;
|
||||
}
|
||||
|
||||
export const useSurveyStatus = (): UseSurveyStatusResult => {
|
||||
const [hasCompletedSurvey, setHasCompletedSurvey] = useState<boolean | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
|
||||
const checkSurveyStatus = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
const response = await surveyApiService.checkAccountSetupSurveyStatus();
|
||||
|
||||
if (response.done) {
|
||||
setHasCompletedSurvey(response.body.is_completed);
|
||||
} else {
|
||||
setHasCompletedSurvey(false);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('Failed to check survey status', err);
|
||||
setError(err as Error);
|
||||
// Assume not completed if there's an error
|
||||
setHasCompletedSurvey(false);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
checkSurveyStatus();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
hasCompletedSurvey,
|
||||
loading,
|
||||
error,
|
||||
refetch: checkSurveyStatus
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user