Files
Fulfillment-Frontend/src/components/DealStatusSelect/DealStatusSelect.tsx
2025-02-07 20:07:10 +04:00

41 lines
1.1 KiB
TypeScript

import ObjectSelect, { ObjectSelectProps } from "../ObjectSelect/ObjectSelect.tsx";
import { FC, useEffect, useState } from "react";
import { BoardSchema, StatusSchema } from "../../client";
type OtherProps = {
board: BoardSchema | null;
}
type SelectProps = Omit<ObjectSelectProps<StatusSchema | null>, "data" | "getLabelFn" | "getValueFn">;
type Props = OtherProps & SelectProps;
const DealStatusSelect: FC<Props> = ({ board, ...props}) => {
const [isInitial, setIsInitial] = useState<boolean>(true);
const filteredData = board?.dealStatuses.filter(
status => !status.isDeleted,
) ?? [];
const onClear = () => props.onChange(null);
useEffect(() => {
if (isInitial) {
setIsInitial(false);
} else {
onClear();
}
}, [board?.id]);
return (
<ObjectSelect
data={filteredData}
searchable
placeholder={"Выберите статус"}
onClear={onClear}
{...props}
/>
);
};
export default DealStatusSelect;