-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefill user ID when replying to an opportunity
- Loading branch information
Showing
6 changed files
with
69 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use client"; | ||
|
||
import { useSession } from "next-auth/react"; | ||
|
||
import { SidebarCTA } from "~/components/Sidebar"; | ||
import { type Opportunity } from "~/src/data/opportunity"; | ||
import { assertIsOurUser } from "~/src/utils"; | ||
|
||
type Props = { | ||
role: Pick<Opportunity, "responseUrl" | "prefillUserId">; | ||
}; | ||
|
||
export const ResponseButton = ({ role }: Props) => { | ||
const { data: session, status: sessionStatus } = useSession(); | ||
if ( | ||
role.prefillUserId && | ||
sessionStatus === "authenticated" && | ||
session.user && | ||
role.responseUrl.startsWith("https://") | ||
) { | ||
// If we have a valid session and the response URL is an ordinary | ||
// HTTPS URL, add current user ID to the response URL. | ||
assertIsOurUser(session.user); | ||
const responseUrl = new URL(role.responseUrl); | ||
responseUrl.searchParams.append("prefill_User", session.user.id); | ||
responseUrl.searchParams.append("hide_User", "true"); | ||
return <SidebarCTA href={responseUrl.toString()} label="Mám zájem ✨" />; | ||
} else { | ||
// Otherwise just use the response URL from the database. | ||
return <SidebarCTA href={role.responseUrl} label="Mám zájem" />; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters