Skip to content

Commit

Permalink
WIP: Create single team per chat
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Dec 18, 2023
1 parent e416e3c commit 7adcd9b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
1 change: 1 addition & 0 deletions main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ entity Chat {=psl
team_id Int?
team_name String?
team_status String?
showLoader Boolean @default(false)
user User? @relation(fields: [userId], references: [id])
userId Int?
name String?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Chat" ADD COLUMN "showLoader" BOOLEAN NOT NULL DEFAULT false;
21 changes: 15 additions & 6 deletions src/client/components/ConversationWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useQuery } from "@wasp/queries";
import getConversations from "@wasp/queries/getConversations";
import getChat from "@wasp/queries/getChat";
import { useSocket, useSocketListener } from "@wasp/webSocket";
import updateExistingChat from "@wasp/actions/updateExistingChat";

import ConversationsList from "./ConversationList";
import Loader from "./Loader";
Expand All @@ -26,9 +27,13 @@ export default function ConversationWrapper() {
const {
data: currentChatDetails,
refetch: refetchChat,
}: { data: any; refetch: any } = useQuery(getChat, {
chatId: Number(id),
});
}: { data: any; refetch: any } = useQuery(
getChat,
{
chatId: Number(id),
},
{ enabled: !!id }
);
const [isSubmitButtonDisabled, setIsSubmitButtonDisabled] = useState(false);
const { data: conversations, refetch } = useQuery(
getConversations,
Expand All @@ -53,6 +58,7 @@ export default function ConversationWrapper() {
setIsSubmitButtonDisabled(
currentChatDetails?.team_status === "inprogress"
);
setIsLoading(currentChatDetails.showLoader);
}
}, [currentChatDetails]);

Expand Down Expand Up @@ -85,7 +91,8 @@ export default function ConversationWrapper() {
Number(id),
userQuery
);
setIsLoading(true);
// setIsLoading(true);
await updateExistingChat({ chat_id: Number(id), showLoader: true });
const teamId = googleRedirectLoginMsg
? Number(id)
: // @ts-ignore
Expand All @@ -100,9 +107,11 @@ export default function ConversationWrapper() {
socket.emit("newConversationAdded", response.chat_id);
}

setIsLoading(false);
// setIsLoading(false);
await updateExistingChat({ chat_id: Number(id), showLoader: false });
} catch (err: any) {
setIsLoading(false);
// setIsLoading(false);
await updateExistingChat({ chat_id: Number(id), showLoader: false });
console.log("Error: " + err.message);
window.alert("Error: Something went wrong. Please try again later.");
}
Expand Down
38 changes: 25 additions & 13 deletions src/server/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ export const addNewConversationToChat: AddNewConversationToChat<

type UpdateExistingChatPayload = {
chat_id: number;
team_name: string;
team_id: number;
team_status: boolean;
team_name?: string;
team_id?: number;
team_status?: boolean;
showLoader?: boolean;
};

export const updateExistingChat: UpdateExistingChat<
Expand All @@ -149,16 +150,27 @@ export const updateExistingChat: UpdateExistingChat<
if (!context.user) {
throw new HttpError(401);
}
await context.entities.Chat.update({
where: {
id: args.chat_id,
},
data: {
team_id: args.team_id,
team_name: args.team_name,
team_status: args.team_status,
},
});
if (args.showLoader === true || args.showLoader === false) {
await context.entities.Chat.update({
where: {
id: args.chat_id,
},
data: {
showLoader: args.showLoader,
},
});
} else {
await context.entities.Chat.update({
where: {
id: args.chat_id,
},
data: {
team_id: args.team_id,
team_name: args.team_name,
team_status: args.team_status,
},
});
}
};

type AgentPayload = {
Expand Down

0 comments on commit 7adcd9b

Please sign in to comment.