update
This commit is contained in:
@@ -9,6 +9,7 @@ import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
|||||||
import { formatDistanceToNow } from "date-fns";
|
import { formatDistanceToNow } from "date-fns";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { getCookie } from "@/lib/client-utils";
|
||||||
|
|
||||||
interface Chat {
|
interface Chat {
|
||||||
_id: string;
|
_id: string;
|
||||||
@@ -36,12 +37,12 @@ export default function ChatList() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchVendorData = async () => {
|
const fetchVendorData = async () => {
|
||||||
try {
|
try {
|
||||||
// Get vendor info from session storage or context
|
// Get vendor info from cookies
|
||||||
const vendorId = sessionStorage.getItem("vendorId");
|
const vendorId = getCookie("vendorId");
|
||||||
|
|
||||||
if (!vendorId) {
|
if (!vendorId) {
|
||||||
toast.error("You need to be logged in to view chats");
|
toast.error("You need to be logged in to view chats");
|
||||||
router.push("/login");
|
router.push("/auth/login");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ export default function ChatList() {
|
|||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const vendorId = sessionStorage.getItem("vendorId");
|
const vendorId = getCookie("vendorId");
|
||||||
|
|
||||||
// Fetch chats
|
// Fetch chats
|
||||||
const chatsResponse = await axios.get(`/api/chats/vendor/${vendorId}`);
|
const chatsResponse = await axios.get(`/api/chats/vendor/${vendorId}`);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { getCookie } from "@/lib/client-utils";
|
||||||
|
|
||||||
interface UnreadCounts {
|
interface UnreadCounts {
|
||||||
totalUnread: number;
|
totalUnread: number;
|
||||||
@@ -28,7 +29,7 @@ export default function ChatNotifications() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUnreadCounts = async () => {
|
const fetchUnreadCounts = async () => {
|
||||||
try {
|
try {
|
||||||
const vendorId = sessionStorage.getItem("vendorId");
|
const vendorId = getCookie("vendorId");
|
||||||
|
|
||||||
if (!vendorId) return;
|
if (!vendorId) return;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Textarea } from "@/components/ui/textarea";
|
|||||||
import { ArrowLeft, Send, RefreshCw } from "lucide-react";
|
import { ArrowLeft, Send, RefreshCw } from "lucide-react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { getCookie } from "@/lib/client-utils";
|
||||||
|
|
||||||
export default function NewChatForm() {
|
export default function NewChatForm() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -23,7 +24,7 @@ export default function NewChatForm() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchVendorStores = async () => {
|
const fetchVendorStores = async () => {
|
||||||
try {
|
try {
|
||||||
const vendorId = sessionStorage.getItem("vendorId");
|
const vendorId = getCookie("vendorId");
|
||||||
|
|
||||||
if (!vendorId) {
|
if (!vendorId) {
|
||||||
toast.error("You need to be logged in");
|
toast.error("You need to be logged in");
|
||||||
|
|||||||
@@ -26,4 +26,14 @@ export async function clientFetch(url: string, options: RequestInit = {}): Promi
|
|||||||
console.error(`Client fetch error at ${url}:`, error);
|
console.error(`Client fetch error at ${url}:`, error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a cookie value by name
|
||||||
|
*/
|
||||||
|
export function getCookie(name: string): string | undefined {
|
||||||
|
return document.cookie
|
||||||
|
.split('; ')
|
||||||
|
.find(row => row.startsWith(`${name}=`))
|
||||||
|
?.split('=')[1];
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user