Skip to content

Commit a0945ac

Browse files
emsilkinasafipatel
andauthored
Devt 61 (#65)
Co-authored-by: Safi Patel <[email protected]>
1 parent 5241923 commit a0945ac

File tree

28 files changed

+2432
-1866
lines changed

28 files changed

+2432
-1866
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"supabase",
99
"taskrun",
1010
"tekton",
11-
"turbopack"
11+
"turbopack",
12+
"unarchived"
1213
],
1314
"editor.defaultFormatter": "esbenp.prettier-vscode",
1415
"editor.formatOnSave": true,

app/chatrooms/[chatroomId]/components/message-area.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import ReactMarkdown from "react-markdown";
2323
import { toast } from "sonner";
2424
import Logo from "@/shared/components/Logo";
2525
import { Separator } from "@/shared/components/ui/separator";
26+
import { notFound } from "next/navigation";
2627

2728
interface Message extends Tables<"Messages"> {
2829
user_id: string;
@@ -170,10 +171,7 @@ const MessageArea = ({
170171
console.log(
171172
"Error rendering chatroom page, member of chatroom but didn't find information about the underlying classroom"
172173
);
173-
return (
174-
// TODO: make 404 page since this is a classroom not found
175-
<h1> 404 </h1>
176-
);
174+
notFound();
177175
}
178176

179177
// Send the message directly from the browser, and also tell the server action if an LLM is involved

app/classrooms/[classroomId]/chat/page.tsx

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,46 @@ export default async function ChatPage({
8383
if (!chatClient.client) {
8484
if (chatClient.failBecauseDatasetEmpty) {
8585
return user.id === classroomInfo.admin_user_id ? (
86-
<div className="flex gap-4">
87-
<h1>Empty dataset, go upload files for classroom: </h1>
88-
<Button
89-
type="button"
90-
// variant={"ghost"}
91-
// size={"iconLg"}
92-
asChild
93-
>
94-
<Link href={`./upload`} passHref>
95-
<Upload className="scale-[200%]" />
96-
</Link>
97-
</Button>
98-
</div>
86+
<>
87+
<div className="flex flex-col gap-4">
88+
<h2 className="text-3xl font-bold tracking-tight">
89+
{classroomInfo.name}
90+
</h2>
91+
<h1 className="flex flex-row gap-4 text-2xl font-medium tracking-tight text-muted-foreground">
92+
<SpeechIcon className="mb-8 self-center" /> Personal Assistant
93+
</h1>
94+
</div>
95+
<div className="col-span-full flex flex-col items-center justify-center gap-4 py-8 text-center">
96+
<p className="text-gray-500">
97+
Empty dataset, please upload materials to the classroom:
98+
</p>
99+
<Button
100+
type="button"
101+
// variant={"ghost"}
102+
// size={"iconLg"}
103+
asChild
104+
className="flex w-1/5 min-w-fit gap-2"
105+
>
106+
<Link href={`./upload`} passHref className="flex gap-4">
107+
Upload <Upload className="scale-[200%]" />
108+
</Link>
109+
</Button>
110+
</div>
111+
</>
99112
) : (
100-
<h1>
101-
Classroom dataset empty, please ask your instructor to add some
102-
resources!
103-
</h1>
113+
<div className="col-span-full flex flex-col items-center justify-center py-8 text-center">
114+
<p className="text-gray-500">
115+
Classroom dataset empty, please ask your instructor to add some
116+
resources!
117+
</p>
118+
</div>
104119
);
105120
}
106-
return <h1>Server error! </h1>; //TODO fixthis
121+
return (
122+
<div className="col-span-full py-8 text-center">
123+
<p className="text-gray-500">Server error!</p>
124+
</div>
125+
);
107126
}
108127

109128
return (
Lines changed: 95 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,109 @@
11
"use client";
2-
import { useState } from "react";
3-
import { inviteMemberToClassroom } from "../../../actions";
2+
import { ReactNode, useState } from "react";
3+
import { InviteActionResults } from "../../../actions";
44
import { toast } from "sonner";
5+
import { Loader2, UserPlus } from "lucide-react";
6+
import { Button } from "@/shared/components/ui/button";
7+
// import { TooltipUtil } from "@/app/classrooms/clientUtils";
8+
import { Input } from "@/shared/components/ui/input";
9+
import {
10+
Dialog,
11+
DialogContent,
12+
DialogDescription,
13+
DialogFooter,
14+
DialogHeader,
15+
DialogTitle,
16+
DialogTrigger,
17+
} from "@/shared/components/ui/dialog";
18+
import { Label } from "@/shared/components/ui/label";
19+
// import {
20+
// Dialog,
21+
// DialogContent,
22+
// DialogDescription,
23+
// DialogHeader,
24+
// DialogTitle,
25+
// DialogTrigger,
26+
// } from "@/components/ui/dialog";
527

6-
export default function InviteMember({ classroomId }: { classroomId: number }) {
28+
export default function InviteMember({
29+
optimisticUpdateCallback,
30+
dialogTrigger,
31+
}: {
32+
optimisticUpdateCallback: (email: string) => Promise<unknown>;
33+
dialogTrigger?: ReactNode;
34+
}) {
735
const [email, setEmail] = useState("");
8-
const handleInvite = async () => {
9-
try {
10-
await inviteMemberToClassroom(email, classroomId);
11-
setEmail("");
12-
toast.success("Added Member Successfully", {
13-
description: `${email} was added to the class.`,
14-
});
15-
} catch (error: unknown) {
16-
//type unknown for typescript lint
17-
if (error instanceof Error) {
18-
toast.error("The user is already part of the classroom.");
19-
// console.error(error.message);
36+
const [isDialogOpen, setIsDialogOpen] = useState(false);
37+
const [isPending, setIsPending] = useState(false);
38+
39+
const inviteCallback = async () => {
40+
setIsDialogOpen(false);
41+
setIsPending(true);
42+
// startTransition(async () => {
43+
const result: InviteActionResults = (await optimisticUpdateCallback(
44+
email
45+
)) as InviteActionResults;
46+
if (!result.supabaseInsertSuccess) {
47+
if (result.userDoesNotExist) {
48+
toast.error(`User does not exist!`);
49+
} else if (result.userAlreadyInClass) {
50+
toast.error(`User already in class!`);
2051
} else {
21-
console.error("Error Occured");
52+
toast.error(
53+
`Uh oh! Something went wrong when inviting member to classroom.`,
54+
{
55+
description: `Please refresh and try again`,
56+
}
57+
);
2258
}
59+
} else {
60+
toast.success(`Invited user with email ${email} successfully!`);
2361
}
62+
setIsDialogOpen(false);
63+
setIsPending(false);
64+
setEmail("");
65+
return;
2466
};
2567

2668
return (
2769
<div className="my-3 flex gap-5">
28-
<input
29-
type="email"
30-
placeholder="Enter Email"
31-
value={email}
32-
onChange={(e) => setEmail(e.target.value)}
33-
className={
34-
"block w-5/12 rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
35-
}
36-
/>
37-
38-
<button
39-
onClick={handleInvite}
40-
className="w-full rounded-lg bg-blue-700 px-5 py-2.5 text-center text-sm font-medium text-white hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 sm:w-auto"
41-
>
42-
Invite
43-
</button>
70+
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
71+
{dialogTrigger ?? (
72+
<DialogTrigger asChild>
73+
<Button variant="outline" effect={"hoverUnderline"}>
74+
Invite Member <UserPlus />
75+
</Button>
76+
</DialogTrigger>
77+
)}
78+
<DialogContent className="sm:max-w-[425px]">
79+
<DialogHeader>
80+
<DialogTitle>Invite Member</DialogTitle>
81+
<DialogDescription>
82+
Enter the email of the member you would like to invite to your
83+
classroom here.
84+
</DialogDescription>
85+
</DialogHeader>
86+
<div className="grid gap-4 py-4">
87+
<div className="grid grid-cols-4 items-center gap-4">
88+
<Label htmlFor="name" className="text-right">
89+
Email
90+
</Label>
91+
<Input
92+
id="email"
93+
value={email}
94+
className="col-span-3"
95+
onChange={(e) => setEmail(e.target.value)}
96+
/>
97+
</div>
98+
</div>
99+
<DialogFooter>
100+
<Button onClick={inviteCallback} type="submit">
101+
{isPending && <Loader2 className="animate-spin" />}
102+
Invite
103+
</Button>
104+
</DialogFooter>
105+
</DialogContent>
106+
</Dialog>
44107
</div>
45108
);
46109
}

0 commit comments

Comments
 (0)