feat(seller): multi-user seller dashboard (owner + staff) #2

Merged
ArdaSamadi merged 3 commits from feat/seller-team into main 2026-07-01 14:04:20 +00:00
2 changed files with 38 additions and 2 deletions
Showing only changes of commit 3502168a8b - Show all commits

View File

@ -1,7 +1,10 @@
import { Link } from "@remix-run/react"; import { Link } from "@remix-run/react";
import AppInput from "../AppInput"; import AppInput from "../AppInput";
import { useState } from "react"; import { useState } from "react";
import { useGetUserThreads } from "../../requestHandler/use-chat-hooks"; import {
useGetUserThreads,
useGetStoreThreads,
} from "../../requestHandler/use-chat-hooks";
import { import {
ThreadList, ThreadList,
ThreadParticipant, ThreadParticipant,
@ -20,7 +23,16 @@ interface ThreadsPageProps {
export default function ThreadsPage({ type, storeId }: ThreadsPageProps) { export default function ThreadsPage({ type, storeId }: ThreadsPageProps) {
const [searchValue, setSearchValue] = useState(""); const [searchValue, setSearchValue] = useState("");
const { data: threads, isLoading, isError, refetch } = useGetUserThreads(); // Seller dashboard shows the STORE's inbox; the profile page shows the user's
// personal (buyer) chats. Two different endpoints so the two never mix.
const userThreads = useGetUserThreads();
const storeThreads = useGetStoreThreads(type === "store" ? storeId : undefined);
const {
data: threads,
isLoading,
isError,
refetch,
} = type === "store" ? storeThreads : userThreads;
const sortedThreads = threads?.sort((a, b) => { const sortedThreads = threads?.sort((a, b) => {
const dateA = new Date(a.lastMessageTime || "2025-01-18T00:00:00.000Z"); const dateA = new Date(a.lastMessageTime || "2025-01-18T00:00:00.000Z");
const dateB = new Date(b.lastMessageTime || "2025-01-18T00:00:00.000Z"); const dateB = new Date(b.lastMessageTime || "2025-01-18T00:00:00.000Z");

View File

@ -31,6 +31,30 @@ export function useGetUserThreads() {
}); });
} }
/**
* List a STORE's inbox (owner + staff), scoped to the store's own threads.
* Distinct from useGetUserThreads(), which returns the user's personal buyer chats.
*/
export function useGetStoreThreads(storeId?: string) {
const token = useAuthToken();
return useQuery({
queryKey: ["getStoreThreads", storeId],
queryFn: async () => {
if (!token) {
throw new Error("Authentication token is required");
}
const chatApi = createChatApi(token);
return await chatApi.apiChatV1ThreadsListList({ storeId });
},
enabled: !!token && !!storeId,
retry: 1,
retryDelay: 3000,
refetchOnWindowFocus: false,
refetchInterval: 20 * 1000,
});
}
/** /**
* Server-side function to get thread details * Server-side function to get thread details
*/ */