Passed
Push — trunk ( 77f064...22dab2 )
by Christian
15:37 queued 01:40
created

index.ts ➔ isAdmin   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
dl 0
loc 3
rs 10
1
import { METRICS_SYSTEM_CONFIG_DOMAIN, ALLOW_USAGE_DATA_SYSTEM_CONFIG_KEY } from 'src/core/service/api/metrics.api.service';
2
import template from './sw-settings-usage-data.html.twig';
3
import './sw-settings-usage-data.scss';
4
5
type CoreMetricsConfigNamespace = {
6
    [ALLOW_USAGE_DATA_SYSTEM_CONFIG_KEY]?: boolean
7
}
8
9
/**
10
 * @private
11
 *
12
 * @package merchant-services
13
 */
14
export default Shopware.Component.wrapComponentConfig({
15
    template,
16
17
    inject: [
18
        'acl',
19
        'systemConfigApiService',
20
    ],
21
22
    data(): { shareUsageData: boolean } {
23
        return {
24
            shareUsageData: false,
25
        };
26
    },
27
28
    computed: {
29
        alertText() {
30
            let alertText = this.$tc('sw-settings-usage-data.general.alertText');
31
32
            if (!this.isAdmin) {
33
                alertText += ` ${this.$tc('sw-settings-usage-data.general.alertTextOnlyAdmins')}`;
34
            }
35
36
            return alertText;
37
        },
38
39
        isAdmin() {
40
            return this.acl.isAdmin();
41
        },
42
    },
43
44
    created() {
45
        void this.createdComponent();
46
    },
47
48
    methods: {
49
        async createdComponent(): Promise<void> {
50
            const config = await this.systemConfigApiService.getValues(
51
                METRICS_SYSTEM_CONFIG_DOMAIN,
52
            ) as CoreMetricsConfigNamespace;
53
54
            this.shareUsageData = config[ALLOW_USAGE_DATA_SYSTEM_CONFIG_KEY] ?? false;
55
        },
56
57
        async saveSystemConfig() {
58
            await this.systemConfigApiService.saveValues({
59
                [ALLOW_USAGE_DATA_SYSTEM_CONFIG_KEY]: this.shareUsageData,
60
            });
61
        },
62
    },
63
});
64