feat(seller): multi-user seller dashboard (owner + staff) #2
@ -1,7 +1,10 @@
|
||||
import { Link } from "@remix-run/react";
|
||||
import AppInput from "../AppInput";
|
||||
import { useState } from "react";
|
||||
import { useGetUserThreads } from "../../requestHandler/use-chat-hooks";
|
||||
import {
|
||||
useGetUserThreads,
|
||||
useGetStoreThreads,
|
||||
} from "../../requestHandler/use-chat-hooks";
|
||||
import {
|
||||
ThreadList,
|
||||
ThreadParticipant,
|
||||
@ -20,7 +23,16 @@ interface ThreadsPageProps {
|
||||
|
||||
export default function ThreadsPage({ type, storeId }: ThreadsPageProps) {
|
||||
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 dateA = new Date(a.lastMessageTime || "2025-01-18T00:00:00.000Z");
|
||||
const dateB = new Date(b.lastMessageTime || "2025-01-18T00:00:00.000Z");
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user