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 | 24x 24x 24x 12x 12x 24x 12x 12x 12x 12x 12x 12x 12x 12x 12x 24x | import { useEffect, useMemo, useState } from "react";
import { ComplianceServiceAdapter } from "../services/ComplianceServiceAdapter";
import { createEmptyCIADetails } from "../utils/serviceUtils";
/**
* Hook to access compliance service functionality
*
* ## Business Perspective
*
* Provides compliance status and framework validation capabilities for CIA security levels.
* Enables widgets to determine which compliance frameworks are satisfied based on
* selected security configurations. 📋
*
* @returns Object containing complianceService, isLoading state, and error state
*
* @example
* ```typescript
* const { complianceService, isLoading, error } = useComplianceService();
*
* if (!isLoading && complianceService) {
* const status = complianceService.getComplianceStatus('High', 'High', 'High');
* console.log(status?.compliantFrameworks);
* }
* ```
*/
export function useComplianceService() {
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
const complianceService = useMemo(() => {
const emptySecurityLevelRecord = {
None: createEmptyCIADetails(),
Low: createEmptyCIADetails(),
Moderate: createEmptyCIADetails(),
High: createEmptyCIADetails(),
"Very High": createEmptyCIADetails(),
};
return new ComplianceServiceAdapter({
availabilityOptions: emptySecurityLevelRecord,
integrityOptions: emptySecurityLevelRecord,
confidentialityOptions: emptySecurityLevelRecord,
roiEstimates: {
NONE: { returnRate: "0%", description: "No ROI" },
LOW: { returnRate: "50%", description: "Low ROI" },
MODERATE: { returnRate: "150%", description: "Moderate ROI" },
HIGH: { returnRate: "300%", description: "High ROI" },
VERY_HIGH: { returnRate: "500%", description: "Very high ROI" },
},
});
}, []);
useEffect(() => {
let isMounted = true;
const initializeService = async () => {
try {
Eif (complianceService) {
Eif (isMounted) {
setIsLoading(false);
}
}
} catch (err) {
console.error("Failed to initialize compliance service:", err);
if (isMounted) {
setError(err instanceof Error ? err : new Error("An error occurred"));
setIsLoading(false);
}
}
};
initializeService();
return () => {
isMounted = false;
};
}, [complianceService]);
return {
isLoading,
complianceService,
error,
};
}
|