@localazy/strapi-plugin 0.1.7 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/.github/workflows/.build.yml +2 -13
  2. package/.nvmrc +1 -1
  3. package/admin/src/modules/@common/components/PluginPageLoader/index.js +22 -0
  4. package/admin/src/modules/@common/services/product-analytics-service.js +67 -0
  5. package/admin/src/modules/@common/utils/format-number.js +1 -0
  6. package/admin/src/modules/plugin-settings/components/ContentTransferSetup/index.js +33 -22
  7. package/admin/src/modules/plugin-settings/components/ContentTransferSetupEmpty/index.js +86 -0
  8. package/admin/src/modules/plugin-settings/components/Tree/index.js +10 -1
  9. package/admin/src/modules/plugin-settings/locale/en.js +7 -0
  10. package/admin/src/modules/plugin-settings/services/plugin-settings-service.js +23 -0
  11. package/admin/src/pages/App/index.js +4 -2
  12. package/admin/src/pages/Download/index.js +16 -1
  13. package/admin/src/pages/Login/index.js +8 -1
  14. package/admin/src/pages/Settings/index.js +17 -3
  15. package/admin/src/pages/Upload/index.js +17 -1
  16. package/admin/src/plugins/analytics-service.js +14 -0
  17. package/admin/src/utils/createPluginConnectorAxiosInstance.js +45 -0
  18. package/package.json +4 -4
  19. package/server/config/index.js +10 -5
  20. package/server/config/local/index.js +15 -0
  21. package/server/controllers/localazy-transfer-controller.js +5 -2
  22. package/server/controllers/plugin-settings-controller.js +14 -0
  23. package/server/db/model/plugin-settings.js +13 -0
  24. package/server/routes/plugin-settings.js +16 -0
  25. package/server/services/plugin-settings-service.js +28 -7
  26. package/server/utils/__tests__/parsed-localazy-entry-to-create-entry.test.js +58 -88
  27. package/server/utils/__tests__/parsed-localazy-entry-to-update-entry.test.js +79 -132
  28. package/server/utils/parsed-localazy-entry-to-create-entry.js +23 -6
  29. package/server/utils/parsed-localazy-entry-to-update-entry.js +5 -1
  30. package/server/utils/pick-entries.js +2 -1
  31. package/server/utils/reset-array-keys-deep.js +19 -0
@@ -10,20 +10,9 @@ jobs:
10
10
  run: pwd && sudo chown -R $USER:$USER ./
11
11
  - uses: actions/checkout@v2
12
12
  - name: Setup Node.js environment
13
- uses: actions/setup-node@v1.4.4
13
+ uses: actions/setup-node@v3
14
14
  with:
15
- node-version: 14.x
16
- - name: Cache node modules
17
- uses: actions/cache@v1
18
- env:
19
- cache-name: cache-node-modules
20
- with:
21
- path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
22
- key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
23
- restore-keys: |
24
- ${{ runner.os }}-build-${{ env.cache-name }}-
25
- ${{ runner.os }}-build-
26
- ${{ runner.os }}-
15
+ node-version: 14.x
27
16
  - name: Install dependencies
28
17
  run: npm ci
