-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: github public scope permissions (#642)
- Loading branch information
1 parent
2ee104a
commit 7add37d
Showing
13 changed files
with
216 additions
and
40 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
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
5 changes: 5 additions & 0 deletions
5
core/application/auth0-client-adapter/hooks/use-local-scope-storage.ts
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,5 @@ | ||
import { useLocalStorage } from "react-use"; | ||
|
||
export function useLocalScopeStorage() { | ||
return useLocalStorage("dynamic-github-public-repo-scope"); | ||
} |
51 changes: 51 additions & 0 deletions
51
core/application/auth0-client-adapter/hooks/use-public-repo-scope.ts
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,51 @@ | ||
import { useMemo } from "react"; | ||
|
||
import { Auth0ClientAdapter } from "@/core/application/auth0-client-adapter"; | ||
import { useLocalScopeStorage } from "@/core/application/auth0-client-adapter/hooks/use-local-scope-storage"; | ||
import { MeReactQueryAdapter } from "@/core/application/react-query-adapter/me"; | ||
import { useClientBootstrapContext } from "@/core/bootstrap/client-bootstrap-context"; | ||
|
||
import { useAuthUser } from "@/shared/hooks/auth/use-auth-user"; | ||
|
||
export function usePublicRepoScope() { | ||
const [scopeStorage, setScopeStorage] = useLocalScopeStorage(); | ||
|
||
const { | ||
clientBootstrap: { authProvider }, | ||
} = useClientBootstrapContext(); | ||
const { isAuthenticated = false, loginWithRedirect, loginWithPopup } = authProvider ?? {}; | ||
|
||
const { user, refetch } = useAuthUser(); | ||
const isAuthorized = useMemo(() => user?.isAuthorizedToApplyOnGithubIssues, [user]); | ||
|
||
const { mutateAsync: logoutUser } = MeReactQueryAdapter.client.useLogoutMe({}); | ||
|
||
async function getPermissions() { | ||
if (!scopeStorage) { | ||
setScopeStorage(process.env.NEXT_PUBLIC_GITHUB_PUBLIC_REPO_SCOPE); | ||
} | ||
|
||
await logoutUser({}); | ||
|
||
if (loginWithPopup) await Auth0ClientAdapter.helpers.handleLoginWithPopup(loginWithPopup); | ||
|
||
await refetch(); | ||
} | ||
|
||
async function handleVerifyPermissions(onSuccess?: () => void) { | ||
if (!isAuthenticated) { | ||
if (loginWithRedirect) Auth0ClientAdapter.helpers.handleLoginWithRedirect(loginWithRedirect); | ||
return; | ||
} | ||
|
||
if (!isAuthorized) { | ||
await getPermissions(); | ||
onSuccess?.(); | ||
return; | ||
} | ||
|
||
onSuccess?.(); | ||
} | ||
|
||
return { handleVerifyPermissions, getPermissions, isAuthorized }; | ||
} |
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
6 changes: 6 additions & 0 deletions
6
...github-public-scope-permission-modal/_translations/github-public-scope-permission.en.json
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,6 @@ | ||
{ | ||
"title": "Grant permissions", | ||
"description": "We need your permission to write comments on your behalf and apply to selected issues directly on OnlyDust. Only need to be accepted once.", | ||
"moreInfo": "Click on \"Grant Permissions\". A GitHub popup will appear. Click on \"Authorize OnlyDust\", and you'll be redirected back here to submit your application.", | ||
"grantPermissions": "Write all public repository data" | ||
} |
7 changes: 7 additions & 0 deletions
7
...nents/github-public-scope-permission-modal/github-public-scope-permission-modal.hooks.tsx
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,7 @@ | ||
import { useState } from "react"; | ||
|
||
export function useGithubPublicScopePermissionModal() { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return { isOpen, setIsOpen }; | ||
} |
51 changes: 51 additions & 0 deletions
51
..._components/github-public-scope-permission-modal/github-public-scope-permission-modal.tsx
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,51 @@ | ||
import githubPermissionImage from "@/public/images/github/github-permission.png"; | ||
import { Github, SquareArrowOutUpRight } from "lucide-react"; | ||
import Image from "next/image"; | ||
|
||
import { Button } from "@/design-system/atoms/button/variants/button-default"; | ||
import { Typo } from "@/design-system/atoms/typo"; | ||
import { Modal } from "@/design-system/molecules/modal"; | ||
|
||
import { GithubPublicScopePermissionModalProps } from "./github-public-scope-permission-modal.types"; | ||
|
||
export function GithubPublicScopePermissionModal({ | ||
isOpen, | ||
onOpenChange, | ||
onRedirect, | ||
}: GithubPublicScopePermissionModalProps) { | ||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
onOpenChange={onOpenChange} | ||
titleProps={{ | ||
translate: { token: "modals:githubPublicScopePermission.title" }, | ||
}} | ||
footer={{ | ||
endContent: ( | ||
<Button | ||
translate={{ token: "modals:githubPublicScopePermission.grantPermissions" }} | ||
startIcon={{ component: Github }} | ||
endIcon={{ component: SquareArrowOutUpRight }} | ||
onClick={onRedirect} | ||
/> | ||
), | ||
}} | ||
size="xl" | ||
background="gradient" | ||
> | ||
<div className="flex flex-col gap-lg"> | ||
<Image | ||
src={githubPermissionImage} | ||
alt="github permission" | ||
className="h-full w-full object-cover object-center" | ||
loading={"lazy"} | ||
width={320} | ||
height={50} | ||
quality={100} | ||
/> | ||
<Typo size="xs" color="primary" translate={{ token: "modals:githubPublicScopePermission.description" }} /> | ||
<Typo size="xs" color="tertiary" translate={{ token: "modals:githubPublicScopePermission.moreInfo" }} /> | ||
</div> | ||
</Modal> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
...nents/github-public-scope-permission-modal/github-public-scope-permission-modal.types.tsx
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,5 @@ | ||
import { ModalPort } from "@/design-system/molecules/modal"; | ||
|
||
export interface GithubPublicScopePermissionModalProps extends Pick<ModalPort<"div">, "isOpen" | "onOpenChange"> { | ||
onRedirect: () => void; | ||
} |
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
Oops, something went wrong.