Skip to content

Commit

Permalink
fix: post, goal and reward share urls to include heroID and rounded c…
Browse files Browse the repository at this point in the history
…orner for sponsorship banner
  • Loading branch information
sajald77 committed Nov 26, 2024
1 parent b46af0e commit 17829d3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const SponsorshipBanner = () => {
padding={{ base: '12px', lg: '16px 24px' }}
backgroundColor="neutral1.4"
>
<Image src={data?.image} height="40px" width="40px" />
<Image src={data?.image} height="40px" width="40px" borderRadius="8px" />
<Body size="xl" medium>
{data?.text}{' '}
<Body as="span">
Expand Down
36 changes: 30 additions & 6 deletions src/modules/project/pages1/projectView/hooks/useProjectShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,17 @@ export const useProjectShare = () => {
/** This hook must be used inside ProjectProvider Context to share project rewardLinks links */
export const useRewardShare = ({ id, name }: Pick<ProjectReward, 'id' | 'name'>) => {
const { project, isProjectOwner } = useProjectAtom()
const { isLoggedIn } = useAuthContext()
const { isLoggedIn, user } = useAuthContext()
const [copied, setCopied] = useState(false)

const getShareRewardUrlWithHeroId = ({ clickedFrom }: { clickedFrom: CampaignContent }) => {
if (user && user.heroId) {
return `${window.location.origin}${getPath('projectRewardView', project.name, `${id}`)}?hero=${user.heroId}`
}

return getShareRewardUrl({ clickedFrom })
}

const getShareRewardUrl = ({ clickedFrom }: { clickedFrom: CampaignContent }) => {
const campaignUrlSuffix = getProjectShareUrlSuffix({
creator: isProjectOwner,
Expand All @@ -124,15 +132,23 @@ export const useRewardShare = ({ id, name }: Pick<ProjectReward, 'id' | 'name'>)
}, 2000)
}

return { getShareRewardUrl, copyRewardLinkToClipboard, copied }
return { getShareRewardUrl, getShareRewardUrlWithHeroId, copyRewardLinkToClipboard, copied }
}

/** This hook must be used inside ProjectProvider Context to share project rpostLinks links */
export const usePostShare = ({ id }: Pick<ProjectEntryFragment, 'id'>) => {
const { project, isProjectOwner } = useProjectAtom()
const { isLoggedIn } = useAuthContext()
const { isLoggedIn, user } = useAuthContext()
const [copied, setCopied] = useState(false)

const getSharePostUrlWithHeroId = ({ clickedFrom }: { clickedFrom: CampaignContent }) => {
if (user && user.heroId) {
return `${window.location.origin}${getPath('projectPostView', project.name, `${id}`)}?hero=${user.heroId}`
}

return getSharePostUrl({ clickedFrom })
}

const getSharePostUrl = ({ clickedFrom }: { clickedFrom: CampaignContent }) => {
const campaignUrlSuffix = getProjectShareUrlSuffix({
creator: isProjectOwner,
Expand All @@ -154,15 +170,23 @@ export const usePostShare = ({ id }: Pick<ProjectEntryFragment, 'id'>) => {
}, 2000)
}

return { getSharePostUrl, copyPostLinkToClipboard, copied }
return { getSharePostUrl, getSharePostUrlWithHeroId, copyPostLinkToClipboard, copied }
}

/** This hook must be used inside ProjectProvider Context to share project goal links */
export const useGoalShare = ({ id, name }: { id: string; name: string }) => {
const { project, isProjectOwner } = useProjectAtom()
const { isLoggedIn } = useAuthContext()
const { isLoggedIn, user } = useAuthContext()
const [copied, setCopied] = useState(false)

const getShareGoalUrlWithHeroId = ({ clickedFrom }: { clickedFrom: CampaignContent }) => {
if (user && user.heroId) {
return `${window.location.origin}${getPath('projectGoalView', project.name, `${id}`)}?hero=${user.heroId}`
}

return getShareGoalUrl({ clickedFrom })
}

const getShareGoalUrl = ({ clickedFrom }: { clickedFrom: CampaignContent }) => {
const campaignUrlSuffix = getProjectShareUrlSuffix({
creator: isProjectOwner,
Expand All @@ -184,5 +208,5 @@ export const useGoalShare = ({ id, name }: { id: string; name: string }) => {
}, 2000)
}

return { getShareGoalUrl, copyGoalLinkToClipboard, copied }
return { getShareGoalUrl, getShareGoalUrlWithHeroId, copyGoalLinkToClipboard, copied }
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export const GoalShare = ({ goal, ...props }: GoalShareProps) => {

const { project } = useProjectAtom()

const { getShareGoalUrl } = useGoalShare({ id: goal.id, name: goal.title })
const { getShareGoalUrlWithHeroId } = useGoalShare({ id: goal.id, name: goal.title })

const projectGoalUrl = getShareGoalUrl({ clickedFrom: CampaignContent.goalShareButton })
const projectGoalUrl = getShareGoalUrlWithHeroId({ clickedFrom: CampaignContent.goalShareButton })

const twitterPostUrl = generateTwitterShareUrl(projectGoalUrl)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const PostShare = ({ post, ...props }: PostShareProps) => {

const postShareModal = useModal()

const { getSharePostUrl } = usePostShare({ id: post.id })
const { getSharePostUrlWithHeroId } = usePostShare({ id: post.id })

const postRewardUrl = getSharePostUrl({ clickedFrom: CampaignContent.postShareButton })
const postRewardUrl = getSharePostUrlWithHeroId({ clickedFrom: CampaignContent.postShareButton })

const twitterPostUrl = generateTwitterShareUrl(postRewardUrl)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ type RewardShareProps = {
export const RewardShare = ({ reward, ...props }: RewardShareProps) => {
const rewardShareModal = useModal()

const { getShareRewardUrl } = useRewardShare({ id: reward.id, name: reward.name })
const { getShareRewardUrlWithHeroId } = useRewardShare({ id: reward.id, name: reward.name })

const projectRewardUrl = getShareRewardUrl({ clickedFrom: CampaignContent.rewardShareButton })
const projectRewardUrl = getShareRewardUrlWithHeroId({ clickedFrom: CampaignContent.rewardShareButton })

const twitterPostUrl = generateTwitterShareUrl(projectRewardUrl)

Expand Down

0 comments on commit 17829d3

Please sign in to comment.