29
18
  - name: Run unit tests
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- 14
1
+ 16
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { Flex } from '@strapi/design-system/Flex';
3
+ import { Loader } from "@strapi/design-system/Loader";
4
+ import { useTranslation } from "react-i18next";
5
+
6
+ import "../../../../i18n";
7
+
8
+ function PluginPageLoader() {
9
+ const { t } = useTranslation();
10
+
11
+ return (
12
+ <Flex
13
+ marginTop={10}
14
+ alignItems="center"
15
+ justifyContent="center"
16
+ >
17
+ <Loader>{t("common.loading_content")}</Loader>
18
+ </Flex>
19
+ )
20
+ }
21
+
22
+ export default PluginPageLoader;
@@ -0,0 +1,67 @@
1
+ import AnalyticsService from "../../../plugins/analytics-service";
2
+
3
+ export default class ProductAnalyticsService {
4
+ static async trackAppConnected(userId, project, params = {}) {
5
+ try {
6
+ const data = this.buildData(userId, "Strapi Connected", project, params);
7
+ await AnalyticsService.trackEvent(data.event, {
8
+ ...data.data,
9
+ userId,
10
+ category: "Project",
11
+ });
12
+ } catch (e) {
13
+ console.warn(e);
14
+ }
15
+ }
16
+
17
+ static async trackAppDisconnected(userId, project, params = {}) {
18
+ try {
19
+ const data = this.buildData(userId, "Strapi Disconnected", project, params);
20
+ await AnalyticsService.trackEvent(data.event, {
21
+ ...data.data,
22
+ userId,
23
+ category: "Project",
24
+ });
25
+ } catch (e) {
26
+ console.warn(e);
27
+ }
28
+ }
29
+
30
+ static async trackUploadToLocalazy(userId, project, params = {}) {
31
+ try {
32
+ const data = this.buildData(userId, "Strapi Upload", project, params);
33
+ await AnalyticsService.trackEvent(data.event, {
34
+ ...data.data,
35
+ userId,
36
+ category: "Project",
37
+ });
38
+ } catch (e) {
39
+ console.warn(e);
40
+ }
41
+ }
42
+
43
+ static async trackDownloadToStrapi(userId, project, params = {}) {
44
+ try {
45
+ const data = this.buildData(userId, "Strapi Download", project, params);
46
+ await AnalyticsService.trackEvent(data.event, {
47
+ ...data.data,
48
+ userId,
49
+ category: "Project",
50
+ });
51
+ } catch (e) {
52
+ console.warn(e);
53
+ }
54
+ }
55
+
56
+ static buildData(userId, event, project, params) {
57
+ return {
58
+ event,
59
+ data: {
60
+ "User Id": userId,
61
+ "Project Id": project.id,
62
+ "Project Name": project.name,
63
+ ...params,
64
+ },
65
+ };
66
+ }
67
+ }
@@ -0,0 +1 @@
1
+ export default (value, options = undefined) => new Intl.NumberFormat("en-GB", options).format(value);
@@ -21,6 +21,7 @@ import hasModelChanged from "../../functions/has-model-changed";
21
21
  import buildContentTransferSetupSchema from "../../functions/build-content-transfer-setup-schema";
22
22
  import { getLocalazyIdentity } from "../../../../state/localazy-identity";
23
23
  import Tree from "../Tree";
24
+ import ContentTransferSetupEmpty from "../ContentTransferSetupEmpty";
24
25
 
25
26
  import "../../../../i18n";
26
27
 
