Skip to content

Commit

Permalink
Merge pull request #356 from stustapay/milo/fix-user-to-role-create
Browse files Browse the repository at this point in the history
fix(admin): correct user list in user to role create
  • Loading branch information
mikonse committed May 20, 2024
2 parents 9f9c557 + 84f3a03 commit cc2d532
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ export const CashierCloseOut: React.FC = () => {
label={t("closeOut.closingOutUser")}
value={formik.values.closingOutUserId}
onBlur={formik.handleBlur}
// TODO: readd filter once roles are again propagated with users
// filterRole="finanzorga"
filterPrivilege="node_administration"
onChange={(val) => formik.setFieldValue("closingOutUserId", val)}
error={formik.touched.closingOutUserId && !!formik.errors.closingOutUserId}
helperText={(formik.touched.closingOutUserId && formik.errors.closingOutUserId) as string}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export const UserToRoleList: React.FC = () => {
return "";
}
const roles = ids.map((id) => selectUserRoleById(userRoles, id));
roles.sort((lhs, rhs) =>
lhs !== undefined && rhs && undefined ? lhs.name.toLowerCase().localeCompare(rhs.name.toLowerCase()) : -1
);

return (
<Box sx={{ display: "grid", gap: 1, gridAutoFlow: "column" }}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User, selectUserAll, useListUsersQuery } from "@/api";
import { Privilege, User, selectUserAll, useListUsersQuery } from "@/api";
import { useCurrentNode } from "@/hooks";
import { Select, SelectProps } from "@stustapay/components";
import { getUserName } from "@stustapay/models";
Expand All @@ -7,12 +7,13 @@ import * as React from "react";
export type UserSelectProps = {
value: number;
onChange: (userId: number) => void;
filterPrivilege?: Privilege;
} & Omit<SelectProps<User, false>, "options" | "formatOption" | "multiple" | "value" | "onChange">;

export const UserSelect: React.FC<UserSelectProps> = ({ value, onChange, ...props }) => {
export const UserSelect: React.FC<UserSelectProps> = ({ value, onChange, filterPrivilege, ...props }) => {
const { currentNode } = useCurrentNode();
const { users } = useListUsersQuery(
{ nodeId: currentNode.id, filterPrivilege: "node_administration" },
{ nodeId: currentNode.id, filterPrivilege },
{
selectFromResult: ({ data, ...rest }) => ({
...rest,
Expand Down

0 comments on commit cc2d532

Please sign in to comment.