mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-23 20:28:47 +00:00
refactor: reorganize user permission checks in AdvancedEnvironmentSelector
- Moved the check for user permissions to delete environments to a more logical position in the code. - Removed redundant API query for environment data, streamlining the component's state management.
This commit is contained in:
@@ -59,26 +59,10 @@ export const AdvancedEnvironmentSelector = ({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data: currentUser } = api.user.get.useQuery();
|
|
||||||
|
|
||||||
// Check if user can delete environments
|
|
||||||
const canDeleteEnvironments =
|
|
||||||
currentUser?.role === "owner" ||
|
|
||||||
currentUser?.role === "admin" ||
|
|
||||||
currentUser?.canDeleteEnvironments === true;
|
|
||||||
|
|
||||||
// Form states
|
// Form states
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [description, setDescription] = useState("");
|
const [description, setDescription] = useState("");
|
||||||
|
|
||||||
// API mutations
|
|
||||||
const { data: environment } = api.environment.one.useQuery(
|
|
||||||
{ environmentId: currentEnvironmentId || "" },
|
|
||||||
{
|
|
||||||
enabled: !!currentEnvironmentId,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get current user's permissions
|
// Get current user's permissions
|
||||||
const { data: currentUser } = api.user.get.useQuery();
|
const { data: currentUser } = api.user.get.useQuery();
|
||||||
|
|
||||||
@@ -88,6 +72,12 @@ export const AdvancedEnvironmentSelector = ({
|
|||||||
currentUser?.role === "admin" ||
|
currentUser?.role === "admin" ||
|
||||||
currentUser?.canCreateEnvironments === true;
|
currentUser?.canCreateEnvironments === true;
|
||||||
|
|
||||||
|
// Check if user can delete environments
|
||||||
|
const canDeleteEnvironments =
|
||||||
|
currentUser?.role === "owner" ||
|
||||||
|
currentUser?.role === "admin" ||
|
||||||
|
currentUser?.canDeleteEnvironments === true;
|
||||||
|
|
||||||
const haveServices =
|
const haveServices =
|
||||||
selectedEnvironment &&
|
selectedEnvironment &&
|
||||||
((selectedEnvironment?.mariadb?.length || 0) > 0 ||
|
((selectedEnvironment?.mariadb?.length || 0) > 0 ||
|
||||||
|
|||||||
Reference in New Issue
Block a user