summaryrefslogtreecommitdiff
path: root/src/jet/intents/static-message-pages/win-back-page-intent-controller.ts
blob: 2b78ba07148f2e8a4f47b9ba15c0ec85da57e268 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import type { IntentController } from '@jet/environment/dispatching';
import type { RouteProvider } from '@jet/environment/routing';
import type { AppStoreObjectGraph } from '@jet-app/app-store/foundation/runtime/app-store-object-graph';
import { withActiveIntent } from '@jet-app/app-store/foundation/dependencies/active-intent';
import { generateRoutes } from '@jet-app/app-store/common/util/generate-routes';
import { injectWebNavigation } from '@jet-app/app-store/common/web-navigation/inject-web-navigation';

import { StaticMessagePage } from '~/jet/models/static-message-page';

const { routes, makeCanonicalUrl } = generateRoutes(
    (opts) => ({
        ...opts,
        $kind: 'WinBackPageIntent',
    }),
    '/win-back/{offerId}',
    [],
    {
        extraRules: [
            {
                regex: [/(?:\/[a-z]{2})?\/win-back/],
            },
        ],
    },
);

export const WinBackPageIntentController: IntentController<any> &
    RouteProvider = {
    $intentKind: 'WinBackPageIntent',

    routes,

    async perform(intent, objectGraphWithoutActiveIntent: AppStoreObjectGraph) {
        return await withActiveIntent(
            objectGraphWithoutActiveIntent,
            intent,
            async (objectGraph) => {
                const page = new StaticMessagePage({
                    titleLocKey: 'ASE.Web.AppStore.WinBack.Title',
                    contentType: 'win-back',
                });

                page.canonicalURL = makeCanonicalUrl(objectGraph, intent);

                injectWebNavigation(objectGraph, page, intent.platform);
                return page;
            },
        );
    },
};