1- import React , { FC , useState } from 'react'
1+ import { FC , useEffect , useRef , useState } from 'react'
2+ import Button from 'components/base/forms/Button'
3+ import ProviderCard from 'components/pages/organisation-settings/tabs/trust-relationships/ProviderCard'
4+ import {
5+ TRUST_RELATIONSHIP_PROVIDERS ,
6+ TrustRelationshipProvider ,
7+ } from 'components/pages/organisation-settings/tabs/trust-relationships/providers'
28import GithubTrustRelationshipForm from 'components/pages/organisation-settings/tabs/trust-relationships/GithubTrustRelationshipForm'
39import TrustRelationshipModal from 'components/pages/organisation-settings/tabs/trust-relationships/TrustRelationshipModal'
10+ import './NewTrustRelationshipModal.scss'
411
5- type Provider = 'github' | 'other'
12+ const ICON_SIZE = 40
613
714type NewTrustRelationshipModalProps = {
815 organisationId : number
@@ -13,55 +20,70 @@ const NewTrustRelationshipModal: FC<NewTrustRelationshipModalProps> = ({
1320 existingAudiences,
1421 organisationId,
1522} ) => {
16- const [ provider , setProvider ] = useState < Provider | null > ( null )
23+ const [ provider , setProvider ] = useState < TrustRelationshipProvider | null > (
24+ null ,
25+ )
26+ const formRef = useRef < HTMLDivElement > ( null )
27+
28+ useEffect ( ( ) => {
29+ // Land on the first field, which depends on the provider and, for GitHub, on
30+ // whether the integration is installed.
31+ formRef . current
32+ ?. querySelector < HTMLElement > (
33+ 'input:not([readonly]):not([type=hidden]), textarea' ,
34+ )
35+ ?. focus ( )
36+ } , [ provider ] )
1737
18- if ( provider === 'github' ) {
38+ if ( ! provider ) {
1939 return (
20- < GithubTrustRelationshipForm
21- organisationId = { organisationId }
22- existingAudiences = { existingAudiences }
23- />
40+ < div className = 'p-4' >
41+ < p className = 'text-secondary mb-3' >
42+ Choose how your CI will authenticate.
43+ </ p >
44+ < div className = 'd-flex flex-column gap-3' >
45+ { TRUST_RELATIONSHIP_PROVIDERS . map ( ( option ) => (
46+ < ProviderCard
47+ key = { option . key }
48+ onClick = { ( ) => setProvider ( option ) }
49+ icon = { option . icon ( ICON_SIZE ) }
50+ title = { option . label }
51+ description = { option . description }
52+ badge = { option . badge }
53+ />
54+ ) ) }
55+ </ div >
56+ </ div >
2457 )
2558 }
26- if ( provider === 'other' ) {
27- return < TrustRelationshipModal organisationId = { organisationId } />
28- }
2959
3060 return (
31- < div className = 'p-4' >
32- < div
33- className = 'panel--grey p-3 mb-3 clickable'
34- data-test = 'provider-github'
35- role = 'button'
36- tabIndex = { 0 }
37- onClick = { ( ) => setProvider ( 'github' ) }
38- onKeyDown = { ( e ) => {
39- if ( e . key === 'Enter' || e . key === ' ' ) setProvider ( 'github' )
40- } }
41- >
42- < h6 className = 'mb-1' > GitHub Actions</ h6 >
43- < div className = 'text-muted fs-small' >
44- Let workflows in a GitHub repository authenticate with their OIDC job
45- token. Recommended if your CI runs on GitHub Actions.
61+ < >
62+ < div className = 'px-4 pt-4' >
63+ < div className = 'fs-small text-secondary text-uppercase mb-2' >
64+ Provider
4665 </ div >
47- </ div >
48- < div
49- className = 'panel--grey p-3 clickable'
50- data-test = 'provider-other'
51- role = 'button'
52- tabIndex = { 0 }
53- onClick = { ( ) => setProvider ( 'other' ) }
54- onKeyDown = { ( e ) => {
55- if ( e . key === 'Enter' || e . key === ' ' ) setProvider ( 'other' )
56- } }
57- >
58- < h6 className = 'mb-1' > Other OIDC provider</ h6 >
59- < div className = 'text-muted fs-small' >
60- Configure a custom issuer, audience and claim matching rules for any
61- OIDC identity provider, such as GitLab CI or Kubernetes.
66+ < div className = 'new-trust-relationship__provider d-flex align-items-center gap-3 p-3 rounded-lg bg-surface-subtle' >
67+ < span className = 'd-flex' aria-hidden >
68+ { provider . icon ( ICON_SIZE - 12 ) }
69+ </ span >
70+ < div className = 'flex-fill fw-semibold' > { provider . label } </ div >
71+ < Button theme = 'text' onClick = { ( ) => setProvider ( null ) } >
72+ Change
73+ </ Button >
6274 </ div >
6375 </ div >
64- </ div >
76+ < div ref = { formRef } >
77+ { provider . key === 'github' ? (
78+ < GithubTrustRelationshipForm
79+ organisationId = { organisationId }
80+ existingAudiences = { existingAudiences }
81+ />
82+ ) : (
83+ < TrustRelationshipModal organisationId = { organisationId } />
84+ ) }
85+ </ div >
86+ </ >
6587 )
6688}
6789
0 commit comments