|
|
@ -1,22 +1,31 @@ |
|
|
|
import type { RoadmapOptionProps } from "../components/RoadCard/RoadmapSelect"; |
|
|
|
import type { RoadmapOptionProps } from '../components/RoadCard/RoadmapSelect'; |
|
|
|
import type { useAuth } from "../hooks/use-auth"; |
|
|
|
import type { useAuth } from '../hooks/use-auth'; |
|
|
|
|
|
|
|
|
|
|
|
export type GetBadgeLinkProps = { |
|
|
|
export type GetBadgeLinkProps = { |
|
|
|
user: ReturnType<typeof useAuth>; |
|
|
|
user: ReturnType<typeof useAuth>; |
|
|
|
variant: 'dark' | 'light'; |
|
|
|
variant: 'dark' | 'light'; |
|
|
|
badge: 'tall' | 'wide'; |
|
|
|
badge: 'tall' | 'wide'; |
|
|
|
roadmaps?: RoadmapOptionProps[] |
|
|
|
roadmaps?: RoadmapOptionProps[]; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export function getBadgeLink({ user, variant, badge, roadmaps }: GetBadgeLinkProps) { |
|
|
|
export function getBadgeLink({ |
|
|
|
const badgeUrl = new URL(`${import.meta.env.PUBLIC_API_URL}/v1-badge/${badge}/${user?.id}`); |
|
|
|
user, |
|
|
|
|
|
|
|
variant, |
|
|
|
|
|
|
|
badge, |
|
|
|
|
|
|
|
roadmaps, |
|
|
|
|
|
|
|
}: GetBadgeLinkProps) { |
|
|
|
|
|
|
|
const badgeUrl = new URL( |
|
|
|
|
|
|
|
`${import.meta.env.PUBLIC_API_URL}/v1-badge/${badge}/${user?.id}` |
|
|
|
|
|
|
|
); |
|
|
|
if (variant) { |
|
|
|
if (variant) { |
|
|
|
badgeUrl.searchParams.set('variant', variant); |
|
|
|
badgeUrl.searchParams.set('variant', variant); |
|
|
|
} |
|
|
|
} |
|
|
|
if (roadmaps && roadmaps?.length > 0) { |
|
|
|
const isRoadmapArray = roadmaps && Array.isArray(roadmaps) && roadmaps.length; |
|
|
|
for (const roadmap of roadmaps) { |
|
|
|
if (isRoadmapArray) { |
|
|
|
badgeUrl.searchParams.append('roadmaps', roadmap.value); |
|
|
|
badgeUrl.searchParams.set( |
|
|
|
} |
|
|
|
'roadmaps', |
|
|
|
|
|
|
|
roadmaps.map(({ value }) => value).join(',') |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
const textareaContent = ` |
|
|
|
const textareaContent = ` |
|
|
|
<a href="${badgeUrl}"> |
|
|
|
<a href="${badgeUrl}"> |
|
|
@ -24,7 +33,8 @@ export function getBadgeLink({ user, variant, badge, roadmaps }: GetBadgeLinkPro |
|
|
|
</a> |
|
|
|
</a> |
|
|
|
`.trim();
|
|
|
|
`.trim();
|
|
|
|
const markdownSnippet = ` |
|
|
|
const markdownSnippet = ` |
|
|
|
[![${user?.name}${user?.name && "'s" |
|
|
|
[![${user?.name}${ |
|
|
|
|
|
|
|
user?.name && "'s" |
|
|
|
} Road Card](${badgeUrl})](${badgeUrl}) |
|
|
|
} Road Card](${badgeUrl})](${badgeUrl}) |
|
|
|
`.trim();
|
|
|
|
`.trim();
|
|
|
|
|
|
|
|
|
|
|
|