Skip to content

Commit

Permalink
Skip "original form" and "help page url" links if the URL isn't valid (
Browse files Browse the repository at this point in the history
…#96)

* Fix #86

* Format with prettier

* Restore accidentally removed comment
  • Loading branch information
nonprofittechy authored Sep 23, 2024
1 parent f10d24e commit 7ee3198
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 33 deletions.
30 changes: 22 additions & 8 deletions src/app/[path]/forms/[form]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ interface PageProps {
};
}

const isValidUrl = (url: string): boolean => {
try {
new URL(url);
return true;
} catch (e) {
return false;
}
};

const Page = async ({ params }: PageProps) => {
const { form } = params;
const { interviewsByTopic, isError } = await fetchInterviews('ma');
Expand Down Expand Up @@ -46,7 +55,8 @@ const Page = async ({ params }: PageProps) => {
{formDetails.metadata.description}
</ReactMarkdown>
{(formDetails.metadata.help_page_url ||
formDetails.metadata.original_form) && (
(formDetails.metadata.original_form &&
isValidUrl(formDetails.metadata.original_form))) && (
<>
<p>
<strong>More information:</strong>
Expand All @@ -59,13 +69,17 @@ const Page = async ({ params }: PageProps) => {
</Link>
</li>
)}
{formDetails.metadata.original_form && (
<li>
<Link href={formDetails.metadata.original_form} target="_blank">
Original form
</Link>
</li>
)}
{formDetails.metadata.original_form &&
isValidUrl(formDetails.metadata.original_form) && (
<li>
<Link
href={formDetails.metadata.original_form}
target="_blank"
>
Original form
</Link>
</li>
)}
</ul>
</>
)}
Expand Down
7 changes: 3 additions & 4 deletions src/app/css/AffiliatesSection.module.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
.AffiliatesSection {
background: rgba(0,0,0,.1);

background: rgba(0, 0, 0, 0.1);
}

.AffiliatesContainer {
margin-right: auto;
margin-left: auto;
max-width: 576px;

& > :not(:last-child) {
margin-bottom: 1em;
}
Expand All @@ -16,4 +15,4 @@
.AffiliateLogo {
height: auto;
max-width: 100%;
}
}
2 changes: 1 addition & 1 deletion src/app/css/AllFormsContainer.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.AllFormsContainer {
max-width: calc(992px);
}
}
2 changes: 1 addition & 1 deletion src/app/css/Footer.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
margin-right: auto;
max-width: 576px;
width: 100%;
}
}
2 changes: 1 addition & 1 deletion src/app/css/FormPage.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.FormPage {
max-width: 768px;
}
}
2 changes: 1 addition & 1 deletion src/app/css/HeroSection.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
& textarea {
min-height: 6lh;
}
}
}
2 changes: 1 addition & 1 deletion src/app/css/HowItWorksSection.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.HowItWorksSection {
background-color: #3e7d9a54;
}
}
6 changes: 2 additions & 4 deletions src/app/css/InteractiveForm.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.Form {
gap: 1rem;

&:last-child{
&:last-child {
border-bottom: 0 !important;
}

Expand All @@ -12,7 +12,6 @@
}
}


.FormTitleContainer {
max-width: 768px;
}
Expand All @@ -24,7 +23,6 @@
}
}


.FormButtonContainer {
margin-left: auto;

Expand All @@ -33,4 +31,4 @@
margin-left: 0;
}
}
}
}
7 changes: 3 additions & 4 deletions src/app/css/NavigationBar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
&:not(:hover) {
text-decoration: none;
}

}

.AllFormsPath {
text-transform: uppercase;
}

.ExternalLinkIcon {
height: .8em;
width: .8em;
height: 0.8em;
width: 0.8em;
vertical-align: top;
}
}
2 changes: 1 addition & 1 deletion src/app/css/SearchSection.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.ClearSearchButton {
font-size: 80%;
}
}
2 changes: 1 addition & 1 deletion src/app/css/ShowAllToggle.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
border: none !important;
background: #002e60 !important;
margin-top: 10px;
}
}
2 changes: 1 addition & 1 deletion src/app/css/ThankYou.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
height: auto;
max-width: 100%;
}
}
}
4 changes: 2 additions & 2 deletions src/app/css/TopicCard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.TagContainer {
overflow: hidden;
transition: max-height 0.4s ease-in-out;
gap: .5rem;
gap: 0.5rem;
}

.FormTag {
Expand Down Expand Up @@ -46,4 +46,4 @@
}

.ShowContainer {
}
}
2 changes: 1 addition & 1 deletion src/app/css/TopicPage.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.TopicPage {
max-width: 768px;
}
}
2 changes: 1 addition & 1 deletion src/app/css/TopicsSection.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.TopicsSection {
background-color: #fbfafe;
}
}
2 changes: 1 addition & 1 deletion src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ h5,
/* Removes body bottom padding if the last child element is the affiliates section. */
.body-container:has(#affiliates-section:last-child) {
padding-bottom: 0 !important;
}
}

0 comments on commit 7ee3198

Please sign in to comment.