diff --git a/resources/scripts/components/App.tsx b/resources/scripts/components/App.tsx index db8d6c3ef..e870787dd 100644 --- a/resources/scripts/components/App.tsx +++ b/resources/scripts/components/App.tsx @@ -6,25 +6,47 @@ import AccountRouter from '@/routers/AccountRouter'; import ServerOverviewContainer from '@/components/ServerOverviewContainer'; import { StoreProvider } from 'easy-peasy'; import { store } from '@/state'; +import { UserData } from '@/state/types'; -class App extends React.PureComponent { - componentDidMount () { - - } - - render () { - return ( - - -
- - - -
-
-
- ); - } +interface WindowWithUser extends Window { + PterodactylUser?: { + uuid: string; + username: string; + email: string; + root_admin: boolean; + use_totp: boolean; + language: string; + updated_at: string; + created_at: string; + }; } +const App = () => { + const data = (window as WindowWithUser).PterodactylUser; + if (data) { + store.getActions().user.setUserData({ + uuid: data.uuid, + username: data.username, + email: data.email, + language: data.language, + rootAdmin: data.root_admin, + useTotp: data.use_totp, + createdAt: new Date(data.created_at), + updatedAt: new Date(data.updated_at), + }); + } + + return ( + + +
+ + + +
+
+
+ ); +}; + export default hot(App); diff --git a/resources/scripts/state/index.ts b/resources/scripts/state/index.ts index e1b4470f5..5df635796 100644 --- a/resources/scripts/state/index.ts +++ b/resources/scripts/state/index.ts @@ -1,16 +1,11 @@ -import { action, createStore } from 'easy-peasy'; +import { createStore } from 'easy-peasy'; import { ApplicationState } from '@/state/types'; +import flashes from '@/state/models/flashes'; +import user from '@/state/models/user'; const state: ApplicationState = { - flashes: { - items: [], - addFlash: action((state, payload) => { - state.items.push(payload); - }), - clearFlashes: action(state => { - state.items = []; - }), - }, + flashes, + user, }; export const store = createStore(state); diff --git a/resources/scripts/state/models/flashes.ts b/resources/scripts/state/models/flashes.ts new file mode 100644 index 000000000..5c9a7f0a3 --- /dev/null +++ b/resources/scripts/state/models/flashes.ts @@ -0,0 +1,14 @@ +import { action } from 'easy-peasy'; +import { FlashState } from '@/state/types'; + +const flashes: FlashState = { + items: [], + addFlash: action((state, payload) => { + state.items.push(payload); + }), + clearFlashes: action(state => { + state.items = []; + }), +}; + +export default flashes; diff --git a/resources/scripts/state/models/user.ts b/resources/scripts/state/models/user.ts new file mode 100644 index 000000000..3997d009f --- /dev/null +++ b/resources/scripts/state/models/user.ts @@ -0,0 +1,11 @@ +import { UserState } from '@/state/types'; +import { action } from 'easy-peasy'; + +const user: UserState = { + data: undefined, + setUserData: action((state, payload) => { + state.data = payload; + }), +}; + +export default user; diff --git a/resources/scripts/state/types.d.ts b/resources/scripts/state/types.d.ts index 742b68320..7c700a692 100644 --- a/resources/scripts/state/types.d.ts +++ b/resources/scripts/state/types.d.ts @@ -3,6 +3,7 @@ import { Action } from 'easy-peasy'; export interface ApplicationState { flashes: FlashState; + user: UserState; } export interface FlashState { @@ -11,6 +12,22 @@ export interface FlashState { clearFlashes: Action; } +export interface UserState { + data?: UserData; + setUserData: Action; +} + +export interface UserData { + uuid: string; + username: string; + email: string; + language: string; + rootAdmin: boolean; + useTotp: boolean; + createdAt: Date; + updatedAt: Date; +} + export interface FlashMessage { id?: string; type: FlashMessageType;