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

@@ -1,33 +1,21 @@
import { Select, Space, Tag } from "antd"; import { Select, Space, Tag } from "antd";
import React, { forwardRef, useEffect, useState } from "react"; import React, { forwardRef } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
const { Option } = Select; const { Option } = Select;
//To be used as a form element only. //To be used as a form element only.
const EmployeeSearchSelect = ( const EmployeeSearchSelect = ({ options, ...props }, ref) => {
{ value, onChange, options, onSelect, onBlur, ...restProps },
ref
) => {
const [option, setOption] = useState(value);
const { t } = useTranslation(); const { t } = useTranslation();
useEffect(() => {
if (value !== option && onChange) {
onChange(option);
}
}, [value, option, onChange]);
return ( return (
<Select <Select
showSearch showSearch
value={option} // value={option}
style={{ style={{
width: 400, width: 400,
}} }}
onChange={setOption}
optionFilterProp="search" optionFilterProp="search"
onSelect={onSelect} {...props}
onBlur={onBlur}
{...restProps}
> >
{options {options
? options.map((o) => ( ? options.map((o) => (

View File

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

View File

@@ -92,9 +92,14 @@ export function TimeTicketModalContainer({
if (enterAgain) { if (enterAgain) {
//Capture the existing information and repopulate it. //Capture the existing information and repopulate it.
const prev = form.getFieldsValue(["date"]); const prev = form.getFieldsValue(["date", "employeeid"]);
console.log(
"🚀 ~ file: time-ticket-modal.container.jsx ~ line 96 ~ prev",
prev
);
form.resetFields(); form.resetFields();
form.setFieldsValue(prev); form.setFieldsValue(prev);
} else { } else {
toggleModalVisible(); toggleModalVisible();
@@ -177,6 +182,7 @@ export function TimeTicketModalContainer({
{timeTicketModal.context && timeTicketModal.context.id ? null : ( {timeTicketModal.context && timeTicketModal.context.id ? null : (
<Button <Button
type="primary" type="primary"
htmlType="submit"
onClick={() => { onClick={() => {
setEnterAgain(true); setEnterAgain(true);
}} }}