@@ -2,6 +2,7 @@ import { type JSX } from 'react';
22
33import { Col , descriptors , Heading , localizationKeys , Text } from '@/customizables' ;
44import { ClipboardInput } from '@/elements/ClipboardInput' ;
5+ import { useCardState } from '@/elements/contexts' ;
56import { Form } from '@/elements/Form' ;
67import { Checkmark , Clipboard } from '@/icons' ;
78import { useFormControl } from '@/ui/utils/useFormControl' ;
@@ -12,6 +13,7 @@ import { useWizard, Wizard } from '../../../elements/Wizard';
1213import { InnerStepCounter } from '../../../elements/Wizard/InnerStepCounter' ;
1314import { AttributeMappingTable , type AttributeMappingTableConfig } from './shared/AttributeMappingTable' ;
1415import { IdentityProviderMetadataForm } from './shared/IdentityProviderMetadataForm' ;
16+ import { useIdentityProviderMetadataForm } from './shared/useIdentityProviderMetadataForm' ;
1517
1618export const SamlCustomConfigureSteps = ( ) : JSX . Element => {
1719 return (
@@ -250,29 +252,19 @@ const SamlCustomAssignUsersStep = (): JSX.Element => {
250252 ) ;
251253} ;
252254
253- const SamlCustomIdentityProviderMetadataStep = ( ) : JSX . Element => (
254- < IdentityProviderMetadataForm
255- modes = { {
256- title : localizationKeys ( 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.modes.title' ) ,
257- ariaLabel : localizationKeys ( 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.modes.ariaLabel' ) ,
258- metadataUrlLabel : localizationKeys (
259- 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.modes.metadataUrl' ,
260- ) ,
261- manualLabel : localizationKeys ( 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.modes.manual' ) ,
262- } }
263- metadataUrl = { {
255+ const SamlCustomIdentityProviderMetadataStep = ( ) : JSX . Element => {
256+ const card = useCardState ( ) ;
257+ const { goNext, goPrev, isFirstStep } = useWizard ( ) ;
258+ const { enterpriseConnection, updateEnterpriseConnection } = useConfigureSSO ( ) ;
259+
260+ const controller = useIdentityProviderMetadataForm ( {
261+ metadataUrl : {
264262 label : localizationKeys ( 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.metadataUrl.label' ) ,
265263 placeholder : localizationKeys (
266264 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.metadataUrl.placeholder' ,
267265 ) ,
268- description : localizationKeys (
269- 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.metadataUrl.description' ,
270- ) ,
271- } }
272- manual = { {
273- description : localizationKeys (
274- 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.description' ,
275- ) ,
266+ } ,
267+ manual : {
276268 signOnUrl : {
277269 label : localizationKeys (
278270 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signOnUrl.label' ,
@@ -289,23 +281,103 @@ const SamlCustomIdentityProviderMetadataStep = (): JSX.Element => (
289281 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.issuer.placeholder' ,
290282 ) ,
291283 } ,
292- signingCertificate : {
293- label : localizationKeys (
294- 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.label' ,
295- ) ,
296- uploadFile : localizationKeys (
297- 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.uploadFile' ,
298- ) ,
299- replaceFile : localizationKeys (
300- 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.replaceFile' ,
301- ) ,
302- removeFile : localizationKeys (
303- 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.removeFile' ,
304- ) ,
305- fileUploaded : localizationKeys (
306- 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.fileUploaded' ,
307- ) ,
308- } ,
309- } }
310- />
311- ) ;
284+ signingCertificateLabel : localizationKeys (
285+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.label' ,
286+ ) ,
287+ } ,
288+ } ) ;
289+
290+ const canSubmit = ! card . isLoading && controller . isValid ;
291+
292+ const handleContinue = async ( ) : Promise < void > => {
293+ if ( ! enterpriseConnection || ! canSubmit ) {
294+ return ;
295+ }
296+
297+ card . setError ( undefined ) ;
298+ card . setLoading ( ) ;
299+
300+ try {
301+ const saml = await controller . buildSamlPayload ( ) ;
302+ await updateEnterpriseConnection ( enterpriseConnection . id , { saml } ) ;
303+ void goNext ( ) ;
304+ } catch ( err ) {
305+ controller . applySubmitError ( err , card ) ;
306+ } finally {
307+ card . setIdle ( ) ;
308+ }
309+ } ;
310+
311+ return (
312+ < >
313+ < Step . Body >
314+ < Step . Section
315+ fill
316+ gap = { 5 }
317+ >
318+ < Heading
319+ elementDescriptor = { descriptors . configureSSOInstructionsHeading }
320+ as = 'h3'
321+ textVariant = 'subtitle'
322+ localizationKey = { localizationKeys (
323+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.modes.title' ,
324+ ) }
325+ />
326+ < IdentityProviderMetadataForm
327+ controller = { controller }
328+ modes = { {
329+ ariaLabel : localizationKeys (
330+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.modes.ariaLabel' ,
331+ ) ,
332+ metadataUrlLabel : localizationKeys (
333+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.modes.metadataUrl' ,
334+ ) ,
335+ manualLabel : localizationKeys (
336+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.modes.manual' ,
337+ ) ,
338+ } }
339+ metadataUrl = { {
340+ description : localizationKeys (
341+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.metadataUrl.description' ,
342+ ) ,
343+ } }
344+ manual = { {
345+ description : localizationKeys (
346+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.description' ,
347+ ) ,
348+ signingCertificate : {
349+ label : localizationKeys (
350+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.label' ,
351+ ) ,
352+ uploadFile : localizationKeys (
353+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.uploadFile' ,
354+ ) ,
355+ replaceFile : localizationKeys (
356+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.replaceFile' ,
357+ ) ,
358+ removeFile : localizationKeys (
359+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.removeFile' ,
360+ ) ,
361+ fileUploaded : localizationKeys (
362+ 'configureSSO.configureStep.samlCustom.identityProviderMetadataStep.manual.signingCertificate.fileUploaded' ,
363+ ) ,
364+ } ,
365+ } }
366+ />
367+ </ Step . Section >
368+ </ Step . Body >
369+
370+ < Step . Footer >
371+ < Step . Footer . Previous
372+ onClick = { ( ) => goPrev ( ) }
373+ isDisabled = { isFirstStep || card . isLoading }
374+ />
375+ < Step . Footer . Continue
376+ onClick = { handleContinue }
377+ isLoading = { card . isLoading }
378+ isDisabled = { ! canSubmit }
379+ />
380+ </ Step . Footer >
381+ </ >
382+ ) ;
383+ } ;
0 commit comments