Skip to content

Commit

Permalink
Update custom page consent-ui-live-example
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuscal-Ashman committed Dec 24, 2024
1 parent ecddbb8 commit 00813d9
Showing 1 changed file with 33 additions and 47 deletions.
80 changes: 33 additions & 47 deletions custom_pages/consent-ui-live-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,59 +50,45 @@ export const InstitutionList = () => {
const checkAllLinks = (institutions) => {
institutions.forEach((institution) => {
if (institution.cdrFAQ) {
fetch(institution.cdrFAQ, { method: "HEAD" })
.then((response) => {
if (!response.ok) {
setNotifications((prevNotifications) => [
...prevNotifications,
{
institution: institution.shortName,
type: "FAQ",
link: institution.cdrFAQ,
},
]);
}
})
.catch(() =>
setNotifications((prevNotifications) => [
...prevNotifications,
{
institution: institution.shortName,
type: "FAQ",
link: institution.cdrFAQ,
},
])
);
checkLink(institution.cdrFAQ, "FAQ", institution.shortName);
}

if (institution.cdrPolicy) {
fetch(institution.cdrPolicy, { method: "HEAD" })
.then((response) => {
if (!response.ok) {
setNotifications((prevNotifications) => [
...prevNotifications,
{
institution: institution.shortName,
type: "CDR Policy",
link: institution.cdrPolicy,
},
]);
}
})
.catch(() =>
setNotifications((prevNotifications) => [
...prevNotifications,
{
institution: institution.shortName,
type: "CDR Policy",
link: institution.cdrPolicy,
},
])
);
checkLink(institution.cdrPolicy, "CDR Policy", institution.shortName);
}
});
};

const checkLink = (url, type, institutionName) => {
// Log each link for debugging purposes
console.log(`Checking link: ${url}`);

fetch(url, { method: "HEAD" })
.then((response) => {
if (response.status === 404) {
// If the status is 404, trigger a notification
setNotifications((prevNotifications) => [
...prevNotifications,
{
institution: institutionName,
type: type,
link: url,
},
]);
}
})
.catch(() => {
// In case of any error (e.g., network error), add a notification
setNotifications((prevNotifications) => [
...prevNotifications,
{
institution: institutionName,
type: type,
link: url,
},
]);
});
};

const filteredInstitutions = institutions.filter((institution) =>
institution.shortName.toLowerCase().includes(searchQuery.toLowerCase())
);
Expand Down

0 comments on commit 00813d9

Please sign in to comment.