+
);
diff --git a/client/src/components/chat-send-message/chat-send-message.component.jsx b/client/src/components/chat-send-message/chat-send-message.component.jsx
index 810777688..646c69777 100644
--- a/client/src/components/chat-send-message/chat-send-message.component.jsx
+++ b/client/src/components/chat-send-message/chat-send-message.component.jsx
@@ -14,6 +14,7 @@ import {
selectMessage,
} from "../../redux/messaging/messaging.selectors";
import { selectBodyshop } from "../../redux/user/user.selectors";
+import ChatPresetsComponent from "../chat-presets/chat-presets.component";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
@@ -53,6 +54,8 @@ function ChatSendMessageComponent({
return (
+
+
+
{
- setSearchQuery(value);
- };
-
- const handleKeyDown = (event) => {
- if (event.key === "Enter") {
- executeSearch();
- }
- };
-
return (
-
-
+ : }
>
{roOptions.map((item, idx) => (
-
+
{` ${item.ro_number || ""} | ${item.ownr_fn || ""} ${
item.ownr_ln || ""
} ${item.ownr_co_nm || ""}`}
-
+
))}
-
+
+ {loading ? : null}
+
{loading ? (
) : (
setVisible(false)} />
)}
-
+
);
}
diff --git a/client/src/components/chat-tag-ro/chat-tag-ro.container.jsx b/client/src/components/chat-tag-ro/chat-tag-ro.container.jsx
index 80b06af89..6a84cd2a1 100644
--- a/client/src/components/chat-tag-ro/chat-tag-ro.container.jsx
+++ b/client/src/components/chat-tag-ro/chat-tag-ro.container.jsx
@@ -1,32 +1,29 @@
-import React, { useState } from "react";
-import ChatTagRo from "./chat-tag-ro.component";
-import { useLazyQuery, useMutation } from "@apollo/react-hooks";
-import { SEARCH_FOR_JOBS } from "../../graphql/jobs.queries";
-import { INSERT_CONVERSATION_TAG } from "../../graphql/job-conversations.queries";
-import { Tag } from "antd";
-import { useTranslation } from "react-i18next";
import { PlusOutlined } from "@ant-design/icons";
+import { useLazyQuery, useMutation } from "@apollo/react-hooks";
+import { Tag } from "antd";
+import _ from "lodash";
+import React, { useState } from "react";
+import { useTranslation } from "react-i18next";
import { logImEXEvent } from "../../firebase/firebase.utils";
+import { INSERT_CONVERSATION_TAG } from "../../graphql/job-conversations.queries";
+import { SEARCH_FOR_JOBS } from "../../graphql/jobs.queries";
+import ChatTagRo from "./chat-tag-ro.component";
export default function ChatTagRoContainer({ conversation }) {
const { t } = useTranslation();
const [visible, setVisible] = useState(false);
- const searchQueryState = useState("");
- const searchText = searchQueryState[0];
- const [loadRo, { called, loading, data, refetch }] = useLazyQuery(
- SEARCH_FOR_JOBS,
- {
- variables: { search: `%${searchText}%` },
- }
- );
+ const [loadRo, { loading, data }] = useLazyQuery(SEARCH_FOR_JOBS);
- const executeSearch = () => {
- logImEXEvent("messaging_search_job_tag", { searchTerm: searchText });
- if (called) refetch();
- else {
- loadRo();
- }
+ const executeSearch = (v) => {
+ logImEXEvent("messaging_search_job_tag", { searchTerm: v });
+ loadRo(v);
+ };
+
+ const debouncedExecuteSearch = _.debounce(executeSearch, 800);
+
+ const handleSearch = (value) => {
+ debouncedExecuteSearch({ variables: { search: value } });
};
const [insertTag] = useMutation(INSERT_CONVERSATION_TAG, {
@@ -45,7 +42,7 @@ export default function ChatTagRoContainer({ conversation }) {
conversation.job_conversations.map((i) => i.jobid);
const roOptions = data
- ? data.jobs.filter((job) => !existingJobTags.includes(job.id))
+ ? data.search_jobs.filter((job) => !existingJobTags.includes(job.id))
: [];
return (
@@ -53,9 +50,8 @@ export default function ChatTagRoContainer({ conversation }) {
{visible ? (
diff --git a/client/src/components/job-search-select/job-search-select.component.jsx b/client/src/components/job-search-select/job-search-select.component.jsx
index b730c6f2e..1db4244b4 100644
--- a/client/src/components/job-search-select/job-search-select.component.jsx
+++ b/client/src/components/job-search-select/job-search-select.component.jsx
@@ -1,12 +1,12 @@
+import { LoadingOutlined } from "@ant-design/icons";
import { useLazyQuery } from "@apollo/react-hooks";
-import { Select } from "antd";
+import { Empty, Select } from "antd";
+import _ from "lodash";
import React, { forwardRef, useEffect, useState } from "react";
import {
- SEARCH_JOBS_FOR_AUTOCOMPLETE,
SEARCH_JOBS_BY_ID_FOR_AUTOCOMPLETE,
+ SEARCH_JOBS_FOR_AUTOCOMPLETE,
} from "../../graphql/jobs.queries";
-import { LoadingOutlined } from "@ant-design/icons";
-import _ from "lodash";
import AlertComponent from "../alert/alert.component";
const { Option } = Select;
@@ -33,7 +33,6 @@ const JobSearchSelect = ({ value, onChange, onBlur, disabled }, ref) => {
useEffect(() => {
if (value === option) {
- console.log("Job ID Provided, searching...");
callIdSearch({ variables: { id: value } });
}
}, [value, option, callIdSearch]);
@@ -71,7 +70,7 @@ const JobSearchSelect = ({ value, onChange, onBlur, disabled }, ref) => {
onSearch={handleSearch}
// onChange={setOption}
onSelect={handleSelect}
- notFoundContent={loading ?
: null}
+ notFoundContent={loading ?
:
}
onBlur={onBlur}
>
{theOptions
diff --git a/client/src/graphql/conversations.queries.js b/client/src/graphql/conversations.queries.js
index ecdbc4e5e..571fd8c3c 100644
--- a/client/src/graphql/conversations.queries.js
+++ b/client/src/graphql/conversations.queries.js
@@ -2,7 +2,7 @@ import gql from "graphql-tag";
export const CONVERSATION_LIST_SUBSCRIPTION = gql`
subscription CONVERSATION_LIST_SUBSCRIPTION {
- conversations {
+ conversations(order_by: { updated_at: desc }, limit: 100) {
phone_num
id
job_conversations {
diff --git a/client/src/graphql/jobs.queries.js b/client/src/graphql/jobs.queries.js
index 616249837..4d3971c78 100644
--- a/client/src/graphql/jobs.queries.js
+++ b/client/src/graphql/jobs.queries.js
@@ -711,7 +711,7 @@ export const SEARCH_JOBS_BY_ID_FOR_AUTOCOMPLETE = gql`
export const SEARCH_FOR_JOBS = gql`
query SEARCH_FOR_JOBS($search: String!) {
- jobs(where: { ro_number: { _ilike: $search } }) {
+ search_jobs(args: { search: $search }) {
id
ro_number
ownr_fn
diff --git a/hasura/migrations/1598634176882_run_sql_migration/down.yaml b/hasura/migrations/1598634176882_run_sql_migration/down.yaml
new file mode 100644
index 000000000..fe51488c7
--- /dev/null
+++ b/hasura/migrations/1598634176882_run_sql_migration/down.yaml
@@ -0,0 +1 @@
+[]
diff --git a/hasura/migrations/1598634176882_run_sql_migration/up.yaml b/hasura/migrations/1598634176882_run_sql_migration/up.yaml
new file mode 100644
index 000000000..612eac420
--- /dev/null
+++ b/hasura/migrations/1598634176882_run_sql_migration/up.yaml
@@ -0,0 +1,9 @@
+- args:
+ cascade: true
+ read_only: false
+ sql: "CREATE OR REPLACE FUNCTION update_conversation_on_message()\nRETURNS TRIGGER
+ AS $$\nBEGIN\n UPDATE conversations SET last_updated = now() WHERE id = NEW.\"conversationid\";\n
+ \ RETURN NEW; \nEND;\n$$ language 'plpgsql';\n\nDROP TRIGGER IF EXISTS trigger_update_conversation_on_message
+ ON messages;\nCREATE TRIGGER trigger_update_conversation_on_message AFTER INSERT
+ ON messages FOR EACH ROW EXECUTE PROCEDURE update_conversation_on_message();"
+ type: run_sql
diff --git a/hasura/migrations/1598634335411_run_sql_migration/down.yaml b/hasura/migrations/1598634335411_run_sql_migration/down.yaml
new file mode 100644
index 000000000..fe51488c7
--- /dev/null
+++ b/hasura/migrations/1598634335411_run_sql_migration/down.yaml
@@ -0,0 +1 @@
+[]
diff --git a/hasura/migrations/1598634335411_run_sql_migration/up.yaml b/hasura/migrations/1598634335411_run_sql_migration/up.yaml
new file mode 100644
index 000000000..699642c6c
--- /dev/null
+++ b/hasura/migrations/1598634335411_run_sql_migration/up.yaml
@@ -0,0 +1,9 @@
+- args:
+ cascade: true
+ read_only: false
+ sql: "CREATE OR REPLACE FUNCTION update_conversation_on_message()\nRETURNS TRIGGER
+ AS $$\nBEGIN\n UPDATE conversations SET updated_at = now() WHERE id = NEW.\"conversationid\";\n
+ \ RETURN NEW; \nEND;\n$$ language 'plpgsql';\n\nDROP TRIGGER IF EXISTS trigger_update_conversation_on_message
+ ON messages;\nCREATE TRIGGER trigger_update_conversation_on_message AFTER INSERT
+ ON messages FOR EACH ROW EXECUTE PROCEDURE update_conversation_on_message();"
+ type: run_sql