Fixed 404 issue #39

This commit is contained in:
2026-01-09 18:28:07 +01:00
parent be5043196f
commit 550a4cc04b
2 changed files with 17 additions and 8 deletions
+8 -4
View File
@@ -13,16 +13,20 @@ import { PlusCircle } from "lucide-react";
import { UserProfile } from "@/hooks/get-user"; import { UserProfile } from "@/hooks/get-user";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import axios from "axios"; import axios from "axios";
import { getProfileByUsername } from "@/actions/get-profile";
import { toast } from "sonner";
export default function StartNewDM() { export default function StartNewDM() {
const [username, setUsername] = useState(""); const [username, setUsername] = useState("");
const router = useRouter(); const router = useRouter();
const handleStartDM = async () => { const handleStartDM = async () => {
const res = await axios.get("/api/profile", { const user = await getProfileByUsername(username);
params: { username }, if (!user) {
}); toast.error("User not found");
const user = res.data as UserProfile; return;
}
router.push(`/chat/${user.id}`); router.push(`/chat/${user.id}`);
setUsername(""); setUsername("");
}; };
+9 -4
View File
@@ -10,6 +10,8 @@ import DMItem from "./DMItem";
import App from "@/types/app"; import App from "@/types/app";
import { UserProfile } from "@/hooks/get-user"; import { UserProfile } from "@/hooks/get-user";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { toast } from "sonner";
import { getProfileByUsername } from "@/actions/get-profile";
export default function SidebarDMs({ app }: { app: App }) { export default function SidebarDMs({ app }: { app: App }) {
const router = useRouter(); const router = useRouter();
@@ -78,11 +80,14 @@ export default function SidebarDMs({ app }: { app: App }) {
variant="ghost" variant="ghost"
className="w-full justify-start gap-2 text-sm truncate" className="w-full justify-start gap-2 text-sm truncate"
onClick={async () => { onClick={async () => {
const res = await axios.get("/api/profile", { const user = await getProfileByUsername(query);
params: { username: query }, if (!user) {
}); toast.error("User not found");
const user = res.data as UserProfile; return;
}
router.push(`/chat/${user.id}`); router.push(`/chat/${user.id}`);
setQuery("");
}} }}
> >
<Plus className="h-4 w-4" /> <Plus className="h-4 w-4" />