From a8f247a02e09f4a6df7b17ee307c2a1be522fa70 Mon Sep 17 00:00:00 2001 From: kajambiya Date: Thu, 21 Dec 2023 12:11:35 +0300 Subject: [PATCH] fix getRegisteredPostSubmissionAction function to handle both custom and inbuilt post submission actions correctly --- src/registry/registry.ts | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/registry/registry.ts b/src/registry/registry.ts index 5c4879944..bbf0bf0ba 100644 --- a/src/registry/registry.ts +++ b/src/registry/registry.ts @@ -124,21 +124,34 @@ export async function getRegisteredFieldSubmissionHandler(type: string): Promise } export async function getRegisteredPostSubmissionAction(actionId: string) { - if (registryCache.postSubmissionActions[actionId]) { - return registryCache.postSubmissionActions[actionId]; + const cachedAction = registryCache.postSubmissionActions[actionId]; + if (cachedAction) { + return cachedAction; } - let lazy = await inbuiltPostSubmissionActions.find((registration) => registration.name === actionId)?.load; - let actionImport = (await lazy()) ?? null; - if (!actionImport) { - lazy = getFormsStore().postSubmissionActions.find((registration) => registration.name === actionId)?.load; - if (lazy) { - actionImport = await lazy(); - registryCache.postSubmissionActions[actionId] = actionImport.default; - } else { - console.error(`No loader found for PostSubmissionAction registration of id: ${actionId}`); - } + + const inbuiltRegistration = inbuiltPostSubmissionActions.find((registration) => registration.name === actionId); + + if (inbuiltRegistration) { + const lazy = inbuiltRegistration.load; + const actionImport = await lazy(); + registryCache.postSubmissionActions[actionId] = actionImport.default; + return actionImport.default; } - return actionImport.default ?? null; + + const formsStoreRegistration = getFormsStore().postSubmissionActions.find( + (registration) => registration.name === actionId, + ); + + if (formsStoreRegistration) { + const lazy = formsStoreRegistration.load; + const actionImport = await lazy(); + registryCache.postSubmissionActions[actionId] = actionImport.default; + return actionImport.default; + } else { + console.error(`No loader found for PostSubmissionAction registration of id: ${actionId}`); + } + + return null; } export async function getRegisteredValidator(name: string): Promise {