{restLines.map((line) => (
diff --git a/packages/desktop/src/pages/terminal/newLine/index.tsx b/packages/desktop/src/pages/terminal/newLine/index.tsx
index 2c0a403..a0ddf1b 100644
--- a/packages/desktop/src/pages/terminal/newLine/index.tsx
+++ b/packages/desktop/src/pages/terminal/newLine/index.tsx
@@ -1,11 +1,12 @@
import { Avatar, Modal } from "antd";
import { HotKeys, KeyMap } from "react-hotkeys";
-import { useCallback, useState } from "react";
+import { useCallback, useEffect, useState } from "react";
+import { useCreateConvo, useUserSearch } from "../../../controller/index";
import BasicUserRow from "../../../components/User/basicUserDetailsRow";
import { FiSearch } from "react-icons/fi";
import { User } from "@nirvana/core/models";
-import { useUserSearch } from "../../../controller/index";
+import toast from "react-hot-toast";
export default function NewLineModal({
open,
@@ -22,34 +23,38 @@ export default function NewLineModal({
const [searchQuery, setSearchQuery] = useState("");
const { refetch, data: searchRes } = useUserSearch(searchQuery);
- const handleSubmit = () => {
- // ensure that we don't have a one on one chat already with x person if it's one person selected
+ const { mutateAsync, isError, isLoading } = useCreateConvo();
- // upon success,
- // make sure that the list of lines updates for this client and others so that it shows this new line
- // select the line so that it shows up in the line details for this client
+ const [lineName, setLineName] = useState("");
- // handle close once the new line is created
- handleClose();
- };
-
- const handleCancel = () => {
- handleClose();
- };
+ useEffect(() => {
+ if (searchQuery) refetch();
+ }, [searchQuery]);
const onSearch = useCallback(() => {
+ console.log("enter key pressed");
+
if (peopleSearchValue) {
console.log("searching for people in database");
setSearchQuery(peopleSearchValue);
}
- }, [setSearchQuery]);
+ }, [setSearchQuery, peopleSearchValue]);
const selectUser = useCallback(
(userToAdd: User) => {
- setSelectedPeople((prevSelectedUsers) => [
- ...prevSelectedUsers,
- userToAdd,
- ]);
+ setSelectedPeople((prevSelectedUsers) => {
+ // if user is not already in the selected user
+ const foundUser = prevSelectedUsers.find(
+ (currentUser) =>
+ currentUser._id.toString() === userToAdd._id.toString()
+ );
+ if (!foundUser) {
+ return [...prevSelectedUsers, userToAdd];
+ }
+
+ toast.error("you already selected this person below!");
+ return prevSelectedUsers;
+ });
},
[setSelectedPeople]
);
@@ -65,17 +70,48 @@ export default function NewLineModal({
[setSelectedPeople]
);
+ const handleSubmit = useCallback(async () => {
+ // ensure that we don't have a one on one chat already with x person if it's one person selected
+
+ // upon success,
+ // make sure that the list of lines updates for this client and others so that it shows this new line
+ // select the line so that it shows up in the line details for this client
+
+ console.log("trying to create line now!");
+
+ try {
+ if (!selectedPeople?.length) {
+ toast.error("you must select at least one person");
+ return;
+ }
+
+ const selectedMemberIds = selectedPeople.map((selectedPerson) =>
+ selectedPerson._id.toString()
+ );
+
+ await mutateAsync({ lineName, otherMemberIds: selectedMemberIds });
+
+ // handle close once the new line is created
+ handleClose();
+ } catch (error) {
+ toast.error(error);
+ console.error(error);
+ }
+ }, [lineName, selectedPeople]);
+
+ const handleCancel = () => {
+ handleClose();
+ };
+
const keyMap: KeyMap = {
- HANDLE_SEARCH: {
- name: "handle search on enter",
- sequence: "enter",
- action: "keypress",
- },
+ HANDLE_SEARCH: "enter",
};
const handlers = {
HANDLE_SEARCH: onSearch,
};
+ if (isLoading) return one second while we make magic;
+
return (
<>
-
+
+
+
People
-
-
People
+
+
-
-
+ setPeopleSearchValue(e.target.value)}
+ placeholder="search by name or email"
+ />
+
+ enter to search
+
+
+
+ {/* search results */}
+