diff --git a/src/stock-lookups/stock-lookups.resource.ts b/src/stock-lookups/stock-lookups.resource.ts index efaae62d..d909e5c4 100644 --- a/src/stock-lookups/stock-lookups.resource.ts +++ b/src/stock-lookups/stock-lookups.resource.ts @@ -152,7 +152,7 @@ export function useUser(id: string) { Error >(apiUrl, openmrsFetch); return { - items: data.data ? data.data : {}, + data: data?.data || {}, isLoading, isError: error, }; diff --git a/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx b/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx index f7fd8d28..4ef8486b 100644 --- a/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx +++ b/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx @@ -19,6 +19,7 @@ import { useRoles, useStockLocations, useStockOperationTypes, + useUser, useUsers, } from "../../stock-lookups/stock-lookups.resource"; import { ResourceRepresentation } from "../../core/api/api"; @@ -43,13 +44,21 @@ import { StockOperationType } from "../../core/api/types/stockOperation/StockOpe const MinDate: Date = today(); -const AddStockUserRoleScope: React.FC = () => { +interface AddStockUserRoleScopeProps { + model?: UserRoleScope; +} + +const AddStockUserRoleScope: React.FC = ({ + model, +}) => { const { t } = useTranslation(); - const [formModel, setFormModel] = useState(); + const [formModel, setFormModel] = useState({ ...model }); const [roles, setRoles] = useState([]); + const { data: user } = useUser(model?.uuid); + // operation types const { types: { results: stockOperations }, @@ -288,6 +297,11 @@ const AddStockUserRoleScope: React.FC = () => { id="userName" size="md" labelText="User" + value={ + formModel.userUuid + ? `${formModel.userFamilyName} ${formModel.userGivenName}` + : `` + } items={users?.results} onChange={onUserChanged} shouldFilterItem={(data) => true} @@ -315,7 +329,8 @@ const AddStockUserRoleScope: React.FC = () => { labelText="Role" size="md" onChange={onRoleChange} - items={rolesData?.results} + value={formModel?.role ?? ""} + items={rolesData?.results ?? roles} shouldFilterItem={() => true} onFocus={() => rolesData?.results} onToggleClick={() => rolesData?.results} @@ -332,12 +347,14 @@ const AddStockUserRoleScope: React.FC = () => { onChange={onEnabledChanged} checked={formModel?.enabled} labelText={`Enabled ?`} + value={model?.enabled} id="chk-userEnabled" /> diff --git a/src/stock-user-role-scopes/edit-stock-user-scope/edit-stock-user-scope-action-menu.component.tsx b/src/stock-user-role-scopes/edit-stock-user-scope/edit-stock-user-scope-action-menu.component.tsx new file mode 100644 index 00000000..aea16f9a --- /dev/null +++ b/src/stock-user-role-scopes/edit-stock-user-scope/edit-stock-user-scope-action-menu.component.tsx @@ -0,0 +1,35 @@ +import { Button } from "@carbon/react"; +import { Edit } from "@carbon/react/icons"; + +import React, { useCallback } from "react"; +import { useTranslation } from "react-i18next"; +import { launchOverlay } from "../../core/components/overlay/hook"; +import AddStockUserRoleScope from "../add-stock-user-scope/add-stock-user-role-scope.component"; +import { UserRoleScope } from "../../core/api/types/identity/UserRoleScope"; + +interface EditStockUserRoleActionsMenuProps { + data: UserRoleScope; +} + +const EditStockUserRoleActionsMenu: React.FC< + EditStockUserRoleActionsMenuProps +> = ({ data }) => { + const { t } = useTranslation(); + + const handleClick = useCallback(() => { + launchOverlay( + "Edit Stock User Role", + + ); + }, [data]); + + return ( +