Skip to content

Commit

Permalink
clean up benefit page rules component
Browse files Browse the repository at this point in the history
  • Loading branch information
wbglaeser committed Dec 17, 2024
1 parent c0fadd6 commit a5b80a6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/ui/screens/benefit-page/hooks/useBenefitPageRules.js
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;

0 comments on commit a5b80a6

Please sign in to comment.