Skip to content

Commit

Permalink
fix error when trying to parse "direct" is a URL
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinSchneider committed Apr 27, 2024
1 parent 9bb1fd2 commit b668dc4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
29 changes: 10 additions & 19 deletions dashboard/src/components/Profiles/ProfileInformationSideBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import EnrichedDataItem from "@/components/Profiles/EnrichedDataItem";
import { Lock } from "lucide-react";
import { humanizeVariable, safelyParseURL } from "@/lib/utils/misc";
import { humanizeVariable, isURL, safelyParseURL } from "@/lib/utils/misc";
import { Tooltipable } from '@/components/ui/tooltip'
import { prettyDateTime } from "@/lib/utils/timeHelpers";
import ProfileTags from "./ProfileTags";
Expand All @@ -18,8 +18,6 @@ const shouldHumanizeValue = key => (
!key.toLowerCase().includes('gclid')
)

const LINKABLE_METADATA_KEYS = ['initial_landing_page_url', 'initial_referrer_url', 'initial_referrer']

export default function ProfileInformationSideBar({ userData, hasStripeIntegrationEnabled, hasProfileEnrichmentEnabled }) {
const hasNoEnrichmentData = !userData.enrichment_data?.job_title &&
!userData.enrichment_data?.twitter_url &&
Expand Down Expand Up @@ -119,24 +117,17 @@ export default function ProfileInformationSideBar({ userData, hasStripeIntegrati
<dt className="text-sm font-medium leading-6 text-gray-900">{humanizeVariable(key)}</dt>
<dd className="text-sm leading-6 text-gray-700 text-right flex flex-col">
<span className='flex justify-end truncate'>
{LINKABLE_METADATA_KEYS.includes(key)
&& (
userData.metadata[key]
? <MaybeExternalLink href={userData.metadata[key]} newTab={true} className='truncate justify-self-end'>
{userData.metadata[key]}
</MaybeExternalLink>
: '-'
{isURL(userData.metadata[key])
? (
<MaybeExternalLink href={userData.metadata[key]} newTab={true} className='truncate justify-self-end'>
{userData.metadata[key]}
</MaybeExternalLink>
) : (
shouldHumanizeValue(key)
? [undefined, null].includes(userData.metadata[key]) ? '-' : humanizeVariable(userData.metadata[key])
: userData.metadata[key].toString()
)
}
{!LINKABLE_METADATA_KEYS.includes(key) && (
!shouldHumanizeValue(key)
? userData.metadata[key]
: humanizeVariable(
[undefined, null].includes(userData.metadata[key])
? '-'
: userData.metadata[key].toString()
)
)}
</span>
</dd>
</div>
Expand Down
9 changes: 9 additions & 0 deletions dashboard/src/lib/utils/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ export const humanizeVariable = variableName => {

export const caseInsensitiveSortedArray = array => {
return array.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
}

export const isURL = url => {
try {
new URL(url)
return true
} catch (err) {
return false
}
}

0 comments on commit b668dc4

Please sign in to comment.