Fixed toaster, updated add conversation dialog
This commit is contained in:
parent
9deffbb099
commit
246b36abc9
3 changed files with 76 additions and 45 deletions
|
|
@ -12,16 +12,27 @@ import {
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { toast } from "@tensamin/shared/log";
|
import { toast } from "@tensamin/shared/log";
|
||||||
import { useSocket } from "@tensamin/ttp/context";
|
import { useSocket } from "@tensamin/ttp/context";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { Loader2 } from "lucide-react";
|
||||||
|
|
||||||
/**
|
// The page
|
||||||
* Executes Page.
|
|
||||||
* @param none This function has no parameters.
|
|
||||||
* @returns unknown.
|
|
||||||
*/
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
|
return (
|
||||||
|
<div className="p-3 flex gap-2">
|
||||||
|
<AddConversationButton />
|
||||||
|
<Button disabled>Add Community</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add Conversation Button Component
|
||||||
|
function AddConversationButton() {
|
||||||
const { send } = useSocket();
|
const { send } = useSocket();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
function submit(username: string | null) {
|
function submit(username: string | null) {
|
||||||
|
if (loading) return;
|
||||||
|
|
||||||
const schema = z
|
const schema = z
|
||||||
.string()
|
.string()
|
||||||
.min(1, "Username is too short")
|
.min(1, "Username is too short")
|
||||||
|
|
@ -34,15 +45,27 @@ export default function Page() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTimeout(() => setLoading(true), 500);
|
||||||
|
|
||||||
send("add_conversation", {
|
send("add_conversation", {
|
||||||
chat_partner_name: result.data,
|
chat_partner_name: result.data,
|
||||||
})
|
})
|
||||||
.then(() => toast("success", "Conversation added"))
|
.then(() => {
|
||||||
.catch(() => toast("error", "Failed to add conversation"));
|
toast("success", "Conversation added");
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (String(error).includes("error_not_found")) {
|
||||||
|
toast("error", "User not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast("error", "Failed to add conversation, check console for details");
|
||||||
|
console.error("Failed to add conversation", error);
|
||||||
|
})
|
||||||
|
.finally(() => setLoading(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-3 flex gap-2">
|
|
||||||
<Dialog>
|
<Dialog>
|
||||||
<DialogTrigger render={<Button>Add Conversation</Button>} />
|
<DialogTrigger render={<Button>Add Conversation</Button>} />
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
|
|
@ -50,8 +73,8 @@ export default function Page() {
|
||||||
<DialogTitle>New Conversation</DialogTitle>
|
<DialogTitle>New Conversation</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
Add a new conversation. Just enter the username of the person you
|
Add a new conversation. Just enter the username of the person you want
|
||||||
want to add as a conversation.
|
to add as a conversation.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
<form
|
<form
|
||||||
className="flex flex-col gap-5"
|
className="flex flex-col gap-5"
|
||||||
|
|
@ -63,6 +86,7 @@ export default function Page() {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
|
required
|
||||||
type="text"
|
type="text"
|
||||||
id="username"
|
id="username"
|
||||||
name="username"
|
name="username"
|
||||||
|
|
@ -70,12 +94,12 @@ export default function Page() {
|
||||||
/>
|
/>
|
||||||
<div className="flex w-full justify-end gap-1">
|
<div className="flex w-full justify-end gap-1">
|
||||||
<DialogClose render={<Button variant="outline">Cancel</Button>} />
|
<DialogClose render={<Button variant="outline">Cancel</Button>} />
|
||||||
<Button type="submit">Continue</Button>
|
<Button disabled={loading} type="submit">
|
||||||
|
{loading && <Loader2 className="animate-spin" />} Continue
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
<Button disabled>Add Community</Button>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,13 @@ export const socket = {
|
||||||
}),
|
}),
|
||||||
response: z.object({}),
|
response: z.object({}),
|
||||||
},
|
},
|
||||||
|
add_conversation: {
|
||||||
|
request: z.object({
|
||||||
|
chat_partner_id: z.number().optional(),
|
||||||
|
chat_partner_name: z.string().min(1).max(15).optional(),
|
||||||
|
}),
|
||||||
|
response: z.object({}),
|
||||||
|
},
|
||||||
} satisfies Record<string, { request: z.ZodType; response: z.ZodType }>;
|
} satisfies Record<string, { request: z.ZodType; response: z.ZodType }>;
|
||||||
|
|
||||||
export type Socket = typeof socket;
|
export type Socket = typeof socket;
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ const Toaster = ({ ...props }: ToasterProps) => {
|
||||||
}}
|
}}
|
||||||
style={
|
style={
|
||||||
{
|
{
|
||||||
"--normal-bg": "var(--popover)",
|
"--normal-bg": "var(--color-popover)",
|
||||||
"--normal-text": "var(--popover-foreground)",
|
"--normal-text": "var(--color-popover-foreground)",
|
||||||
"--normal-border": "var(--border)",
|
"--normal-border": "var(--color-border)",
|
||||||
"--border-radius": "var(--radius)",
|
"--border-radius": "var(--radius)",
|
||||||
} as React.CSSProperties
|
} as React.CSSProperties
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue