From 5de18f9dc22a67cdc4a745c56430014b09de2c74 Mon Sep 17 00:00:00 2001 From: hamzawaleed01 Date: Mon, 11 Mar 2024 19:17:43 +0500 Subject: [PATCH 1/2] fix: hit updateEnterpriseSsoOrchestrationRecord if errore --- .../SettingsSSOTab/NewExistingSSOConfigs.jsx | 4 ++-- .../SettingsSSOTab/SSOFormWorkflowConfig.tsx | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/settings/SettingsSSOTab/NewExistingSSOConfigs.jsx b/src/components/settings/SettingsSSOTab/NewExistingSSOConfigs.jsx index 792e6913f7..895788f9e2 100644 --- a/src/components/settings/SettingsSSOTab/NewExistingSSOConfigs.jsx +++ b/src/components/settings/SettingsSSOTab/NewExistingSSOConfigs.jsx @@ -161,8 +161,8 @@ const NewExistingSSOConfigs = ({ ); const untested = res.data.filter(config => !config.validated_at || config.validated_at < config.configured_at); const timedOut = res.data.filter(checkTimedOut); - const errored = res.data.filter(checkErrored); - if (timedOut.length >= 1) { + const errored = res.data.filter(checkErrored); + if (timedOut.length >= 1) { setTimedOutConfigs(timedOut); } diff --git a/src/components/settings/SettingsSSOTab/SSOFormWorkflowConfig.tsx b/src/components/settings/SettingsSSOTab/SSOFormWorkflowConfig.tsx index d5bbe5b8c7..ca6ec565b0 100644 --- a/src/components/settings/SettingsSSOTab/SSOFormWorkflowConfig.tsx +++ b/src/components/settings/SettingsSSOTab/SSOFormWorkflowConfig.tsx @@ -105,11 +105,25 @@ export const SSOFormWorkflowConfig = ({ enterpriseId, setConfigureError }) => { }: FormWorkflowHandlerArgs) => { let err = null; - // Accurately detect if form fields have changed - if (!formFieldsChanged) { - // Don't submit if nothing has changed + // Accurately detect if form fields have changed or there's and error in existing record + let isErrored; + if (formFields?.uuid) { + const ssoRecord = + await LmsApiService.fetchEnterpriseSsoOrchestrationRecord( + formFields?.uuid + ).catch(() => { + return { data: {} }; + }); + const { data } = ssoRecord; + isErrored = + data.errored_at && + data.uuid == formFields?.uuid && + data.submitted_at < data.errored_at; + } + if (!isErrored && !formFieldsChanged) { return formFields; } + // else, update enterprise SSO record let updatedFormFields: SSOConfigCamelCase = omit(formFields, ['idpConnectOption', 'spMetadataUrl', 'isPendingConfiguration']); updatedFormFields.enterpriseCustomer = enterpriseId; const submittedFormFields: SSOConfigSnakeCase = snakeCaseDict(updatedFormFields) as SSOConfigSnakeCase; From b88f23411e582e4a1d99e2347ce1e751f391dc25 Mon Sep 17 00:00:00 2001 From: hamzawaleed01 Date: Tue, 12 Mar 2024 13:18:06 +0500 Subject: [PATCH 2/2] refactor: remove unnecessary API call --- .../SettingsSSOTab/SSOFormWorkflowConfig.tsx | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/components/settings/SettingsSSOTab/SSOFormWorkflowConfig.tsx b/src/components/settings/SettingsSSOTab/SSOFormWorkflowConfig.tsx index ca205428d9..6f2bde79b1 100644 --- a/src/components/settings/SettingsSSOTab/SSOFormWorkflowConfig.tsx +++ b/src/components/settings/SettingsSSOTab/SSOFormWorkflowConfig.tsx @@ -64,6 +64,7 @@ export type SSOConfigCamelCase = { submittedAt: null, configuredAt: null, validatedAt: null, + erroredAt: null, odataApiTimeoutInterval: null, odataApiRootUrl: string, odataCompanyId: string, @@ -108,16 +109,10 @@ export const SSOFormWorkflowConfig = ({ enterpriseId, setConfigureError }) => { // Accurately detect if form fields have changed or there's and error in existing record let isErrored; if (formFields?.uuid) { - const ssoRecord = - await LmsApiService.fetchEnterpriseSsoOrchestrationRecord( - formFields?.uuid - ).catch(() => { - return { data: {} }; - }); - const { data } = ssoRecord; isErrored = - data.errored_at && - data.submitted_at < data.errored_at; + formFields.erroredAt && + formFields.submittedAt && + formFields.submittedAt < formFields.erroredAt; } if (!isErrored && !formFieldsChanged) { return formFields;