Просмотр исходного кода

Merge pull request #30001 from overleaf/mj-workbench-consent-screen

[web] Add consent screen to workbench

GitOrigin-RevId: 7640154e9c02d340eb9c782e276a84cd961ad755
Mathias Jakobsen 8 месяцев назад
Родитель
Сommit
0c07e5ff40

+ 1 - 0
services/web/app/src/Features/Tutorial/TutorialController.mjs

@@ -8,6 +8,7 @@ const VALID_KEYS = [
   'writefull-oauth-promotion',
   'bib-file-tpr-prompt',
   'ai-error-assistant-consent',
+  'workbench-consent',
   'history-restore-promo',
   'us-gov-banner',
   'us-gov-banner-fedramp',

+ 23 - 8
services/web/frontend/js/shared/hooks/promotions/use-tutorial.tsx

@@ -4,6 +4,17 @@ import { postJSON } from '@/infrastructure/fetch-json'
 import { debugConsole } from '@/utils/debugging'
 import { useEditorContext } from '@/shared/context/editor-context'
 
+type CompleteTutorialParams = {
+  event: string
+  action: 'complete' | 'postpone'
+} & Record<string, any>
+
+type CompleteTutorialOptions = {
+  // Whether to ignore errors if the request fails. Defaults to true. If
+  // successfull completion is required, set this to false.
+  failSilently?: boolean
+}
+
 const useTutorial = (
   tutorialKey: string,
   eventData: Record<string, any> = {}
@@ -14,18 +25,22 @@ const useTutorial = (
     useEditorContext()
 
   const completeTutorial = useCallback(
-    async ({
-      event = 'promo-click',
-      action = 'complete',
-      ...rest
-    }: {
-      event: string
-      action: 'complete' | 'postpone'
-    } & Record<string, any>) => {
+    async (
+      {
+        event = 'promo-click',
+        action = 'complete',
+        ...rest
+      }: CompleteTutorialParams,
+      options: CompleteTutorialOptions = {}
+    ) => {
       eventTracking.sendMB(event, { ...eventData, ...rest })
       try {
         await postJSON(`/tutorial/${tutorialKey}/${action}`)
       } catch (err) {
+        const failSilently = options.failSilently ?? true
+        if (!failSilently) {
+          throw err
+        }
         debugConsole.error(err)
       }
       setShowPopup(false)