Skip to content

Commit

Permalink
Added ptop-energy plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-eminds committed Sep 27, 2024
1 parent 48d70b8 commit 4c09db3
Show file tree
Hide file tree
Showing 33 changed files with 4,414 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/ptop-energy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Strapi plugin ptop-energy

A quick description of ptop-energy.
24 changes: 24 additions & 0 deletions plugins/ptop-energy/admin/src/components/Initializer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
*
* Initializer
*
*/

import { useEffect, useRef } from 'react';
import pluginId from '../../pluginId';

type InitializerProps = {
setPlugin: (id: string) => void;
};

const Initializer = ({ setPlugin }: InitializerProps) => {
const ref = useRef(setPlugin);

useEffect(() => {
ref.current(pluginId);
}, []);

return null;
};

export default Initializer;
12 changes: 12 additions & 0 deletions plugins/ptop-energy/admin/src/components/PluginIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
*
* PluginIcon
*
*/

import React from 'react';
import { Puzzle } from '@strapi/icons';

const PluginIcon = () => <Puzzle />;

export default PluginIcon;
67 changes: 67 additions & 0 deletions plugins/ptop-energy/admin/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { prefixPluginTranslations } from '@strapi/helper-plugin';

import pluginPkg from '../../package.json';
import pluginId from './pluginId';
import Initializer from './components/Initializer';
import PluginIcon from './components/PluginIcon';

const name = pluginPkg.strapi.name;

export default {
register(app: any) {
app.addMenuLink({
to: `/plugins/${pluginId}`,
icon: PluginIcon,
intlLabel: {
id: `${pluginId}.plugin.name`,
defaultMessage: name,
},
Component: async () => {
const component = await import(/* webpackChunkName: "[request]" */ './pages/App');

return component;
},
permissions: [
// Uncomment to set the permissions of the plugin here
// {
// action: '', // the action name should be plugin::plugin-name.actionType
// subject: null,
// },
],
});
const plugin = {
id: pluginId,
initializer: Initializer,
isReady: false,
name,
};

app.registerPlugin(plugin);
},

bootstrap(app: any) {},

async registerTrads(app: any) {
const { locales } = app;

const importedTrads = await Promise.all(
(locales as any[]).map((locale) => {
return import(`./translations/${locale}.json`)
.then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, pluginId),
locale,
};
})
.catch(() => {
return {
data: {},
locale,
};
});
})
);

return Promise.resolve(importedTrads);
},
};
25 changes: 25 additions & 0 deletions plugins/ptop-energy/admin/src/pages/App/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
*
* This component is the skeleton around the actual pages, and should only
* contain code that should be seen on all pages. (e.g. navigation bar)
*
*/

import React from 'react';
import { Switch, Route } from 'react-router-dom';
import { AnErrorOccurred } from '@strapi/helper-plugin';
import pluginId from '../../pluginId';
import HomePage from '../HomePage';

const App = () => {
return (
<div>
<Switch>
<Route path={`/plugins/${pluginId}`} component={HomePage} exact />
<Route component={AnErrorOccurred} />
</Switch>
</div>
);
};

export default App;
19 changes: 19 additions & 0 deletions plugins/ptop-energy/admin/src/pages/HomePage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
*
* HomePage
*
*/

import React from 'react';
import pluginId from '../../pluginId';

const HomePage = () => {
return (
<div>
<h1>{pluginId}&apos;s HomePage</h1>
<p>Happy coding</p>
</div>
);
};

export default HomePage;
5 changes: 5 additions & 0 deletions plugins/ptop-energy/admin/src/pluginId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pluginPkg from '../../package.json';

const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, '');

export default pluginId;
1 change: 1 addition & 0 deletions plugins/ptop-energy/admin/src/translations/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions plugins/ptop-energy/admin/src/translations/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions plugins/ptop-energy/admin/src/utils/getTrad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pluginId from '../pluginId';

const getTrad = (id: string) => `${pluginId}.${id}`;

export default getTrad;
5 changes: 5 additions & 0 deletions plugins/ptop-energy/custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '@strapi/design-system/*';
declare module '@strapi/design-system';
declare module '@strapi/icons';
declare module '@strapi/icons/*';
declare module '@strapi/helper-plugin';
Loading

0 comments on commit 4c09db3

Please sign in to comment.