-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean up benefit page rules component
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useState, useEffect } from "react"; | ||
import { transformRulesFromRequirementProfile } from "@foerderfunke/matching-engine/src/prematch"; | ||
import resourceService from "../../../../core/services/resourceService"; | ||
|
||
const useBenefitPageRules = (benefitId, validationConfig, validationReport) => { | ||
const [rulesData, setRulesData] = useState({}); | ||
const [benefitReport, setBenefitReport] = useState({}); | ||
|
||
useEffect(() => { | ||
const fetchRulesData = async () => { | ||
if (!validationConfig) return; | ||
|
||
const rpUri = benefitId.startsWith("ff:") | ||
? `https://foerderfunke.org/default#${benefitId.split(":")[1]}` | ||
: benefitId; | ||
|
||
const query = validationConfig['queries'].find(query => query['rpUri'] === rpUri); | ||
if (!query) return; | ||
|
||
const rpTurtleStr = await resourceService.fetchResource(query.fileUrl); | ||
const rules = await transformRulesFromRequirementProfile(rpTurtleStr); | ||
|
||
setRulesData(rules); | ||
setBenefitReport(validationReport.reports.find(report => report.rpUri === rpUri)); | ||
}; | ||
|
||
fetchRulesData(); | ||
}, [benefitId, validationConfig, validationReport]); | ||
|
||
return { rulesData, benefitReport }; | ||
}; | ||
|
||
export default useBenefitPageRules; |