make my shit work
This commit is contained in:
parent
da29133989
commit
ee31b639b2
|
|
@ -4,9 +4,9 @@ const nextConfig: NextConfig = {
|
||||||
images: {
|
images: {
|
||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
{
|
{
|
||||||
protocol: "http",
|
protocol: "https",
|
||||||
hostname: "89.169.188.2",
|
hostname: "api.travelmarine.ru",
|
||||||
pathname: '/**'
|
pathname: "/**",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
unoptimized: true,
|
unoptimized: true,
|
||||||
|
|
|
||||||
|
|
@ -3,43 +3,43 @@ import useAuthStore from "@/stores/useAuthStore";
|
||||||
import useAuthPopup from "@/stores/useAuthPopup";
|
import useAuthPopup from "@/stores/useAuthPopup";
|
||||||
|
|
||||||
const useApiClient = () => {
|
const useApiClient = () => {
|
||||||
const { getToken } = useAuthStore();
|
const { getToken } = useAuthStore();
|
||||||
const authPopup = useAuthPopup();
|
const authPopup = useAuthPopup();
|
||||||
|
|
||||||
const apiClient = axios.create({
|
const apiClient = axios.create({
|
||||||
baseURL: "http://89.169.188.2/api",
|
baseURL: "https://api.travelmarine.ru",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
apiClient.interceptors.request.use(
|
apiClient.interceptors.request.use(
|
||||||
(config) => {
|
(config) => {
|
||||||
const token = getToken();
|
const token = getToken();
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
config.headers.Authorization = `Token ${token}`;
|
config.headers.Authorization = `Token ${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
apiClient.interceptors.response.use(
|
apiClient.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
(error) => {
|
(error) => {
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
console.error("Authentication error:", error);
|
console.error("Authentication error:", error);
|
||||||
authPopup.open();
|
authPopup.open();
|
||||||
}
|
}
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return apiClient;
|
return apiClient;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useApiClient;
|
export default useApiClient;
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,26 @@
|
||||||
import { clsx, type ClassValue } from "clsx"
|
import { clsx, type ClassValue } from "clsx";
|
||||||
import { twMerge } from "tailwind-merge"
|
import { twMerge } from "tailwind-merge";
|
||||||
import { differenceInHours, parseISO } from "date-fns";
|
import { differenceInHours, parseISO } from "date-fns";
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
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 => {
|
export const getImageUrl = (relativePath: string): string => {
|
||||||
if (!relativePath) return "";
|
if (!relativePath) return "";
|
||||||
// Если путь уже абсолютный, возвращаем как есть
|
// Если путь уже абсолютный, возвращаем как есть
|
||||||
if (relativePath.startsWith("http://") || relativePath.startsWith("https://")) {
|
if (
|
||||||
|
relativePath.startsWith("http://") ||
|
||||||
|
relativePath.startsWith("https://")
|
||||||
|
) {
|
||||||
return relativePath;
|
return relativePath;
|
||||||
}
|
}
|
||||||
// Убираем начальный слеш, если есть, и формируем абсолютный URL
|
// Убираем начальный слеш, если есть, и формируем абсолютный URL
|
||||||
const cleanPath = relativePath.startsWith("/") ? relativePath.slice(1) : relativePath;
|
const cleanPath = relativePath.startsWith("/")
|
||||||
|
? relativePath.slice(1)
|
||||||
|
: relativePath;
|
||||||
return `${API_BASE_URL}/${cleanPath}`;
|
return `${API_BASE_URL}/${cleanPath}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -67,7 +72,8 @@ export const calculateTotalPrice = (
|
||||||
|
|
||||||
// Добавляем разницу в минутах
|
// Добавляем разницу в минутах
|
||||||
const minutesDiff =
|
const minutesDiff =
|
||||||
(arrivalDateTime.getMinutes() - departureDateTime.getMinutes()) / 60;
|
(arrivalDateTime.getMinutes() - departureDateTime.getMinutes()) /
|
||||||
|
60;
|
||||||
hoursDiff += minutesDiff;
|
hoursDiff += minutesDiff;
|
||||||
|
|
||||||
// Округляем до ближайших 0.5 часа
|
// Округляем до ближайших 0.5 часа
|
||||||
|
|
@ -81,4 +87,4 @@ export const calculateTotalPrice = (
|
||||||
console.error("Error calculating price:", error);
|
console.error("Error calculating price:", error);
|
||||||
return { totalHours: 0, totalPrice: 0 };
|
return { totalHours: 0, totalPrice: 0 };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue