From db4036bc4dfc741d8fe8e8c3f1259e2c83198b6e Mon Sep 17 00:00:00 2001
From: Josh <37798644+joshuaellis@users.noreply.github.com>
Date: Thu, 16 Feb 2023 13:51:54 +0100
Subject: [PATCH] chore: remove axios-instance and fix types for StrapiApp
---
examples/getstarted/src/index.js | 4 +-
.../plugin/admin/src/utils/axiosInstance.js | 42 -------------------
.../src/components/Initializer/index.tsx | 2 +-
.../admin/src/components/PluginIcon/index.tsx | 2 +-
.../lib/files/ts/plugin/admin/src/index.tsx | 10 +++--
.../ts/plugin/admin/src/pages/App/index.tsx | 2 +-
.../plugin/admin/src/pages/HomePage/index.tsx | 2 +-
.../plugin/admin/src/utils/axiosInstance.ts | 42 -------------------
.../lib/templates/js/plugin-package.json.hbs | 1 -
.../lib/templates/ts/plugin-package.json.hbs | 1 -
10 files changed, 13 insertions(+), 95 deletions(-)
delete mode 100644 packages/generators/generators/lib/files/js/plugin/admin/src/utils/axiosInstance.js
delete mode 100644 packages/generators/generators/lib/files/ts/plugin/admin/src/utils/axiosInstance.ts
diff --git a/examples/getstarted/src/index.js b/examples/getstarted/src/index.js
index 5abfcc85cf..9dd946b82b 100644
--- a/examples/getstarted/src/index.js
+++ b/examples/getstarted/src/index.js
@@ -7,7 +7,9 @@ module.exports = {
*
* This gives you an opportunity to extend code.
*/
- register({ strapi }) {},
+ register(app) {
+ console.log(app);
+ },
/**
* An asynchronous bootstrap function that runs before
diff --git a/packages/generators/generators/lib/files/js/plugin/admin/src/utils/axiosInstance.js b/packages/generators/generators/lib/files/js/plugin/admin/src/utils/axiosInstance.js
deleted file mode 100644
index e487f8c4ce..0000000000
--- a/packages/generators/generators/lib/files/js/plugin/admin/src/utils/axiosInstance.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * axios with a custom config.
- */
-
-import axios from 'axios';
-import { auth, wrapAxiosInstance } from '@strapi/helper-plugin';
-
-const instance = axios.create({
- baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
-});
-
-instance.interceptors.request.use(
- async (config) => {
- config.headers = {
- Authorization: `Bearer ${auth.getToken()}`,
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- };
-
- return config;
- },
- (error) => {
- Promise.reject(error);
- }
-);
-
-instance.interceptors.response.use(
- (response) => response,
- (error) => {
- // whatever you want to do with the error
- if (error.response?.status === 401) {
- auth.clearAppStorage();
- window.location.reload();
- }
-
- throw error;
- }
-);
-
-const wrapper = wrapAxiosInstance(instance);
-
-export default wrapper;
diff --git a/packages/generators/generators/lib/files/ts/plugin/admin/src/components/Initializer/index.tsx b/packages/generators/generators/lib/files/ts/plugin/admin/src/components/Initializer/index.tsx
index 7f4d42aa2f..efa7752ac0 100644
--- a/packages/generators/generators/lib/files/ts/plugin/admin/src/components/Initializer/index.tsx
+++ b/packages/generators/generators/lib/files/ts/plugin/admin/src/components/Initializer/index.tsx
@@ -4,7 +4,7 @@
*
*/
-import React, { useEffect, useRef } from 'react';
+import { useEffect, useRef } from 'react';
import pluginId from '../../pluginId';
type InitializerProps = {
diff --git a/packages/generators/generators/lib/files/ts/plugin/admin/src/components/PluginIcon/index.tsx b/packages/generators/generators/lib/files/ts/plugin/admin/src/components/PluginIcon/index.tsx
index bd2bd3e571..e2bb2d5922 100644
--- a/packages/generators/generators/lib/files/ts/plugin/admin/src/components/PluginIcon/index.tsx
+++ b/packages/generators/generators/lib/files/ts/plugin/admin/src/components/PluginIcon/index.tsx
@@ -7,6 +7,6 @@
import React from 'react';
import { Puzzle } from '@strapi/icons';
-const PluginIcon: React.VoidFunctionComponent = () => ;
+const PluginIcon = () => ;
export default PluginIcon;
diff --git a/packages/generators/generators/lib/files/ts/plugin/admin/src/index.tsx b/packages/generators/generators/lib/files/ts/plugin/admin/src/index.tsx
index d33663e38e..c366461de3 100644
--- a/packages/generators/generators/lib/files/ts/plugin/admin/src/index.tsx
+++ b/packages/generators/generators/lib/files/ts/plugin/admin/src/index.tsx
@@ -1,4 +1,5 @@
import { prefixPluginTranslations } from '@strapi/helper-plugin';
+
import pluginPkg from '../../package.json';
import pluginId from './pluginId';
import Initializer from './components/Initializer';
@@ -7,7 +8,7 @@ import PluginIcon from './components/PluginIcon';
const name = pluginPkg.strapi.name;
export default {
- register(app) {
+ register(app: any) {
app.addMenuLink({
to: `/plugins/${pluginId}`,
icon: PluginIcon,
@@ -38,12 +39,13 @@ export default {
app.registerPlugin(plugin);
},
- bootstrap(app) {},
- async registerTrads(app) {
+ bootstrap(app: any) {},
+
+ async registerTrads(app: any) {
const { locales } = app;
const importedTrads = await Promise.all(
- locales.map((locale) => {
+ (locales as any[]).map((locale) => {
return import(`./translations/${locale}.json`)
.then(({ default: data }) => {
return {
diff --git a/packages/generators/generators/lib/files/ts/plugin/admin/src/pages/App/index.tsx b/packages/generators/generators/lib/files/ts/plugin/admin/src/pages/App/index.tsx
index 36ccc83448..b2d80ef744 100644
--- a/packages/generators/generators/lib/files/ts/plugin/admin/src/pages/App/index.tsx
+++ b/packages/generators/generators/lib/files/ts/plugin/admin/src/pages/App/index.tsx
@@ -11,7 +11,7 @@ import { NotFound } from '@strapi/helper-plugin';
import pluginId from '../../pluginId';
import HomePage from '../HomePage';
-const App: React.VoidFunctionComponent = () => {
+const App = () => {
return (
diff --git a/packages/generators/generators/lib/files/ts/plugin/admin/src/pages/HomePage/index.tsx b/packages/generators/generators/lib/files/ts/plugin/admin/src/pages/HomePage/index.tsx
index 24ce835333..d7aa708f9e 100644
--- a/packages/generators/generators/lib/files/ts/plugin/admin/src/pages/HomePage/index.tsx
+++ b/packages/generators/generators/lib/files/ts/plugin/admin/src/pages/HomePage/index.tsx
@@ -7,7 +7,7 @@
import React from 'react';
import pluginId from '../../pluginId';
-const HomePage: React.VoidFunctionComponent = () => {
+const HomePage = () => {
return (
{pluginId}'s HomePage
diff --git a/packages/generators/generators/lib/files/ts/plugin/admin/src/utils/axiosInstance.ts b/packages/generators/generators/lib/files/ts/plugin/admin/src/utils/axiosInstance.ts
deleted file mode 100644
index e487f8c4ce..0000000000
--- a/packages/generators/generators/lib/files/ts/plugin/admin/src/utils/axiosInstance.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * axios with a custom config.
- */
-
-import axios from 'axios';
-import { auth, wrapAxiosInstance } from '@strapi/helper-plugin';
-
-const instance = axios.create({
- baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
-});
-
-instance.interceptors.request.use(
- async (config) => {
- config.headers = {
- Authorization: `Bearer ${auth.getToken()}`,
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- };
-
- return config;
- },
- (error) => {
- Promise.reject(error);
- }
-);
-
-instance.interceptors.response.use(
- (response) => response,
- (error) => {
- // whatever you want to do with the error
- if (error.response?.status === 401) {
- auth.clearAppStorage();
- window.location.reload();
- }
-
- throw error;
- }
-);
-
-const wrapper = wrapAxiosInstance(instance);
-
-export default wrapper;
diff --git a/packages/generators/generators/lib/templates/js/plugin-package.json.hbs b/packages/generators/generators/lib/templates/js/plugin-package.json.hbs
index cf2fec6bd3..a9bbfcab4c 100644
--- a/packages/generators/generators/lib/templates/js/plugin-package.json.hbs
+++ b/packages/generators/generators/lib/templates/js/plugin-package.json.hbs
@@ -12,7 +12,6 @@
"@strapi/design-system": "^1.6.3",
"@strapi/helper-plugin": "^4.6.0",
"@strapi/icons": "^1.6.3",
- "axios": "^1.2.2",
"prop-types": "^15.7.2"
},
"devDependencies": {
diff --git a/packages/generators/generators/lib/templates/ts/plugin-package.json.hbs b/packages/generators/generators/lib/templates/ts/plugin-package.json.hbs
index 10c175d47b..4b56934c6b 100644
--- a/packages/generators/generators/lib/templates/ts/plugin-package.json.hbs
+++ b/packages/generators/generators/lib/templates/ts/plugin-package.json.hbs
@@ -11,7 +11,6 @@
"@strapi/design-system": "^1.6.3",
"@strapi/helper-plugin": "^4.6.0",
"@strapi/icons": "^1.6.3",
- "axios": "^1.2.2",
"prop-types": "^15.7.2"
},
"devDependencies": {