47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@common/components";
|
|
import { RoleApi } from "@/entities/role";
|
|
import { ENDPOINT } from "@/shared/config";
|
|
|
|
type RoleSelectProps = React.ComponentPropsWithoutRef<typeof Select> & {
|
|
mngrYn?: string;
|
|
};
|
|
|
|
function RoleSelect({ mngrYn = "N", ...props }: RoleSelectProps) {
|
|
const { data: roles } = useQuery({
|
|
queryKey: [ENDPOINT.USER_SERVICE.ROLES],
|
|
queryFn: () =>
|
|
RoleApi.getRoles({
|
|
keywordType: "useYn",
|
|
keyword: "Y",
|
|
page: 0,
|
|
size: 100,
|
|
}),
|
|
});
|
|
|
|
const options = roles?.content.filter((role) => role.mngrYn === mngrYn);
|
|
|
|
return (
|
|
<Select {...props}>
|
|
<SelectTrigger className="w-[24rem]">
|
|
<SelectValue placeholder="선택" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{options?.map((item) => (
|
|
<SelectItem key={item.roleId} value={item.roleId}>
|
|
{item.roleName}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
);
|
|
}
|
|
|
|
export { RoleSelect };
|