11import "./ApplicationDetail.scss" ;
22import React , { useEffect , useState } from "react" ;
3- import { publicServiceProviderByDetail } from "../api/index.js" ;
3+ import { connectServiceProviderToIdentityProvider , publicServiceProviderByDetail } from "../api/index.js" ;
44import I18n from "../locale/I18n.js" ;
55import { useNavigate , useParams } from "react-router-dom" ;
6- import { Button , ButtonIconPlacement , ButtonType , Loader } from "@surfnet/sds" ;
6+ import { Button , ButtonIconPlacement , ButtonType , Loader , RadioOptions , RadioOptionsOrientation } from "@surfnet/sds" ;
77import StudentPng from "../icons/student2.png" ;
88import PlaceHolderImage from "@surfnet/sds/icons/placeholder-image.svg" ;
99import ArrowLeftIcon from "@surfnet/sds/icons/functional-icons/arrow-left-2.svg" ;
@@ -13,6 +13,13 @@ import {useAppStore} from "../stores/AppStore.js";
1313import { useShallow } from "zustand/react/shallow" ;
1414import ConfirmationDialog from "../components/ConfirmationDialog.jsx" ;
1515
16+ const confirmationModalOptions = {
17+ makeConnection : "makeConnection" ,
18+ requestConnection : "requestConnection" ,
19+ disconnectConnection : "disconnectConnection" ,
20+ requestDisconnectConnection : "requestDisconnectConnection" ,
21+ }
22+
1623const ApplicationDetail = ( { anonymous} ) => {
1724
1825 const { arp, privacy, user} = useAppStore ( useShallow ( state => ( {
@@ -28,13 +35,24 @@ const ApplicationDetail = ({anonymous}) => {
2835 const [ serviceProvider , setServiceProvider ] = useState ( [ ] ) ;
2936 const [ showAttributes , setShowAttributes ] = useState ( false ) ;
3037 const [ showPrivacy , setShowPrivacy ] = useState ( false ) ;
38+ const [ metaData , setMetaData ] = useState ( { } ) ;
39+ const [ connectWithOutInteraction , setConnectWithOutInteraction ] = useState ( false ) ;
3140 const [ confirmation , setConfirmation ] = useState ( { } ) ;
41+ const [ accessChoice , setAccessChoice ] = useState ( "ALL" ) ;
42+ const [ confirmationModalOption , setConfirmationModalOption ] = useState ( null ) ;
43+
3244
3345 useEffect ( ( ) => {
3446 publicServiceProviderByDetail ( manageType , manageId )
3547 . then ( res => {
3648 setServiceProvider ( res ) ;
3749 setLoading ( false ) ;
50+ const newMetaData = res . data . metaDataFields ;
51+ setMetaData ( newMetaData ) ;
52+ const connectOption = newMetaData [ "coin:dashboard_connect_option" ] || "connect_with_interaction" ;
53+ const sameInstitution = ! isEmpty ( newMetaData [ "coin:institution_guid" ] ) &&
54+ newMetaData [ "coin:institution_guid" ] === user . identityProvider . data . metaDataFields [ "coin:institution_guid" ]
55+ setConnectWithOutInteraction ( connectOption !== "connect_with_interaction" || sameInstitution ) ;
3856 } )
3957 . catch ( ( ) => {
4058 navigate ( "/404" ) ;
@@ -63,8 +81,6 @@ const ApplicationDetail = ({anonymous}) => {
6381 ) ;
6482 }
6583
66- const metaData = serviceProvider . data . metaDataFields ;
67-
6884 const toggleShowAttributes = e => {
6985 stopEvent ( e ) ;
7086 setShowAttributes ( true ) ;
@@ -79,57 +95,65 @@ const ApplicationDetail = ({anonymous}) => {
7995 return arp . attributes . find ( attr => attr . urn === urn ) ;
8096 }
8197
82- const mayConnectWithoutInteraction = ( ) => {
83- const connectOption = metaData [ "coin:dashboard_connect_option" ] || "connect_with_interaction" ;
84- const sameInstitution = ! isEmpty ( metaData [ "coin:institution_guid" ] ) &&
85- metaData [ "coin:institution_guid" ] === user . identityProvider . data . metaDataFields [ "coin:institution_guid" ]
86- return connectOption !== "connect_with_interaction" || sameInstitution ;
87- }
88-
89- const openConnectDialog = ( ) => {
90- setConfirmation ( {
91- open : true ,
92- cancel : ( ) => setConfirmation ( { open : false } ) ,
93- action : ( ) => doDelete ( invitation , false ) ,
94- question : I18n . t ( "invitationsManagement.deleteConfirmation" , { email : invitation . inviter . name } ) ,
95- okButton : I18n . t ( "invitationsManagement.revoke" )
96- } ) ;
97- }
98-
99- const doRequestConnection = ( ) => {
100-
98+ const confirmationModalChildren = ( ) => {
99+ if ( confirmationModalOption === confirmationModalOptions . makeConnection ) {
100+ return (
101+ < div className = "connect-options-container" >
102+ < RadioOptions name = { "access" }
103+ label = { I18n . t ( "applicationConnect.defaultAccess" ) }
104+ value = { accessChoice }
105+ onChange = { e => {
106+ const newValue = e . target . id . replace ( "access_" , "" ) . toUpperCase ( ) ;
107+ setAccessChoice ( newValue ) ;
108+ } }
109+ isMultiple = { true }
110+ labels = { [ "ALL" , "SOME" ] }
111+ labelResolver = { label => I18n . t ( `applicationConnect.access.${ label . toLowerCase ( ) } ` , {
112+ orgName : providerName ( I18n . locale , user . identityProvider )
113+ } ) }
114+ orientation = { RadioOptionsOrientation . column } />
115+ </ div >
116+ ) ;
117+ }
118+ return "TODO"
101119 }
102120
103- const openRequestConnectionDialog = ( ) => {
104- setConfirmation ( {
105- open : true ,
106- cancel : ( ) => setConfirmation ( { open : false } ) ,
107- action : ( ) => doDelete ( invitation , false ) ,
108- question : I18n . t ( "invitationsManagement.deleteConfirmation" , { email : invitation . inviter . name } ) ,
109- okButton : I18n . t ( "invitationsManagement.revoke" )
110- } ) ;
121+ const doRequestConnection = withConfirmation => {
122+ if ( withConfirmation ) {
123+ setConfirmation ( {
124+ open : true ,
125+ cancel : ( ) => setConfirmation ( { open : false } ) ,
126+ action : ( ) => doRequestConnection ( false ) ,
127+ title : null ,
128+ question : null ,
129+ okButton : I18n . t ( "forms.proceed" )
130+ } ) ;
131+ setConfirmationModalOption ( confirmationModalOptions . makeConnection )
132+ } else {
133+ setConfirmation ( { } ) ;
134+ connectServiceProviderToIdentityProvider ( serviceProvider . id , serviceProvider . type , user . identityProvider . id )
135+ . then ( ( ) => {
136+ //Where to go to next?
137+ alert ( "done" )
138+ } )
139+ }
111140 }
112141
113142 const goBack = e => {
114143 stopEvent ( e ) ;
115144 navigate ( - 1 ) ;
116145 }
117146
118- const connectButtonText = ( ) => {
119- //Is the app already connected, may the app be connected without interaction, or is there already an outstanding change request?
120- return I18n . t ( `applicationConnect.${ mayConnectWithoutInteraction ( ) ? "connect" : "request" } ` )
121- }
122-
123- const { open, cancel, action, question, okButton, children} = confirmation ;
147+ const { open, cancel, action, question, title, okButton} = confirmation ;
124148
125149 return (
126150 < div className = "application-detail-container" >
127151 { open && < ConfirmationDialog confirm = { action }
128152 cancel = { cancel }
129- confirmationHeader = { I18n . t ( "forms.submit" ) }
130153 confirmationTxt = { okButton }
154+ confirmationHeader = { title }
131155 question = { question } >
132- { children }
156+ { confirmationModalChildren ( ) }
133157 </ ConfirmationDialog >
134158 }
135159 { anonymous && < div className = "application-detail-header-container" >
@@ -164,8 +188,8 @@ const ApplicationDetail = ({anonymous}) => {
164188 iconPlacement = { ButtonIconPlacement . Left }
165189 onClick = { goBack }
166190 txt = { I18n . t ( "applicationDetail.back" ) } /> }
167- { ! anonymous && < Button onClick = { ( ) => alert ( "Todo" ) }
168- txt = { connectButtonText ( ) } /> }
191+ { ! anonymous && < Button onClick = { ( ) => doRequestConnection ( true ) }
192+ txt = { I18n . t ( `applicationConnect. ${ connectWithOutInteraction ? "connect" : "request" } ` ) } /> }
169193 </ div >
170194 < div className = "details" >
171195 < div className = "left" >
0 commit comments