make my shit work

This commit is contained in:
Иван 2025-12-19 20:41:46 +03:00
parent da29133989
commit ee31b639b2
3 changed files with 48 additions and 42 deletions

View File

@ -4,9 +4,9 @@ const nextConfig: NextConfig = {
images: {
remotePatterns: [
{
protocol: "http",
hostname: "89.169.188.2",
pathname: '/**'
protocol: "https",
hostname: "api.travelmarine.ru",
pathname: "/**",
},
],
unoptimized: true,

View File

@ -3,43 +3,43 @@ import useAuthStore from "@/stores/useAuthStore";
import useAuthPopup from "@/stores/useAuthPopup";
const useApiClient = () => {
const { getToken } = useAuthStore();
const authPopup = useAuthPopup();
const { getToken } = useAuthStore();
const authPopup = useAuthPopup();
const apiClient = axios.create({
baseURL: "http://89.169.188.2/api",
headers: {
"Content-Type": "application/json",
},
});
const apiClient = axios.create({
baseURL: "https://api.travelmarine.ru",
headers: {
"Content-Type": "application/json",
},
});
apiClient.interceptors.request.use(
(config) => {
const token = getToken();
apiClient.interceptors.request.use(
(config) => {
const token = getToken();
if (token) {
config.headers.Authorization = `Token ${token}`;
}
if (token) {
config.headers.Authorization = `Token ${token}`;
}
return config;
},
(error) => {
return Promise.reject(error);
}
);
return config;
},
(error) => {
return Promise.reject(error);
}
);
apiClient.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) {
console.error("Authentication error:", error);
authPopup.open();
}
return Promise.reject(error);
}
);
apiClient.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) {
console.error("Authentication error:", error);
authPopup.open();
}
return Promise.reject(error);
}
);
return apiClient;
return apiClient;
};
export default useApiClient;

View File

@ -1,21 +1,26 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
import { differenceInHours, parseISO } from "date-fns";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
return twMerge(clsx(inputs));
}
const API_BASE_URL = "http://89.169.188.2";
const API_BASE_URL = "https://api.travelmarine.ru";
export const getImageUrl = (relativePath: string): string => {
if (!relativePath) return "";
// Если путь уже абсолютный, возвращаем как есть
if (relativePath.startsWith("http://") || relativePath.startsWith("https://")) {
if (
relativePath.startsWith("http://") ||
relativePath.startsWith("https://")
) {
return relativePath;
}
// Убираем начальный слеш, если есть, и формируем абсолютный URL
const cleanPath = relativePath.startsWith("/") ? relativePath.slice(1) : relativePath;
const cleanPath = relativePath.startsWith("/")
? relativePath.slice(1)
: relativePath;
return `${API_BASE_URL}/${cleanPath}`;
};
@ -67,7 +72,8 @@ export const calculateTotalPrice = (
// Добавляем разницу в минутах
const minutesDiff =
(arrivalDateTime.getMinutes() - departureDateTime.getMinutes()) / 60;
(arrivalDateTime.getMinutes() - departureDateTime.getMinutes()) /
60;
hoursDiff += minutesDiff;
// Округляем до ближайших 0.5 часа
@ -81,4 +87,4 @@ export const calculateTotalPrice = (
console.error("Error calculating price:", error);
return { totalHours: 0, totalPrice: 0 };
}
};
};