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 React, { forwardRef, useEffect, useState } from "react";
import React, { forwardRef } 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 EmployeeSearchSelect = ({ options, ...props }, ref) => {
const { t } = useTranslation();
useEffect(() => {
if (value !== option && onChange) {
onChange(option);
}
}, [value, option, onChange]);
return (
<Select
showSearch
value={option}
// value={option}
style={{
width: 400,
}}
onChange={setOption}
optionFilterProp="search"
onSelect={onSelect}
onBlur={onBlur}
{...restProps}
{...props}
>
{options
? options.map((o) => (

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) => (

View File

@@ -92,9 +92,14 @@ export function TimeTicketModalContainer({
if (enterAgain) {
//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.setFieldsValue(prev);
} else {
toggleModalVisible();
@@ -177,6 +182,7 @@ export function TimeTicketModalContainer({
{timeTicketModal.context && timeTicketModal.context.id ? null : (
<Button
type="primary"
htmlType="submit"
onClick={() => {
setEnterAgain(true);
}}