Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show user feedback on admin panel #197

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 82 additions & 11 deletions src/app/admin/projects/[project_id]/chats/[chat_id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"use client";

import loading from "@/components/ui/loading";
import Loading from "@/components/ui/loading";
import { ChatMessageType } from "@/types/chat";
import { Project } from "@/types/project";
import { API } from "@/utils/api";
import { useQuery } from "@tanstack/react-query";
import Link from "next/link";
import Image from "next/image";
import { useState } from "react";
import Modal from "@/components/modal";
import { Feedback } from "@/types/test";

export default function Page({
params,
Expand All @@ -27,6 +29,30 @@ export default function Page({
const project: Project = projectQuery.data;
const chats: any | undefined = chatQuery.data;

const feedbackQuery = useQuery({
queryKey: ["project", project_id, "chat", chat_id],
queryFn: () => API.feedback.list(project_id, chat_id),
});
Comment on lines +32 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the expected type of data here? useQuery<DataType>({...

Copy link
Contributor Author

@Pranshu1902 Pranshu1902 May 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skks1212 there is no existing DataType declared for useQuery response, right? Should I just declare a new one? Also, the backend PR was merged but the staging hasn't been updated, could you redeploy that.

const feedbacks = feedbackQuery.data;
const feedbacksMap = feedbacks?.data
.map((feedback: any) => ({ [feedback.chat_message]: feedback }))
.reduce(
(acc: string, feedbackObj: any) => Object.assign(acc, feedbackObj),
{},
);

const [showFeedBackModal, setShowFeedBackModal] = useState({
open: false,
feedback: {
external_id: "",
chat_message: "",
liked: true,
message: "",
created_at: "",
modified_at: "",
},
});

return (
<div>
<h1 className="text-3xl font-bold">{project?.title}</h1>
Expand Down Expand Up @@ -69,17 +95,41 @@ export default function Page({
{chat.message}
</div>
) : chat.messageType === ChatMessageType.AYUSHMA ? (
<div className="border border-gray-300 hover:bg-secondary bg-secondaryActive rounded-lg p-4 flex gap-3 items-center">
<div className="flex items-center justify-center w-10 h-10 text-2xl shrink-0 text-center rounded-full">
<Image
className="p-0.5"
src="/logo.svg"
alt="Logo"
width={100}
height={100}
/>
<div className="border border-gray-300 hover:bg-secondary bg-secondaryActive rounded-lg p-4 flex justify-between gap-3 items-center">
<div className="flex items-center gap-3">
<div className="flex items-center justify-center w-10 h-10 text-2xl shrink-0 text-center rounded-full">
<Image
className="p-0.5"
src="/logo.svg"
alt="Logo"
width={100}
height={100}
/>
</div>
{chat.message}
</div>
<div>
{Object.keys(feedbacksMap[chat.external_id] || {})
.length !== 0 && (
<div className="flex gap-2">
{feedbacksMap[chat.external_id].liked ? (
<i className="fas fa-thumbs-up p-1 rounded text-green-900 bg-green-100" />
) : (
<i className="fas fa-thumbs-down p-1 rounded text-red-900 bg-red-100" />
)}
<p
onClick={() =>
setShowFeedBackModal({
open: true,
feedback: feedbacksMap[chat.external_id],
})
}
>
<i className="fa fa-eye"></i>
</p>
</div>
)}
</div>
{chat.message}
</div>
) : (
<div className="flex items-center justify-center w-10 h-10 text-2xl shrink-0 text-center bg-gray-300 rounded-full">
Expand All @@ -101,6 +151,27 @@ export default function Page({
Chat not found
</div>
)}
<Modal
onClose={() =>
setShowFeedBackModal({ ...showFeedBackModal, open: false })
}
show={showFeedBackModal.open}
className="w-[500px]"
>
<div className="flex flex-col gap-2 p-6">
<div className="flex items-center gap-3">
<p className="font-bold text-xl">Feedback</p>
<div>
{showFeedBackModal.feedback.liked ? (
<i className="fas fa-thumbs-up p-1 rounded text-green-900 bg-green-100" />
) : (
<i className="fas fa-thumbs-down p-1 rounded text-red-900 bg-red-100" />
)}
</div>
</div>
<p>Message: {showFeedBackModal.feedback.message}</p>
</div>
</Modal>
</div>
);
}
4 changes: 3 additions & 1 deletion src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use client"
"use client";

import { ChatConverseStream, ChatFeedbackType } from "@/types/chat";
import {
Expand Down Expand Up @@ -438,6 +438,8 @@ export const API = {
feedback: {
create: (feedback: Partial<ChatFeedbackType>) =>
request(`feedback`, "POST", { ...feedback }),
list: (project_id: string, chat_id: string) =>
request(`projects/${project_id}/chats/${chat_id}/feedbacks`, "GET"),
},
users: {
get: (username: string) => request(`users/${username}`, "GET"),
Expand Down