Skip to content

Commit

Permalink
fix(api-form-builder): skip create fb on new locale if fb not install…
Browse files Browse the repository at this point in the history
…ed on current locale
  • Loading branch information
brunozoric authored and adrians5j committed Dec 19, 2024
1 parent 485f870 commit 46a11e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ export const createFormStorageOperations = (
}
let latestPublishedKeys: Keys | undefined;
const entityBatch = createEntityWriteBatch({
entity
entity,
delete: [createLatestKeys(form)]
});

for (const item of items) {
Expand Down
10 changes: 5 additions & 5 deletions packages/api-form-builder/__tests__/forms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Form Builder "Form" Test', () => {
}
});

test("should create a form and return it in the list of latest forms", async () => {
it("should create a form and return it in the list of latest forms", async () => {
const [create] = await createForm({ data: { name: "contact-us" } });
const { id } = create.data.formBuilder.createForm.data;

Expand Down Expand Up @@ -70,7 +70,7 @@ describe('Form Builder "Form" Test', () => {
expect(data[0].id).toEqual(id);
});

test("should update form and return new data from storage", async () => {
it("should update form and return new data from storage", async () => {
const [create] = await createForm({ data: { name: "contact-us" } });
const { id } = create.data.formBuilder.createForm.data;

Expand Down Expand Up @@ -219,7 +219,7 @@ describe('Form Builder "Form" Test', () => {
expect(revisions[0].version).toEqual(2);
});

test("should delete a form and all of its revisions", async () => {
it("should delete a form and all of its revisions", async () => {
const [create] = await createForm({ data: { name: "contact-us" } });
const { id } = create.data.formBuilder.createForm.data;

Expand All @@ -246,7 +246,7 @@ describe('Form Builder "Form" Test', () => {
expect(list.data.formBuilder.listForms.data.length).toBe(0);
});

test("should publish, add views and unpublish", async () => {
it("should publish, add views and unpublish", async () => {
const [create] = await createForm({ data: { name: "contact-us" } });
const { id } = create.data.formBuilder.createForm.data;

Expand Down Expand Up @@ -306,7 +306,7 @@ describe('Form Builder "Form" Test', () => {
expect(latestPublished3.data.formBuilder.getPublishedForm.data.id).toEqual(id);
});

test("should create, list and export submissions to file", async () => {
it("should create, list and export submissions to file", async () => {
const [create] = await createForm({ data: { name: "contact-us" } });
const { id } = create.data.formBuilder.createForm.data;

Expand Down
6 changes: 6 additions & 0 deletions packages/api-form-builder/src/plugins/crud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export default (params: CreateFormBuilderCrudParams) => {
// Once a new locale is created, we need to create a new settings entry for it.
new ContextPlugin<FormBuilderContext>(async context => {
context.i18n.locales.onLocaleAfterCreate.subscribe(async params => {
// We don't want to auto-create the settings entry if Form Builder is not installed.
// This is because the entry will be created by the app's installer.
const fbIsInstalled = Boolean(await context.formBuilder.getSystemVersion());
if (!fbIsInstalled) {
return;
}
const { locale } = params;
await context.i18n.withLocale(locale, async () => {
return context.formBuilder.createSettings({});
Expand Down

0 comments on commit 46a11e9

Please sign in to comment.