Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix getRegisteredPostSubmissionAction function to handle both custom and inbuilt post submission actions correctly #160

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions src/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FieldValidator> {
Expand Down
Loading