diff --git a/web/app/components/new/doc-form.ts b/web/app/components/new/doc-form.ts index d1eaeb714..b9df39b13 100644 --- a/web/app/components/new/doc-form.ts +++ b/web/app/components/new/doc-form.ts @@ -15,8 +15,6 @@ import cleanString from "hermes/utils/clean-string"; import { ProductArea } from "hermes/services/product-areas"; import { next } from "@ember/runloop"; import HermesFlashMessagesService from "hermes/services/flash-messages"; -import { ModelFrom } from "hermes/types/route-models"; -import AuthenticatedNewRoute from "hermes/routes/authenticated/new"; import DocumentTypesService from "hermes/services/document-types"; interface DocFormErrors { @@ -25,7 +23,6 @@ interface DocFormErrors { } const AWAIT_DOC_DELAY = Ember.testing ? 0 : 2000; -const AWAIT_DOC_CREATED_MODAL_DELAY = Ember.testing ? 0 : 1500; interface NewDocFormComponentSignature { Args: { @@ -224,15 +221,23 @@ export default class NewDocFormComponent extends Component { + if (this.configSvc.config.create_docs_as_user) { + this.flashMessages.success("", { + title: "Draft created!", + }); + } else { + /** + * If `create_docs_as_user` is false, show a modal alert + * explaining the limitations on notifications. + */ + this.modalAlerts.setActive.perform("draftCreated"); + } + }); } catch (e) { this.docIsBeingCreated = false; diff --git a/web/app/config/environment.d.ts b/web/app/config/environment.d.ts index e61323dc5..b24e648da 100644 --- a/web/app/config/environment.d.ts +++ b/web/app/config/environment.d.ts @@ -16,6 +16,7 @@ export interface HermesConfig { draftsIndexName: string; internalIndexName: string; }; + createDocsAsUser: boolean; featureFlags: Record; google: { docFolders: string; diff --git a/web/app/services/config.ts b/web/app/services/config.ts index 9bc96c152..2517761cb 100644 --- a/web/app/services/config.ts +++ b/web/app/services/config.ts @@ -7,6 +7,7 @@ export default class ConfigService extends Service { algolia_drafts_index_name: config.algolia.draftsIndexName, algolia_internal_index_name: config.algolia.internalIndexName, api_version: "v1", + create_docs_as_user: config.createDocsAsUser, feature_flags: config.featureFlags, google_doc_folders: config.google.docFolders ?? "", short_link_base_url: config.shortLinkBaseURL, diff --git a/web/tests/acceptance/authenticated/new/doc-test.ts b/web/tests/acceptance/authenticated/new/doc-test.ts index dbe8452c6..e9eabc0c1 100644 --- a/web/tests/acceptance/authenticated/new/doc-test.ts +++ b/web/tests/acceptance/authenticated/new/doc-test.ts @@ -15,6 +15,7 @@ import { Response } from "miragejs"; import RouterService from "@ember/routing/router-service"; import window from "ember-window-mock"; import { DRAFT_CREATED_LOCAL_STORAGE_KEY } from "hermes/components/modals/draft-created"; +import { TEST_WEB_CONFIG } from "hermes/utils/mirage-utils"; // Selectors const DOC_FORM = "[data-test-new-doc-form]"; @@ -170,7 +171,31 @@ module("Acceptance | authenticated/new/doc", function (hooks) { assert.dom(PRODUCT_SELECT_TOGGLE).includesText("Terraform"); }); - test("it shows a confirmation modal when a draft is created", async function (this: AuthenticatedNewDocRouteTestContext, assert) { + test("it shows a confirmation flash message when a draft is created (when creating draft as the user)", async function (this: AuthenticatedNewDocRouteTestContext, assert) { + this.server.get("/web/config", () => { + return new Response( + 200, + {}, + JSON.stringify({ ...TEST_WEB_CONFIG, create_docs_as_user: true }), + ); + }); + + this.server.createList("product", 1); + + await visit("/new/doc?docType=RFC"); + + await fillIn(TITLE_INPUT, "Foo"); + await click(PRODUCT_SELECT_TOGGLE); + await click(FIRST_PRODUCT_SELECT_ITEM_BUTTON); + + await click(CREATE_BUTTON); + + await waitFor(FLASH_NOTIFICATION); + + assert.dom(FLASH_NOTIFICATION).hasText("Draft created!"); + }); + + test("it shows a confirmation modal when a draft is created (not creating doc as user)", async function (this: AuthenticatedNewDocRouteTestContext, assert) { // Reset the localStorage item window.localStorage.removeItem(DRAFT_CREATED_LOCAL_STORAGE_KEY);