8 Commits

Author SHA1 Message Date
Patryk
a04ef906cd fix merge 2025-06-09 21:49:07 +02:00
Patryk
a51345fd93 Merge remote-tracking branch 'origin/ScreenRotation' 2025-06-09 21:21:15 +02:00
7ec883100f headers user is hidden, [userId] is changed to "Ogłsozenia uzytkownika" 2025-06-09 21:12:10 +02:00
c25495ba3f AppIco added 2025-06-09 20:51:09 +02:00
be51f1e9cc Mail sender is working 2025-06-09 20:39:00 +02:00
14bd178f84 Mail sender is working 2025-06-09 20:38:13 +02:00
7fc1312ddc Avatar + SafeAreaView 2025-06-09 19:27:05 +02:00
1d3cbeef3a Added ScreenRotation to notice and updated userNotices 2025-06-08 17:22:02 +02:00
14 changed files with 393 additions and 341 deletions

View File

@@ -13,6 +13,6 @@ export async function listCategories() {
});
return response.data;
} catch (err) {
console.error("Nie udało się pobrać listy kategorii.", err.response.status);
// console.error("Nie udało się pobrać listy kategorii.", err.response.status);
}
}

View File

@@ -7,10 +7,9 @@ export async function getUserById(userId) {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const response = await axios.get(
`${API_URL}/clients/get/${userId}`,
headers
);
const response = await axios.get(`${API_URL}/clients/get/${userId}`, {
headers: headers,
});
return response.data;
} catch (err) {
console.error(

View File

@@ -0,0 +1,30 @@
import { useAuthStore } from "@/store/authStore";
const API_URL = "https://hopp.zikor.pl/api/v1";
export const sendEmail = async (emailData) => {
const token = useAuthStore.getState().token;
try {
const response = await fetch(`${API_URL}/email/send`, {
method: "POST",
headers: {
"Content-Type": "application/json",
...(token && { Authorization: `Bearer ${token}` }),
},
body: JSON.stringify(emailData),
});
if (!response.ok) {
const errorMessage = `HTTP error! Status: ${response.status}`;
console.error("Error przy wysyłaniu maila", errorMessage);
return { success: false, error: errorMessage };
}
const result = await response.text();
return { success: true, result };
} catch (error) {
console.error("Error przy wysyłaniu maila:", error.message);
return { success: false, error: error.message };
}
};

View File

@@ -5,7 +5,7 @@
"scheme": "com.hamx.artisanconnect",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"icon": "./assets/AppIco.png",
"userInterfaceStyle": "light",
"newArchEnabled": true,
"splash": {

View File

@@ -63,7 +63,7 @@ export default function UserNotices() {
}
};
loadNotices();
}, []);
}, [fetchNotices]);
const showNewToast = (title) => {
const newId = Math.random();

View File

@@ -15,15 +15,15 @@ export default function Home() {
const [isReady, setIsReady] = useState(false);
const fetchNotices = useNoticesStore((state) => state.fetchNotices);
useEffect(() => {
setIsReady(true);
}, []);
// useEffect(() => {
// setIsReady(true);
// }, []);
useEffect(() => {
if (isReady && !token) {
router.replace("/login");
}
}, [isReady, token, router]);
// useEffect(() => {
// if (isReady && !token) {
// router.replace("/login");
// }
// }, [isReady, token, router]);
useEffect(() => {
if (token) {

View File

@@ -17,6 +17,7 @@ return (
}}
>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="user" options={{ headerShown: false }} />
<Stack.Screen
name="(auth)/login"
options={{ headerShown: false }}/>

View File

@@ -1,338 +1,338 @@
import {Link, Stack, useLocalSearchParams} from "expo-router";
import {Box} from "@/components/ui/box";
import {Card} from "@/components/ui/card";
import {Heading} from "@/components/ui/heading";
import {Image} from "@/components/ui/image";
import {Text} from "@/components/ui/text";
import {VStack} from "@/components/ui/vstack";
import {Ionicons} from "@expo/vector-icons";
import { Link, Stack, useLocalSearchParams } from "expo-router";
import { Box } from "@/components/ui/box";
import { Card } from "@/components/ui/card";
import { Heading } from "@/components/ui/heading";
import { Image } from "@/components/ui/image";
import { Text } from "@/components/ui/text";
import { VStack } from "@/components/ui/vstack";
import { Ionicons } from "@expo/vector-icons";
import {
ActivityIndicator,
Dimensions,
FlatList,
View,
TextInput,
ActivityIndicator,
Dimensions,
FlatList,
View,
TextInput,
} from "react-native";
import {useEffect, useState, useRef} from "react";
import {useNoticesStore} from "@/store/noticesStore";
import {useWishlist} from "@/store/wishlistStore";
import {Pressable, ScrollView} from "react-native";
import {getUserById} from "@/api/client";
import { useEffect, useState, useRef } from "react";
import { useNoticesStore } from "@/store/noticesStore";
import { useWishlist } from "@/store/wishlistStore";
import { Pressable, ScrollView } from "react-native";
import { getUserById } from "@/api/client";
const {width} = Dimensions.get("window");
const { width } = Dimensions.get("window");
export default function NoticeDetails() {
const {id} = useLocalSearchParams();
const [images, setImages] = useState([]);
const [isImageLoading, setIsImageLoading] = useState(true);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);
const [notice, setNotice] = useState(null);
const [user, setUser] = useState(null);
const [isUserLoading, setIsUserLoading] = useState(true);
const flatListRef = useRef(null);
const [currentIndex, setCurrentIndex] = useState(0);
const { id } = useLocalSearchParams();
const [images, setImages] = useState([]);
const [isImageLoading, setIsImageLoading] = useState(true);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);
const [notice, setNotice] = useState(null);
const [user, setUser] = useState(null);
const [isUserLoading, setIsUserLoading] = useState(true);
const flatListRef = useRef(null);
const [currentIndex, setCurrentIndex] = useState(0);
const [isMessageFormVisible, setIsMessageFormVisible] = useState(false);
const [message, setMessage] = useState("");
const [Email, setEmail] = useState("");
const handleSendMessage = () => {
console.log("Wiadomość do:", user?.email);
console.log("Email nadawcy:", Email);
console.log("Treść:", message);
const [isMessageFormVisible, setIsMessageFormVisible] = useState(false);
const [message, setMessage] = useState("");
const [Email, setEmail] = useState("");
const handleSendMessage = () => {
console.log("Wiadomość do:", user?.email);
console.log("Email nadawcy:", Email);
console.log("Treść:", message);
setIsMessageFormVisible(false);
setMessage("");
setEmail("");
setIsMessageFormVisible(false);
setMessage("");
setEmail("");
};
const formatDate = (dateString) => {
const date = new Date(dateString);
return date.toLocaleDateString("pl-PL", {
year: "numeric",
month: "2-digit",
day: "2-digit",
});
};
const { getNoticeById, getAllImagesByNoticeId } = useNoticesStore();
const toggleNoticeInWishlist = useWishlist(
(state) => state.toggleNoticeInWishlist
);
const isInWishlist = useWishlist((state) =>
id ? state.wishlistNotices.some((item) => item.noticeId === id) : false
);
const onViewableItemsChanged = useRef(({ viewableItems }) => {
if (viewableItems.length > 0) {
setCurrentIndex(viewableItems[0].index);
}
}).current;
const viewabilityConfig = useRef({
itemVisiblePercentThreshold: 70,
}).current;
useEffect(() => {
const fetchNotice = async () => {
setIsLoading(true);
try {
const noticeData = getNoticeById(Number(id));
if (noticeData) {
setNotice(noticeData);
setError(null);
} else {
setError(new Error(`Notice with ID ${id} not found.`));
}
} catch (err) {
setError(err);
} finally {
setIsLoading(false);
}
};
const formatDate = (dateString) => {
const date = new Date(dateString);
return date.toLocaleDateString("pl-PL", {
year: "numeric",
month: "2-digit",
day: "2-digit",
});
fetchNotice();
}, [id]);
useEffect(() => {
const fetchImage = async () => {
setIsImageLoading(true);
if (notice) {
try {
const fetchedImages = await getAllImagesByNoticeId(notice.noticeId);
setImages(
fetchedImages && fetchedImages.length > 0
? fetchedImages
: { uri: "https://http.cat/404.jpg" }
);
} catch (err) {
console.error("Error while loading images:", err);
setImage({ uri: "https://http.cat/404.jpg" });
} finally {
setIsImageLoading(false);
}
}
};
const {getNoticeById, getAllImagesByNoticeId} = useNoticesStore();
const toggleNoticeInWishlist = useWishlist(
(state) => state.toggleNoticeInWishlist
);
if (notice) {
fetchImage();
}
}, [notice]);
const isInWishlist = useWishlist((state) =>
id ? state.wishlistNotices.some((item) => item.noticeId === id) : false
);
const onViewableItemsChanged = useRef(({viewableItems}) => {
if (viewableItems.length > 0) {
setCurrentIndex(viewableItems[0].index);
useEffect(() => {
const fetchUser = async () => {
if (notice && notice.clientId) {
setIsUserLoading(true);
try {
const userData = await getUserById(notice.clientId);
setUser(userData);
} catch (err) {
console.error("Nie udało się pobrać danych użytkownika:", err);
} finally {
setIsUserLoading(false);
}
}).current;
}
};
const viewabilityConfig = useRef({
itemVisiblePercentThreshold: 70,
}).current;
fetchUser();
}, [notice]);
useEffect(() => {
const fetchNotice = async () => {
setIsLoading(true);
try {
const noticeData = getNoticeById(Number(id));
if (noticeData) {
setNotice(noticeData);
setError(null);
} else {
setError(new Error(`Notice with ID ${id} not found.`));
}
} catch (err) {
setError(err);
} finally {
setIsLoading(false);
}
};
if (isLoading) {
return <ActivityIndicator />;
}
fetchNotice();
}, [id]);
if (error) {
return <Text>Błąd, spróbuj ponownie póżniej: {error.message}</Text>;
}
useEffect(() => {
const fetchImage = async () => {
setIsImageLoading(true);
if (notice) {
try {
const fetchedImages = await getAllImagesByNoticeId(notice.noticeId);
setImages(
fetchedImages && fetchedImages.length > 0
? fetchedImages
: {uri: "https://http.cat/404.jpg"}
);
} catch (err) {
console.error("Error while loading images:", err);
setImage({uri: "https://http.cat/404.jpg"});
} finally {
setIsImageLoading(false);
}
}
};
if (!notice) {
return <Text>Nie znaleziono ogłoszenia</Text>;
}
if (notice) {
fetchImage();
}
}, [notice]);
return (
<Card className="p-0 rounded-lg m-3 flex-1">
<Stack.Screen
options={{
title: notice.title,
}}
/>
{isImageLoading ? (
<Box className="h-auto w-full rounded-md aspect-[1/1] bg-gray-100 items-center justify-center">
<ActivityIndicator size="large" color="#3b82f6" />
</Box>
) : (
<Box className="sticky top-0 z-10 bg-white">
<FlatList
ref={flatListRef}
data={images}
horizontal
snapToInterval={width}
snapToAlignment="start"
decelerationRate="fast"
showsHorizontalScrollIndicator={false}
pagingEnabled
onViewableItemsChanged={onViewableItemsChanged}
viewabilityConfig={viewabilityConfig}
renderItem={({ item, index }) => (
<View style={{ width: width }} className="p-1">
<Image
source={item}
className="h-auto w-auto rounded-md aspect-[1/1]"
alt={`Zdjęcie ${index + 1}`}
resizeMode="cover"
/>
</View>
)}
keyExtractor={(item, index) => index.toString()}
/>
useEffect(() => {
const fetchUser = async () => {
if (notice && notice.clientId) {
setIsUserLoading(true);
try {
const userData = await getUserById(notice.clientId);
setUser(userData);
} catch (err) {
console.error("Nie udało się pobrać danych użytkownika:", err);
} finally {
setIsUserLoading(false);
}
}
};
{images.length > 1 && (
<Box className="flex-row justify-center mt-2">
{images.map((_, index) => (
<Box
key={index}
className={`w-2 h-2 rounded-full mx-1 ${
index === currentIndex ? "bg-primary-500" : "bg-gray-300"
}`}
/>
))}
</Box>
)}
</Box>
)}
fetchUser();
}, [notice]);
<ScrollView showsVerticalScrollIndicator={false}>
<VStack className="p-2">
<Text className="text-sm font-normal mb-2 text-typography-700">
{formatDate(notice.publishDate)}
</Text>
<Text className="text-2xl text-gray-950 font-bold mb-2 text-center bg-gray-50 rounded-md p-2">
{notice.title}
</Text>
if (isLoading) {
return <ActivityIndicator/>;
}
<Box className="flex-row items-center bg-gray-50 rounded-md p-2">
<Heading size="md" className="flex-1 text-xl text-gray-950">
<Text className="text-sm text-typography-500">Cena: </Text>
{notice.price}
</Heading>
if (error) {
return <Text>Błąd, spróbuj ponownie póżniej: {error.message}</Text>;
}
<Pressable
onPress={() => {
toggleNoticeInWishlist(id);
}}
>
<Ionicons
name={isInWishlist ? "heart" : "heart-outline"}
size={24}
color={"primary-heading-500"}
/>
</Pressable>
</Box>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
<Text className="text-sm text-typography-500">
Kategoria:{" "}
<Text className="font-bold text-gray-950">{notice.category}</Text>
</Text>
</Box>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
<Text className="text-2xl text-gray-950">Opis ogloszenia</Text>
<Text className="text-sm text-typography-700">
{notice.description}
</Text>
</Box>
if (!notice) {
return <Text>Nie znaleziono ogłoszenia</Text>;
}
return (
<Card className="p-0 rounded-lg m-3 flex-1">
<Stack.Screen
options={{
title: notice.title,
}}
/>
{isImageLoading ? (
<Box className="h-auto w-full rounded-md aspect-[1/1] bg-gray-100 items-center justify-center">
<ActivityIndicator size="large" color="#3b82f6"/>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
<Text className="text-sm text-typography-500">Uzytkownik:</Text>
{isUserLoading ? (
<ActivityIndicator />
) : user ? (
<>
<Box className="mr-4">
<Image
source={{
uri:
user.profileImage ||
"https://th.bing.com/th/id/OIP.3coo_N8sieled8QNroQmkgHaHa?rs=1&pid=ImgDetMain",
}} // Domyślny obraz, jeśli brak zdjęcia profilowego
className="h-12 w-12 rounded-full"
alt="Zdjęcie profilowe"
/>
</Box>
<Box className="flex-1">
<Text className="text-xl font-bold text-gray-950">
{user.firstName} {user.lastName}
</Text>
<Text className="text-sm text-typography-700">
Email: {user.email}
</Text>
<Pressable
onPress={() => setIsMessageFormVisible(true)}
className="mt-3 bg-primary-500 py-2 px-4 rounded-md"
>
<Text className="text-white text-center font-bold">
Wyślij wiadomość
</Text>
</Pressable>
<Link href={`/user/${notice.clientId}`}>
<Text className="text-xl p-3 font-bold text-center text-typography-700 mt-3">
Zobacz więcej ogłoszeń od {user.firstName}
</Text>
</Link>
</Box>
</>
) : (
<Box className="sticky top-0 z-10 bg-white">
<FlatList
ref={flatListRef}
data={images}
horizontal
snapToInterval={width}
snapToAlignment="start"
decelerationRate="fast"
showsHorizontalScrollIndicator={false}
pagingEnabled
onViewableItemsChanged={onViewableItemsChanged}
viewabilityConfig={viewabilityConfig}
renderItem={({item, index}) => (
<View style={{width: width}} className="p-1">
<Image
source={item}
className="h-auto w-auto rounded-md aspect-[1/1]"
alt={`Zdjęcie ${index + 1}`}
resizeMode="cover"
/>
</View>
)}
keyExtractor={(item, index) => index.toString()}
/>
{images.length > 1 && (
<Box className="flex-row justify-center mt-2">
{images.map((_, index) => (
<Box
key={index}
className={`w-2 h-2 rounded-full mx-1 ${
index === currentIndex ? "bg-primary-500" : "bg-gray-300"
}`}
/>
))}
</Box>
)}
</Box>
<Text>Błąd podczas ładowania danych użytkownika</Text>
)}
</Box>
</VStack>
</ScrollView>
{isMessageFormVisible && (
<View className="absolute inset-0 bg-black bg-opacity-50 justify-center items-center z-20">
<View className="bg-white p-4 rounded-lg w-4/5">
<Text className="text-lg font-bold mb-4">
Wyślij wiadomość do {user?.firstName}
</Text>
<ScrollView showsVerticalScrollIndicator={false}>
<VStack className="p-2">
<Text className="text-sm font-normal mb-2 text-typography-700">
{formatDate(notice.publishDate)}
</Text>
<Text className="text-2xl text-gray-950 font-bold mb-2 text-center bg-gray-50 rounded-md p-2">
{notice.title}
</Text>
<Text className="text-sm font-medium mb-1">Do:</Text>
<Text className="bg-gray-100 p-3 rounded text-gray-500">
{user?.email || "Brak adresu e-mail"}
</Text>
<Text className="text-sm font-medium mb-1">Twój e-mail:</Text>
<TextInput
className="border border-gray-300 p-2 rounded"
placeholder="Wpisz swój adres e-mail"
value={Email}
onChangeText={setEmail}
/>
<Box className="flex-row items-center bg-gray-50 rounded-md p-2">
<Heading size="md" className="flex-1 text-xl text-gray-950">
<Text className="text-sm text-typography-500">Cena: </Text>
{notice.price}
</Heading>
<TextInput
className="border border-gray-300 rounded-md p-2 mb-4 h-32 text-left"
multiline
numberOfLines={4}
placeholder="Napisz swoją wiadomość..."
value={message}
onChangeText={setMessage}
/>
<Pressable
onPress={() => {
toggleNoticeInWishlist(id);
}}
>
<Ionicons
name={isInWishlist ? "heart" : "heart-outline"}
size={24}
color={"primary-heading-500"}
/>
</Pressable>
</Box>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
<Text className="text-sm text-typography-500">
Kategoria:{" "}
<Text className="font-bold text-gray-950">{notice.category}</Text>
</Text>
</Box>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
<Text className="text-2xl text-gray-950">Opis ogloszenia</Text>
<Text className="text-sm text-typography-700">
{notice.description}
</Text>
</Box>
<View className="flex-row justify-end space-x-2">
<Pressable
onPress={() => setIsMessageFormVisible(false)}
className="bg-gray-300 py-2 px-4 rounded-md"
>
<Text className="text-gray-800">Anuluj</Text>
</Pressable>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
<Text className="text-sm text-typography-500">Uzytkownik:</Text>
{isUserLoading ? (
<ActivityIndicator/>
) : user ? (
<>
<Box className="mr-4">
<Image
source={{
uri:
user.profileImage ||
"https://th.bing.com/th/id/OIP.3coo_N8sieled8QNroQmkgHaHa?rs=1&pid=ImgDetMain",
}} // Domyślny obraz, jeśli brak zdjęcia profilowego
className="h-12 w-12 rounded-full"
alt="Zdjęcie profilowe"
/>
</Box>
<Box className="flex-1">
<Text className="text-xl font-bold text-gray-950">
{user.firstName} {user.lastName}
</Text>
<Text className="text-sm text-typography-700">
Email: {user.email}
</Text>
<Pressable
onPress={() => setIsMessageFormVisible(true)}
className="mt-3 bg-primary-500 py-2 px-4 rounded-md"
>
<Text className="text-white text-center font-bold">
Wyślij wiadomość
</Text>
</Pressable>
<Link href={`/user/${notice.clientId}`}>
<Text className="text-xl p-3 font-bold text-center text-typography-700 mt-3">
Zobacz więcej ogłoszeń od {user.firstName}
</Text>
</Link>
</Box>
</>
) : (
<Text>Błąd podczas ładowania danych użytkownika</Text>
)}
</Box>
</VStack>
</ScrollView>
{isMessageFormVisible && (
<View className="absolute inset-0 bg-black bg-opacity-50 justify-center items-center z-20">
<View className="bg-white p-4 rounded-lg w-4/5">
<Text className="text-lg font-bold mb-4">
Wyślij wiadomość do {user?.firstName}
</Text>
<Text className="text-sm font-medium mb-1">Do:</Text>
<Text className="bg-gray-100 p-3 rounded text-gray-500">
{user?.email || "Brak adresu e-mail"}
</Text>
<Text className="text-sm font-medium mb-1">Twój e-mail:</Text>
<TextInput
className="border border-gray-300 p-2 rounded"
placeholder="Wpisz swój adres e-mail"
value={Email}
onChangeText={setEmail}
/>
<TextInput
className="border border-gray-300 rounded-md p-2 mb-4 h-32 text-left"
multiline
numberOfLines={4}
placeholder="Napisz swoją wiadomość..."
value={message}
onChangeText={setMessage}
/>
<View className="flex-row justify-end space-x-2">
<Pressable
onPress={() => setIsMessageFormVisible(false)}
className="bg-gray-300 py-2 px-4 rounded-md"
>
<Text className="text-gray-800">Anuluj</Text>
</Pressable>
<Pressable
onPress={handleSendMessage}
className="bg-primary-500 py-2 px-4 rounded-md"
>
<Text className="text-white">Wyślij</Text>
</Pressable>
</View>
</View>
</View>
)}
</Card>
);
<Pressable
onPress={handleSendMessage}
className="bg-primary-500 py-2 px-4 rounded-md"
>
<Text className="text-white">Wyślij</Text>
</Pressable>
</View>
</View>
</View>
)}
</Card>
);
}

View File

@@ -0,0 +1,11 @@
import { Stack } from 'expo-router';
export default function UserLayout() {
return (
<Stack
screenOptions={{
headerTitle: 'Ogłoszenia użytkownika',
}}
/>
);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

View File

@@ -1,6 +1,5 @@
import { View, FlatList } from "react-native";
import { useEffect, useState } from "react";
import { useAuthStore } from "@/store/authStore";
import { Heading } from "@/components/ui/heading";
import { Text } from "@/components/ui/text";
import { Link } from "expo-router";
@@ -17,7 +16,6 @@ export function CategorySection({ notices, title }) {
setCategoryMap(data);
}
};
fetchCategories();
}, []);

View File

@@ -43,6 +43,7 @@
"expo-image-picker": "~16.1.4",
"expo-linking": "~7.1.4",
"expo-router": "~5.0.5",
"expo-screen-orientation": "~8.1.7",
"expo-status-bar": "~2.2.3",
"expo-web-browser": "~14.1.6",
"form-data": "^4.0.2",
@@ -7012,6 +7013,16 @@
"node": ">=10"
}
},
"node_modules/expo-screen-orientation": {
"version": "8.1.7",
"resolved": "https://registry.npmjs.org/expo-screen-orientation/-/expo-screen-orientation-8.1.7.tgz",
"integrity": "sha512-nYwadYtdU6mMDk0MCHMPPPQtBoeFYJ2FspLRW+J35CMLqzE4nbpwGeiImfXzkvD94fpOCfI4KgLj5vGauC3pfA==",
"license": "MIT",
"peerDependencies": {
"expo": "*",
"react-native": "*"
}
},
"node_modules/expo-status-bar": {
"version": "2.2.3",
"license": "MIT",

View File

@@ -62,7 +62,8 @@
"react-native-svg": "15.11.2",
"react-native-web": "~0.20.0",
"tailwindcss": "^3.4.17",
"zustand": "^5.0.3"
"zustand": "^5.0.3",
"expo-screen-orientation": "~8.1.7"
},
"devDependencies": {
"@babel/core": "^7.20.0",

View File

@@ -11,22 +11,23 @@ let interceptorInitialized = false;
export const useAuthStore = create(
persist(
(set, get) => {
// if (!interceptorInitialized.current) {
// axios.interceptors.response.use(
// (response) => response,
// (error) => {
// if (
// (error.response && error.response.status === 401) ||
// error.response.status === 403
// ) {
// set({ user_id: null, token: null, isLoading: false });
// delete axios.defaults.headers.common["Authorization"];
// }
// return Promise.reject(error);
// }
// );
// interceptorInitialized = true;
// }
if (!interceptorInitialized.current) {
axios.interceptors.response.use(
(response) => response,
(error) => {
if (
(error.response && error.response.status === 401) ||
error.response.status === 403
) {
set({ user_id: null, token: null, isLoading: false });
delete axios.defaults.headers.common["Authorization"];
router.replace("/login");
}
return Promise.reject(error);
}
);
interceptorInitialized = true;
}
return {
user_id: null,
token: null,