57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
import { Select, Space, Tag } from "antd";
|
|
import React, { forwardRef, useEffect, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
const { Option } = Select;
|
|
//To be used as a form element only.
|
|
|
|
const EmployeeSearchSelect = (
|
|
{ value, onChange, options, onSelect, onBlur, ...restProps },
|
|
ref
|
|
) => {
|
|
const [option, setOption] = useState(value);
|
|
const { t } = useTranslation();
|
|
useEffect(() => {
|
|
if (value !== option && onChange) {
|
|
onChange(option);
|
|
}
|
|
}, [value, option, onChange]);
|
|
|
|
return (
|
|
<Select
|
|
showSearch
|
|
value={option}
|
|
style={{
|
|
width: 400,
|
|
}}
|
|
onChange={setOption}
|
|
optionFilterProp="search"
|
|
onSelect={onSelect}
|
|
onBlur={onBlur}
|
|
{...restProps}
|
|
>
|
|
{options
|
|
? options.map((o) => (
|
|
<Option
|
|
key={o.id}
|
|
value={o.id}
|
|
search={`${o.employee_number} ${o.first_name} ${o.last_name}`}
|
|
discount={o.discount}
|
|
>
|
|
<Space>
|
|
{`${o.employee_number} ${o.first_name} ${o.last_name}`}
|
|
<Tag color="blue">{o.cost_center}</Tag>
|
|
|
|
<Tag color="green">
|
|
{o.flat_rate
|
|
? t("timetickets.labels.flat_rate")
|
|
: t("timetickets.labels.straight_time")}
|
|
</Tag>
|
|
</Space>
|
|
</Option>
|
|
))
|
|
: null}
|
|
</Select>
|
|
);
|
|
};
|
|
export default forwardRef(EmployeeSearchSelect);
|