11import { useState } from 'react' ;
22import { useForm , UseFormReturn } from 'react-hook-form' ;
3- import { AnyVariables , useMutation , UseMutationState , useQuery } from 'urql' ;
3+ import { AnyVariables , useMutation , UseMutationState } from 'urql' ;
44import { z } from 'zod' ;
55import { Tag } from '@/components//v2/tag' ;
6- import { PermissionScopeItem , usePermissionsManager } from '@/components/organization/Permissions' ;
6+ import { PermissionScopeItem } from '@/components/organization/Permissions' ;
77import { Button } from '@/components/ui/button' ;
88import {
99 Dialog ,
@@ -18,7 +18,7 @@ import { Input } from '@/components/ui/input';
1818import { InputCopy } from '@/components/ui/input-copy' ;
1919import { useToast } from '@/components/ui/use-toast' ;
2020import { Accordion } from '@/components/v2/accordion' ;
21- import { FragmentType , graphql , useFragment } from '@/gql' ;
21+ import { graphql } from '@/gql' ;
2222import { TargetAccessScope } from '@/gql/graphql' ;
2323import { RegistryAccessScope } from '@/lib/access/common' ;
2424import { zodResolver } from '@hookform/resolvers/zod' ;
@@ -48,16 +48,6 @@ export const CreateAccessToken_CreateTokenMutation = graphql(`
4848 }
4949` ) ;
5050
51- const CreateAccessTokenModalQuery = graphql ( `
52- query CreateAccessTokenModalQuery($organizationSlug: String!) {
53- organization(selector: { organizationSlug: $organizationSlug }) {
54- organization {
55- ...CreateAccessTokenModalContent_OrganizationFragment
56- }
57- }
58- }
59- ` ) ;
60-
6151export function CreateAccessTokenModal ( props : {
6252 isOpen : boolean ;
6353 toggleModalOpen : ( ) => void ;
@@ -66,52 +56,19 @@ export function CreateAccessTokenModal(props: {
6656 targetSlug : string ;
6757} ) {
6858 const { isOpen, toggleModalOpen } = props ;
69- const [ organizationQuery ] = useQuery ( {
70- query : CreateAccessTokenModalQuery ,
71- variables : {
72- organizationSlug : props . organizationSlug ,
73- } ,
74- } ) ;
75-
76- const organization = organizationQuery . data ?. organization ?. organization ;
7759
7860 return (
7961 < Dialog open = { isOpen } onOpenChange = { toggleModalOpen } >
80- { organization ? (
81- < ModalContent
82- organization = { organization }
83- organizationSlug = { props . organizationSlug }
84- projectSlug = { props . projectSlug }
85- targetSlug = { props . targetSlug }
86- toggleModalOpen = { toggleModalOpen }
87- />
88- ) : (
89- < DialogContent className = "container w-4/5 max-w-[600px] md:w-3/5" >
90- < DialogHeader >
91- < DialogTitle > Organization not found</ DialogTitle >
92- < DialogDescription >
93- The organization you are trying to access does not exist.
94- </ DialogDescription >
95- </ DialogHeader >
96- < DialogFooter >
97- < Button onClick = { toggleModalOpen } > Ok, got it!</ Button >
98- </ DialogFooter >
99- </ DialogContent >
100- ) }
62+ < ModalContent
63+ organizationSlug = { props . organizationSlug }
64+ projectSlug = { props . projectSlug }
65+ targetSlug = { props . targetSlug }
66+ toggleModalOpen = { toggleModalOpen }
67+ />
10168 </ Dialog >
10269 ) ;
10370}
10471
105- const CreateAccessTokenModalContent_OrganizationFragment = graphql ( `
106- fragment CreateAccessTokenModalContent_OrganizationFragment on Organization {
107- id
108- ...UsePermissionManager_OrganizationFragment
109- me {
110- ...UsePermissionManager_MemberFragment
111- }
112- }
113- ` ) ;
114-
11572function getFinalTargetAccessScopes (
11673 selectedScope : 'no-access' | TargetAccessScope ,
11774) : Array < TargetAccessScope > {
@@ -142,25 +99,14 @@ const createRegistryTokenFormSchema = z.object({
14299} ) ;
143100
144101export function ModalContent ( props : {
145- organization : FragmentType < typeof CreateAccessTokenModalContent_OrganizationFragment > ;
146102 organizationSlug : string ;
147103 projectSlug : string ;
148104 targetSlug : string ;
149105 toggleModalOpen : ( ) => void ;
150106} ) {
151107 const { toast } = useToast ( ) ;
152- const organization = useFragment (
153- CreateAccessTokenModalContent_OrganizationFragment ,
154- props . organization ,
155- ) ;
156108 const [ selectedScope , setSelectedScope ] = useState < 'no-access' | TargetAccessScope > ( 'no-access' ) ;
157109
158- const manager = usePermissionsManager ( {
159- organization,
160- member : organization . me ,
161- passMemberScopes : false ,
162- } ) ;
163-
164110 const form = useForm < z . infer < typeof createRegistryTokenFormSchema > > ( {
165111 mode : 'onChange' ,
166112 resolver : zodResolver ( createRegistryTokenFormSchema ) ,
@@ -205,7 +151,6 @@ export function ModalContent(props: {
205151 return (
206152 < GenerateTokenContent
207153 form = { form }
208- manager = { manager }
209154 noPermissionsSelected = { noPermissionsSelected }
210155 onSubmit = { onSubmit }
211156 selectedScope = { selectedScope } // Ensure selectedScope is passed correctly
@@ -246,7 +191,6 @@ export function CreatedTokenContent(props: {
246191export function GenerateTokenContent ( props : {
247192 form : UseFormReturn < z . infer < typeof createRegistryTokenFormSchema > > ;
248193 onSubmit : ( values : z . infer < typeof createRegistryTokenFormSchema > ) => void ;
249- manager : ReturnType < typeof usePermissionsManager > ;
250194 setSelectedScope : ( scope : 'no-access' | TargetAccessScope ) => void ;
251195 selectedScope : 'no-access' | TargetAccessScope ;
252196 toggleModalOpen : ( ) => void ;
@@ -292,11 +236,8 @@ export function GenerateTokenContent(props: {
292236 dataCy = "registry-access-scope"
293237 key = { props . selectedScope }
294238 scope = { RegistryAccessScope }
295- canManageScope = {
296- props . manager . canAccessTarget ( RegistryAccessScope . mapping [ 'read-only' ] ) ||
297- props . manager . canAccessTarget ( RegistryAccessScope . mapping [ 'read-write' ] )
298- }
299- checkAccess = { props . manager . canAccessTarget }
239+ canManageScope
240+ checkAccess = { ( ) => true }
300241 onChange = { value => {
301242 if ( value === 'no-access' ) {
302243 props . setSelectedScope ( 'no-access' ) ;
0 commit comments