Skip to content

Commit

Permalink
OS-2765. Populate default resource owner field for new pools
Browse files Browse the repository at this point in the history
Updated the logic to fetch eligible employees for the Default Resource Owner field during pool creation by using the parent pool ID
  • Loading branch information
ek-hystax authored Dec 25, 2024
1 parent 9203864 commit c1a6c3e
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions ngui/ui/src/components/forms/PoolForm/CreatePoolForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ import { Box } from "@mui/material";
import { FormProvider, useForm } from "react-hook-form";
import ButtonLoader from "components/ButtonLoader";
import FormButtonsWrapper from "components/FormButtonsWrapper";
import EmployeesService from "services/EmployeesService";
import PoolsService from "services/PoolsService";
import { isOrganizationManager, isPoolManager } from "utils/employees";
import { NameField, LimitField, TypeSelector, AutoExtendCheckbox, OwnerSelector } from "./FormElements";
import { CreatePoolFormProps, CreatePoolFormValues } from "./types";
import { getCreateFormDefaultValues } from "./utils";

const CreatePoolForm = ({ parentId, onSuccess, unallocatedLimit }: CreatePoolFormProps) => {
const { useCreatePool } = PoolsService();
const { useCreatePool, useGetPoolOwners } = PoolsService();
const { isLoading: isCreatePoolLoading, createPool } = useCreatePool();

const { useGet: useGetEmployees } = EmployeesService();

const { isLoading: isGetEmployeesLoading, employees } = useGetEmployees();

const owners = employees.filter((employee) => isOrganizationManager(employee) || isPoolManager(employee, parentId));
const { poolOwners, isDataReady: isPoolOwnersDataReady } = useGetPoolOwners(parentId);

const methods = useForm<CreatePoolFormValues>({
defaultValues: getCreateFormDefaultValues()
Expand All @@ -32,7 +26,7 @@ const CreatePoolForm = ({ parentId, onSuccess, unallocatedLimit }: CreatePoolFor
<form data-test-id="form_add_pool" onSubmit={onSubmit} noValidate>
<NameField />
<TypeSelector />
<OwnerSelector isLoading={isGetEmployeesLoading} owners={owners} helpMessageId="createPoolDefaultOwnerHelp" />
<OwnerSelector isLoading={!isPoolOwnersDataReady} owners={poolOwners} helpMessageId="createPoolDefaultOwnerHelp" />
<LimitField unallocatedLimit={unallocatedLimit} />
<AutoExtendCheckbox />
<FormButtonsWrapper justifyContent="space-between">
Expand Down

0 comments on commit c1a6c3e

Please sign in to comment.