summaryrefslogtreecommitdiff
path: root/src/jet/intents/static-message-pages/invoice-page-intent-controller.ts
blob: caa02f4af7a1dbee920cecbaa080f03031a56133 (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
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: 'InvoicePageIntent',
    }),
    '/invoice',
);

export const InvoicePageIntentController: IntentController<any> &
    RouteProvider = {
    $intentKind: 'InvoicePageIntent',

    routes,

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

                page.canonicalURL = makeCanonicalUrl(objectGraph, intent);

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