IO-934 Refactor some search select fields & save employee on new ticket

This commit is contained in:
Patrick Fic
2021-04-26 14:57:04 -07:00
parent 438692ea7c
commit 485e1c4497
3 changed files with 17 additions and 38 deletions

View File

@@ -2,7 +2,7 @@ import { LoadingOutlined } from "@ant-design/icons";
import { useLazyQuery } from "@apollo/client";
import { Empty, Select } from "antd";
import _ from "lodash";
import React, { forwardRef, useEffect, useState } from "react";
import React, { forwardRef, useEffect } from "react";
import { useTranslation } from "react-i18next";
import {
SEARCH_JOBS_BY_ID_FOR_AUTOCOMPLETE,
@@ -13,13 +13,11 @@ const { Option } = Select;
const JobSearchSelect = (
{
value,
onChange,
onBlur,
disabled,
convertedOnly = false,
notExported = true,
clm_no = false,
...restProps
},
ref
) => {
@@ -52,20 +50,11 @@ const JobSearchSelect = (
debouncedExecuteSearch({ variables: { search: value } });
};
const [option, setOption] = useState(value);
useEffect(() => {
if (value === option && value) {
callIdSearch({ variables: { id: value } }); // Sometimes results in a no-op. Not sure how to fix.
if (restProps.value) {
callIdSearch({ variables: { id: restProps.value } }); // Sometimes results in a no-op. Not sure how to fix.
}
}, [value, option, callIdSearch]);
const handleSelect = (value) => {
setOption(value);
if (value !== option && onChange) {
onChange(value);
}
};
}, [restProps.value, callIdSearch]);
const theOptions = _.uniqBy(
[
@@ -82,17 +71,13 @@ const JobSearchSelect = (
disabled={disabled}
showSearch
autoFocus
value={option}
style={{
width: "100%",
}}
filterOption={false}
onSearch={handleSearch}
// onChange={setOption}
onChange={handleSelect}
onSelect={handleSelect}
notFoundContent={loading ? <LoadingOutlined /> : <Empty />}
onBlur={onBlur}
{...restProps}
>
{theOptions
? theOptions.map((o) => (