diff --git a/app/Http/Requests/Api/Application/Roles/GetRoleRequest.php b/app/Http/Requests/Api/Application/Roles/GetRoleRequest.php index 7458ea3a1..cd583c85c 100644 --- a/app/Http/Requests/Api/Application/Roles/GetRoleRequest.php +++ b/app/Http/Requests/Api/Application/Roles/GetRoleRequest.php @@ -4,7 +4,7 @@ namespace Pterodactyl\Http\Requests\Api\Application\Roles; use Pterodactyl\Models\AdminRole; -class GetRoleRequest extends GetMountsRequest +class GetRoleRequest extends GetRolesRequest { /** * Determine if the requested role exists on the Panel. diff --git a/resources/scripts/components/admin/roles/RoleEditContainer.tsx b/resources/scripts/components/admin/roles/RoleEditContainer.tsx index c541988b3..dc3e68b43 100644 --- a/resources/scripts/components/admin/roles/RoleEditContainer.tsx +++ b/resources/scripts/components/admin/roles/RoleEditContainer.tsx @@ -1,8 +1,78 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; +import tw from 'twin.macro'; +import { useRouteMatch } from 'react-router-dom'; +import { action, Action, Actions, createContextStore, useStoreActions } from 'easy-peasy'; +import { Role } from '@/api/admin/roles/getRoles'; +import getRole from '@/api/admin/roles/getRole'; +import AdminContentBlock from '@/components/admin/AdminContentBlock'; +import Spinner from '@/components/elements/Spinner'; +import FlashMessageRender from '@/components/FlashMessageRender'; +import { ApplicationStore } from '@/state'; + +interface ctx { + role: Role | undefined; + setRole: Action; +} + +export const Context = createContextStore({ + role: undefined, + + setRole: action((state, payload) => { + state.role = payload; + }), +}); + +const RoleEditContainer = () => { + const match = useRouteMatch<{ id?: string }>(); + + const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); + const [ loading, setLoading ] = useState(true); + + const role = Context.useStoreState(state => state.role); + const setRole = Context.useStoreActions(actions => actions.setRole); + + useEffect(() => { + clearFlashes('role'); + + getRole(Number(match.params?.id)) + .then(role => setRole(role)) + .catch(error => { + console.error(error); + clearAndAddHttpError({ key: 'role', error }); + }) + .then(() => setLoading(false)); + }, []); + + if (loading || role === undefined) { + return ( + + + +
+ +
+
+ ); + } + + return ( + +
+
+

{role.name}

+

{role.description}

+
+
+ + +
+ ); +}; export default () => { return ( - <> - + + + ); };