@@ -28,7 +29,6 @@ function ContentTransferSetup() {
28
29
  /**
29
30
  * Translation function
30
31
  */
31
- // eslint-disable-next-line no-unused-vars
32
32
  const { t } = useTranslation();
33
33
 
34
34
  /**
@@ -250,6 +250,10 @@ function ContentTransferSetup() {
250
250
  shadow="tableShadow"
251
251
  hasRadius
252
252
  >
253
+ {!formModel.length && (
254
+ // empty state
255
+ <ContentTransferSetupEmpty />
256
+ )}
253
257
  {formModel.map((tree, index) => {
254
258
  return (
255
259
  <Box
@@ -257,30 +261,37 @@ function ContentTransferSetup() {
257
261
  key={`box_tree_${index}`}
258
262
  marginBottom={3}
259
263
  >
260
- <Tree onTreeItemClick={onTreeItemClick} objects={tree} />
264
+ <Tree
265
+ onTreeItemClick={onTreeItemClick}
266
+ objects={tree}
267
+ initiallyExpanded={index === 0} />
261
268
  </Box>
262
269
  );
263
270
  })}
264
- <Box
265
- paddingTop={6}
266
- paddingBottom={6}
267
- >
268
- <Divider />
269
- </Box>
270
- <Typography variant="omega">{t("plugin_settings.you_can_upload_download")}</Typography>
271
- <Typography variant="omega" fontWeight="semiBold">{t("plugin_settings.only_text_based_content")}</Typography>
272
- <br />
273
- <br />
274
- <Typography variant="omega">{t("plugin_settings.learn_more_in_docs_message_a")}</Typography>
275
- <Typography
276
- onClick={onReadDocumentationClick}
277
- variant="omega"
278
- fontWeight="semiBold"
279
- textColor="primary600"
280
- style={{ cursor: "pointer" }}
281
- >
282
- {t("plugin_settings.learn_more_in_docs_message_b")}
283
- </Typography>
271
+ {!!formModel.length && (
272
+ <Box>
273
+ <Box
274
+ paddingTop={6}
275
+ paddingBottom={6}
276
+ >
277
+ <Divider />
278
+ </Box>
279
+ <Typography variant="omega">{t("plugin_settings.you_can_upload_download")}</Typography>
280
+ <Typography variant="omega" fontWeight="semiBold">{t("plugin_settings.only_text_based_content")}</Typography>
281
+ <br />
282
+ <br />
283
+ <Typography variant="omega">{t("plugin_settings.learn_more_in_docs_message_a")}</Typography>
284
+ <Typography
285
+ onClick={onReadDocumentationClick}
286
+ variant="omega"
287
+ fontWeight="semiBold"
288
+ textColor="primary600"
289
+ style={{ cursor: "pointer" }}
290
+ >
291
+ {t("plugin_settings.learn_more_in_docs_message_b")}
292
+ </Typography>
293
+ </Box>
294
+ )}
284
295
  </Box>
285
296
  )
286
297
  }
@@ -0,0 +1,86 @@
1
+ import React from "react";
2
+ import { useTranslation, Trans } from "react-i18next";
3
+ import styled from 'styled-components';
4
+ import { Typography, Flex } from "@strapi/design-system";
5
+ import Dot from '@strapi/icons/Dot';
6
+
7
+ const CustomBullet = styled(Dot)`
8
+ width: ${12 / 16}rem;
9
+ height: ${4 / 16}rem;
10
+ margin-right: ${4 / 16}rem;
11
+ * {
12
+ fill: ${({ theme, $active }) => ($active ? theme.colors.primary600 : theme.colors.neutral600)};
13
+ }
14
+ `;
15
+
16
+ function ContentTransferSetupEmpty() {
17
+ const { t } = useTranslation();
18
+
19
+ return (
20
+ <div>
21
+ <Typography
22
+ textColor="neutral600"
23
+ variant="beta"
24
+ >
25
+ {t("plugin_settings.there_is_nothing_to_transfer")}
26
+ </Typography>
27
+ <br />
28
+ <br />
29
+ <Typography
30
+ textColor="neutral600"
31
+ variant="omega"
32
+ >
33
+ {t("plugin_settings.please_check_that_you_have_entered_a_valid_collection")}
34
+ </Typography>
35
+ <br />
36
+ <Flex marginTop={1} alignItems="center">
37
+ <CustomBullet />
38
+ <Typography
39
+ textColor="neutral600"
40
+ variant="omega"
41
+ >
42
+ <Trans i18nKey="plugin_settings.step_1" components={{ 1: <Typography variant="omega" fontWeight="semiBold" /> }} />
43
+ </Typography>
44
+ </Flex>
45
+ <Flex marginTop={1} alignItems="center">
46
+ <CustomBullet />
47
+
48
+ <Typography
49
+ textColor="neutral600"
50
+ variant="omega"
51
+ >
52
+ <Trans i18nKey="plugin_settings.step_2" components={{ 1: <Typography variant="omega" fontWeight="semiBold" /> }} />
53
+ </Typography>
54
+ </Flex>
55
+ <Flex marginTop={1} alignItems="center">
56
+ <CustomBullet />
57
+ <Typography
58
+ textColor="neutral600"
59
+ variant="omega"
60
+ >
61
+ <Trans i18nKey="plugin_settings.step_3" components={{ 1: <Typography variant="omega" fontWeight="semiBold" /> }} />
62
+ </Typography>
63
+ </Flex>
64
+ <Flex marginTop={1} alignItems="center">
65
+ <CustomBullet />
66
+ <Typography
67
+ textColor="neutral600"
68
+ variant="omega"
69
+ >
70
+ <Trans i18nKey="plugin_settings.step_4" components={{ 1: <Typography variant="omega" fontWeight="semiBold" /> }} />
71
+ </Typography>
72
+ </Flex>
73
+ <Flex marginTop={1} alignItems="center">
74
+ <CustomBullet />
75
+ <Typography
76
+ textColor="neutral600"
77
+ variant="omega"
78
+ >
79
+ <Trans i18nKey="plugin_settings.step_5" components={{ 1: <Typography variant="omega" fontWeight="semiBold" /> }} />
80
+ </Typography>
81
+ </Flex>
82
+ </div >
83
+ );
84
+ }
85
+
86
+ export default ContentTransferSetupEmpty;
@@ -1,4 +1,4 @@
1
- import React, { useState } from "react";
1
+ import React, { useState, useEffect } from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import { Box } from "@strapi/design-system/Box";
4
4
  import { Switch } from '@strapi/design-system/Switch';
@@ -13,6 +13,10 @@ function Tree(props) {
13
13
  props.onTreeItemClick(key, currentValue);
14
14
  };
15
15
 
16
+ useEffect(() => {
17
+ setIsExpanded(props.initiallyExpanded);
18
+ }, [props.initiallyExpanded]);
19
+
16
20
  const createTree = (name, branch, path = "") => {
17
21
  const isBranchObject = typeof branch === "object" && branch !== null;
18
22
 
@@ -115,6 +119,11 @@ function Tree(props) {
115
119
  Tree.propTypes = {
116
120
  objects: PropTypes.object.isRequired,
117
121
  onTreeItemClick: PropTypes.func.isRequired,
122
+ initiallyExpanded: PropTypes.bool,
123
+ };
124
+
125
+ Tree.defaultProps = {
126
+ initiallyExpanded: false,
118
127
  };
119
128
 
120
129
  export default Tree;
@@ -16,4 +16,11 @@ export default {
16
16
  only_text_based_content: "only text based content.",
17
17
  learn_more_in_docs_message_a: "If you want to learn more about how to setup your Content Transfer settings read the ",
18
18
  learn_more_in_docs_message_b: "Localazy documentation.",
19
+ there_is_nothing_to_transfer: "There is nothing to transfer.",
20
+ please_check_that_you_have_entered_a_valid_collection: "To finish the content transfer setup, you must enable localization for at least one Content-Type.",
21
+ step_1: "Go to the <1>Content-Type Builder</1>",
22
+ step_2: "Click on <1>Edit</1> and select the <1>Advanced Settings</1> tab",
23
+ step_3: "Check <1>Enable localization for this Content-Type</1>",
24
+ step_4: "Repeat for all Content-Types you want to translate",
25
+ step_5: "Return to this screen and finish the transfer setup",
19
26
  };
@@ -29,4 +29,27 @@ export default class PluginSettingsService {
29
29
  throw e;
30
30
  }
31
31
  }
32
+
33
+ static async getPluginSettings() {
34
+ try {
35
+ const result = await axiosInstance.get(`${BASE_PATH}/plugin-settings`);
36
+
37
+ return result.data;
38
+ } catch (e) {
39
+ throw e;
40
+ }
41
+ }
42
+
43
+ static async updatePluginSettings(data) {
44
+ try {
45
+ const result = await axiosInstance.put(
46
+ `${BASE_PATH}/plugin-settings`,
47
+ data
48
+ );
49
+
50
+ return result.data;
51
+ } catch (e) {
52
+ throw e;
53
+ }
54
+ }
32
55
  }
@@ -12,8 +12,8 @@ import { ThemeProvider } from "@strapi/design-system/ThemeProvider";
12
12
  import { lightTheme } from "@strapi/design-system/themes";
13
13
  import { Box } from "@strapi/design-system/Box";
14
14
  import { Layout } from "@strapi/design-system/Layout";
15
- import { Loader } from "@strapi/design-system/Loader";
16
15
  import { useTranslation } from "react-i18next";
16
+ import Loader from "../../modules/@common/components/PluginPageLoader";
17
17
  import pluginId from "../../pluginId";
18
18
  import Download from "../Download";
19
19
  import Settings from "../Settings";
@@ -32,6 +32,7 @@ import {
32
32
  getLocalazyIdentity,
33
33
  } from "../../state/localazy-identity";
34
34
  import history from "../../modules/@common/utils/history";
35
+ import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";
35
36
 
36
37
  import "../../i18n";
37
38
 
@@ -89,7 +90,8 @@ function App() {
89
90
  if (!hasLocalazyIdentity()) {
90
91
  redirectToPluginRoute(PLUGIN_ROUTES.LOGIN);
91
92
  } else {
92
- redirectToPluginRoute(PLUGIN_ROUTES.DOWNLOAD);
93
+ const lastRoute = (await PluginSettingsService.getPluginSettings()).defaultRoute || PLUGIN_ROUTES.UPLOAD;
94
+ redirectToPluginRoute(lastRoute);
93
95
  }
94
96
  }
95
97
  }
@@ -5,11 +5,11 @@ import { Button } from "@strapi/design-system/Button";
5
5
  import DownloadIcon from "@strapi/icons/Download";
6
6
  import { Box } from "@strapi/design-system/Box";
7
7
  import { Alert } from "@strapi/design-system/Alert";
8
- import { Loader } from "@strapi/design-system/Loader";
9
8
  import { useTranslation } from "react-i18next";
10
9
  import { Flex } from '@strapi/design-system/Flex';
11
10
  import { Divider } from '@strapi/design-system/Divider';
12
11
  import { Typography } from "@strapi/design-system/Typography";
12
+ import Loader from "../../modules/@common/components/PluginPageLoader";
13
13
  import LocalazyDownloadService from "../../modules/localazy-download/services/localazy-download-service";
14
14
  import areLocalesCompatible from "../../modules/@common/utils/are-locales-compatible";
15
15
  import hasModelChanged from "../../modules/plugin-settings/functions/has-model-changed";
@@ -17,6 +17,9 @@ import TransferReport from "../../modules/@common/components/TransferReport";
17
17
  import ReadDocsButton from "../../modules/localazy-upload/components/ReadDocsButton";
18
18
  import "../../i18n";
19
19
  import { getLocalazyIdentity } from "../../state/localazy-identity";
20
+ import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
21
+ import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";
22
+ import { PLUGIN_ROUTES } from "../../modules/@common/utils/redirect-to-plugin-route";
20
23
 
21
24
  function Download(props) {
22
25
  const { t } = useTranslation();
@@ -44,6 +47,16 @@ function Download(props) {
44
47
  setIsDownloading(true);
45
48
  const result = await LocalazyDownloadService.download();
46
49
  setDownloadResult(result);
50
+
51
+ // track download
52
+ ProductAnalyticsService.trackDownloadToStrapi(
53
+ localazyIdentity.user.id,
54
+ localazyIdentity.project,
55
+ {
56
+ "Target Languages Codes": "all",
57
+ }
58
+ );
59
+
47
60
  setIsDownloading(false);
48
61
  setshowDownloadFinishedModal(true);
49
62
  };
@@ -58,6 +71,8 @@ function Download(props) {
58
71
  setModelChanged(await hasModelChanged());
59
72
  setLocalesIncompatible(!(await areLocalesCompatible()));
60
73
 
74
+ PluginSettingsService.updatePluginSettings({ defaultRoute: PLUGIN_ROUTES.DOWNLOAD });
75
+
61
76
  setIsLoading(false);
62
77
  }
63
78
  initComponent();
@@ -6,19 +6,20 @@
6
6
 
7
7
  import React from "react";
8
8
  import PropTypes from "prop-types";
9
- import { Loader } from "@strapi/design-system/Loader";
10
9
  import { Link } from "@strapi/design-system/Link";
11
10
  import { useHistory } from "react-router-dom";
12
11
  import { useTranslation } from "react-i18next";
13
12
  import { HeaderLayout } from "@strapi/design-system/Layout";
14
13
  import { Box } from "@strapi/design-system/Box";
15
14
  import { Typography } from "@strapi/design-system/Typography";
15
+ import Loader from "../../modules/@common/components/PluginPageLoader";
16
16
  import { setLocalazyIdentity } from "../../state/localazy-identity";
17
17
  import LocalazyUserService from "../../modules/user/services/localazy-user-service";
18
18
  import LoginButton from "../../modules/login/components/LoginButton";
19
19
  import redirectToPluginRoute, {
20
20
  PLUGIN_ROUTES,
21
21
  } from "../../modules/@common/utils/redirect-to-plugin-route";
22
+ import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
22
23
 
23
24
  import "../../i18n";
24
25
 
@@ -40,6 +41,12 @@ function Login(props) {
40
41
  setLocalazyIdentity(result);
41
42
 
42
43
  if (result.accessToken) {
44
+ // track user login
45
+ ProductAnalyticsService.trackAppConnected(
46
+ result.user.id,
47
+ result.project,
48
+ );
49
+
43
50
  redirectToPluginRoute(PLUGIN_ROUTES.DOWNLOAD, history);
44
51
  }
45
52
  };
@@ -1,12 +1,12 @@
1
1
  import React, { useEffect, useState } from "react";
2
2
  import PropTypes from "prop-types";
3
- import { Loader } from "@strapi/design-system/Loader";
4
3
  import { HeaderLayout } from "@strapi/design-system/Layout";
5
4
  import { Box } from "@strapi/design-system/Box";
6
5
  import { useHistory } from "react-router-dom";
7
6
  import { useTranslation } from "react-i18next";
8
7
  import { Grid } from '@strapi/design-system/Grid';
9
8
  import { Divider } from '@strapi/design-system/Divider';
9
+ import Loader from "../../modules/@common/components/PluginPageLoader";
10
10
  import LogoutButton from "../../modules/login/components/LogoutButton";
11
11
  import redirectToPluginRoute, {
12
12
  PLUGIN_ROUTES,
@@ -16,6 +16,9 @@ import OverviewItem from "../../modules/settings/components/OverviewItem";
16
16
  import OverviewItemLink from "../../modules/settings/components/OverviewItemLink";
17
17
  import PrerequisitiesInfo from "../../modules/settings/components/PrerequisitiesInfo";
18
18
  import ProjectService from "../../modules/@common/services/project-service";
19
+ import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
20
+ import formatNumber from "../../modules/@common/utils/format-number";
21
+ import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";
19
22
 
20
23
  import "../../i18n";
21
24
 
@@ -35,6 +38,9 @@ function Settings(props) {
35
38
  setIsLoading(true);
36
39
  const project = await ProjectService.getConnectedProject();
37
40
  setConnectedProject(project);
41
+
42
+ PluginSettingsService.updatePluginSettings({ defaultRoute: PLUGIN_ROUTES.SETTINGS });
43
+
38
44
  setIsLoading(false);
39
45
  }
40
46
 
@@ -45,6 +51,12 @@ function Settings(props) {
45
51
  * On logout action
46
52
  */
47
53
  const onLoggedOut = () => {
54
+ // track user logout
55
+ ProductAnalyticsService.trackAppDisconnected(
56
+ localazyIdentity.user.id,
57
+ localazyIdentity.project,
58
+ );
59
+
48
60
  redirectToPluginRoute(PLUGIN_ROUTES.LOGIN, history);
49
61
  };
50
62
 
@@ -56,7 +68,9 @@ function Settings(props) {
56
68
  primaryAction={<LogoutButton onResultFetched={onLoggedOut} />}
57
69
  as="h2"
58
70
  />
59
- {(props.isLoading || isLoading) && (<Loader>{t("common.loading_content")}</Loader>)}
71
+ {(props.isLoading || isLoading) && (
72
+ <Loader>{t("common.loading_content")}</Loader>
73
+ )}
60
74
  {!(props.isLoading || isLoading) && (
61
75
  <Box paddingRight={10} paddingLeft={10}>
62
76
  <Box
@@ -86,7 +100,7 @@ function Settings(props) {
86
100
  <OverviewItem
87
101
  label={t("settings.remaining_organization_keys")}
88
102
  value={
89
- connectedProject.organization.availableKeys - connectedProject.organization.usedKeys
103
+ formatNumber(connectedProject.organization.availableKeys - connectedProject.organization.usedKeys)
90
104
  }
91
105
  />
92
106
  <OverviewItemLink
@@ -9,7 +9,7 @@ import { Button } from "@strapi/design-system/Button";
9
9
  import UploadIcon from "@strapi/icons/Upload";
10
10
  import { Box } from "@strapi/design-system/Box";
11
11
  import { Alert } from "@strapi/design-system/Alert";
12
- import { Loader } from "@strapi/design-system/Loader";
12
+ import Loader from "../../modules/@common/components/PluginPageLoader";
13
13
  import LocalazyUploadService from "../../modules/localazy-upload/services/localazy-upload-service";
14
14
  import areLocalesCompatible from "../../modules/@common/utils/are-locales-compatible";
15
15
  import { getStrapiDefaultLocale, getLocalazySourceLanguage } from "../../modules/@common/utils/get-default-locale";
@@ -21,6 +21,9 @@ import ReadDocsButton from "../../modules/localazy-upload/components/ReadDocsBut
21
21
  import redirectToPluginRoute, {
22
22
  PLUGIN_ROUTES,
23
23
  } from "../../modules/@common/utils/redirect-to-plugin-route";
24
+ import { getLocalazyIdentity } from "../../state/localazy-identity";
25
+ import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
26
+ import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";
24
27
 
25
28
  import "../../i18n";
26
29
 
@@ -38,6 +41,7 @@ function Upload(props) {
38
41
  const [isUploading, setIsUploading] = useState(false);
39
42
  const [strapiDefaultLocale, setStrapiDefaultLocale] = useState(null);
40
43
  const [localazySourceLanguage, setLocalazySourceLanguage] = useState(null);
44
+ const [localazyIdentity] = getLocalazyIdentity();
41
45
 
42
46
  const onChangeSettingsClick = () => {
43
47
  redirectToPluginRoute(PLUGIN_ROUTES.CONTENT_TRANSFER_SETUP);
@@ -49,6 +53,16 @@ function Upload(props) {
49
53
  setIsUploading(true);
50
54
  const result = await LocalazyUploadService.upload();
51
55
  setUploadResult(result);
56
+
57
+ // track upload
58
+ ProductAnalyticsService.trackUploadToLocalazy(
59
+ localazyIdentity.user.id,
60
+ localazyIdentity.project,
61
+ {
62
+ "Source Language Code": localazySourceLanguage.code,
63
+ }
64
+ );
65
+
52
66
  setIsUploading(false);
53
67
  setShowUploadFinishedModal(true);
54
68
  };
@@ -66,6 +80,8 @@ function Upload(props) {
66
80
  setModelChanged(await hasModelChanged());
67
81
  setLocalesIncompatible(!(await areLocalesCompatible(strapiDefaultLocale, localazySourceLanguage)));
68
82
 
83
+ PluginSettingsService.updatePluginSettings({ defaultRoute: PLUGIN_ROUTES.UPLOAD });
84
+
69
85
  setIsLoading(false);
70
86
  }
71
87
  initComponent();
@@ -0,0 +1,14 @@
1
+ import createPluginConnectorAxiosInstance from "../utils/createPluginConnectorAxiosInstance";
2
+
3
+ const ANALYTICS_PATH = "/analytics";
4
+ const axiosInstance = createPluginConnectorAxiosInstance();
5
+ export default class AnalyticsService {
6
+ static async trackEvent(event, data) {
7
+ const result = await axiosInstance.post(`${ANALYTICS_PATH}/track`, {
8
+ event,
9
+ ...data,
10
+ });
11
+
12
+ return result.data;
13
+ }
14
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * axios with plugin connector config.
3
+ */
4
+
5
+ import axios from "axios";
6
+ import { config } from "../../../server";
7
+
8
+ const BASE_PLUGIN_PATH = config.default.LOCALAZY_PLUGIN_CONNECTOR_API_URL;
9
+
10
+ const createPluginConnectorAxiosInstance = (baseUrl = null) => {
11
+ if (baseUrl === null) {
12
+ baseUrl = `${BASE_PLUGIN_PATH}`;
13
+ }
14
+
15
+ const instance = axios.create({
16
+ baseURL: baseUrl,
17
+ });
18
+
19
+ instance.interceptors.request.use(
20
+ async (config) => {
21
+ config.headers = {
22
+ Accept: "application/json",
23
+ "Content-Type": "application/json",
24
+ // Strapi plugin id in terms of plugin connector
25
+ "X-Localazy-Plugin-Id": 1,
26
+ };
27
+
28
+ return config;
29
+ },
30
+ (error) => {
31
+ Promise.reject(error);
32
+ }
33
+ );
34
+
35
+ instance.interceptors.response.use(
36
+ (response) => response,
37
+ (error) => {
38
+ throw error;
39
+ }
40
+ );
41
+
42
+ return instance;
43
+ };
44
+
45
+ export default createPluginConnectorAxiosInstance;