chore: build
This commit is contained in:
+107
-25
@@ -27,6 +27,8 @@ export interface AuthResponse {
|
||||
access_token?: string;
|
||||
token_type?: string;
|
||||
expires_in?: number;
|
||||
requires_2fa?: boolean;
|
||||
session_token?: string;
|
||||
user?: {
|
||||
id: number;
|
||||
username: string;
|
||||
@@ -48,6 +50,13 @@ export const loginUser = async (
|
||||
username,
|
||||
password,
|
||||
});
|
||||
if (data.requires_2fa) {
|
||||
return {
|
||||
success: false,
|
||||
requires_2fa: true,
|
||||
session_token: data.session_token,
|
||||
};
|
||||
}
|
||||
if (!data.access_token) {
|
||||
return { success: false, message: "Token non reçu du serveur" };
|
||||
}
|
||||
@@ -68,6 +77,35 @@ export const loginUser = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const verifyClient2FA = async (
|
||||
sessionToken: string,
|
||||
code: string,
|
||||
): Promise<AuthResponse> => {
|
||||
try {
|
||||
const { data } = await apiClient.post(`${V1}/auth/2fa/verify`, {
|
||||
session_token: sessionToken,
|
||||
code,
|
||||
});
|
||||
if (!data.access_token) {
|
||||
return { success: false, message: "Token non reçu du serveur" };
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
message: "Connexion réussie",
|
||||
access_token: data.access_token,
|
||||
token_type: data.token_type,
|
||||
expires_in: data.expires_in,
|
||||
user: data.user,
|
||||
};
|
||||
} catch (error: any) {
|
||||
const msg =
|
||||
error.response?.data?.error ||
|
||||
error.message ||
|
||||
"Code invalide";
|
||||
return { success: false, message: msg };
|
||||
}
|
||||
};
|
||||
|
||||
export const registerUser = async (
|
||||
username: string,
|
||||
password: string,
|
||||
@@ -322,19 +360,18 @@ export const checkoutCart = async (
|
||||
price_currency: data.price_currency,
|
||||
};
|
||||
} catch (error: any) {
|
||||
const errMsg: string = error.response?.data?.error || "Erreur serveur";
|
||||
if (errMsg.startsWith("Adresse invalide ")) {
|
||||
const suggested = errMsg.replace("Adresse invalide ", "").trim();
|
||||
const data = error.response?.data;
|
||||
if (data?.corrected_address) {
|
||||
return {
|
||||
success: false,
|
||||
invalid_address: true,
|
||||
suggested_address: suggested,
|
||||
message: errMsg,
|
||||
suggested_address: data.corrected_address,
|
||||
message: data.error || "Adresse non reconnue",
|
||||
};
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
message: errMsg,
|
||||
message: data?.error || "Erreur serveur",
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -420,10 +457,6 @@ export const respondToAddressProposal = async (
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================
|
||||
// TRACKING
|
||||
// ============================================
|
||||
|
||||
export const getOrderTracking = async (
|
||||
commandId: number,
|
||||
): Promise<TrackingResponse> => {
|
||||
@@ -517,10 +550,6 @@ export const getMyCompletedOrders = async (): Promise<HistoryResponse> => {
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================
|
||||
// CANCEL
|
||||
// ============================================
|
||||
|
||||
export const cancelCommand = async (
|
||||
commandId: number,
|
||||
reason?: string,
|
||||
@@ -778,6 +807,11 @@ export interface PublicSettings {
|
||||
telegram_notifications_enabled: boolean;
|
||||
two_fa_enabled: boolean;
|
||||
contact_telegram: string;
|
||||
client_color_primary: string;
|
||||
client_color_secondary: string;
|
||||
client_color_success: string;
|
||||
client_color_danger: string;
|
||||
client_color_warning: string;
|
||||
}
|
||||
|
||||
export const getPublicSettings = async (): Promise<PublicSettings> => {
|
||||
@@ -794,6 +828,11 @@ export const getPublicSettings = async (): Promise<PublicSettings> => {
|
||||
telegram_notifications_enabled: false,
|
||||
two_fa_enabled: false,
|
||||
contact_telegram: "",
|
||||
client_color_primary: "#7c3aed",
|
||||
client_color_secondary: "#22d3ee",
|
||||
client_color_success: "#4ade80",
|
||||
client_color_danger: "#ef4444",
|
||||
client_color_warning: "#f59e0b",
|
||||
};
|
||||
try {
|
||||
const { data } = await apiClient.get(`${V1}/app-settings`);
|
||||
@@ -816,6 +855,11 @@ export const getPublicSettings = async (): Promise<PublicSettings> => {
|
||||
data.telegram_notifications_enabled ?? false,
|
||||
two_fa_enabled: data.two_fa_enabled ?? false,
|
||||
contact_telegram: data.contact_telegram || "",
|
||||
client_color_primary: data.client_color_primary || "#7c3aed",
|
||||
client_color_secondary: data.client_color_secondary || "#22d3ee",
|
||||
client_color_success: data.client_color_success || "#4ade80",
|
||||
client_color_danger: data.client_color_danger || "#ef4444",
|
||||
client_color_warning: data.client_color_warning || "#f59e0b",
|
||||
};
|
||||
} catch {
|
||||
return defaults;
|
||||
@@ -926,6 +970,13 @@ export type RewardCategoryConfig = {
|
||||
amount: number;
|
||||
};
|
||||
|
||||
export type RewardItemConfig = {
|
||||
product_id: number;
|
||||
product_name: string;
|
||||
quantity: number;
|
||||
price: number;
|
||||
};
|
||||
|
||||
export type PointsPoolInfo = {
|
||||
key: string;
|
||||
name: string;
|
||||
@@ -934,13 +985,7 @@ export type PointsPoolInfo = {
|
||||
rewards_claimed: number;
|
||||
rewards_available: number;
|
||||
eligible_configs: RewardCategoryConfig[];
|
||||
};
|
||||
|
||||
export type RewardItemConfig = {
|
||||
product_id: number;
|
||||
product_name: string;
|
||||
quantity: number;
|
||||
price: number;
|
||||
eligible_reward_items: RewardItemConfig[];
|
||||
};
|
||||
|
||||
export type PointsRewardConfig = {
|
||||
@@ -969,7 +1014,10 @@ export const getMyPointsRewards = async (): Promise<{
|
||||
}
|
||||
};
|
||||
|
||||
export const claimMyReward = async (poolKey: string, productId?: number): Promise<{
|
||||
export const claimMyReward = async (
|
||||
poolKey: string,
|
||||
productId?: number,
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
description?: string;
|
||||
remaining_rewards?: number;
|
||||
@@ -978,7 +1026,9 @@ export const claimMyReward = async (poolKey: string, productId?: number): Promis
|
||||
error?: string;
|
||||
}> => {
|
||||
try {
|
||||
const body: { pool_key: string; product_id?: number } = { pool_key: poolKey };
|
||||
const body: { pool_key: string; product_id?: number } = {
|
||||
pool_key: poolKey,
|
||||
};
|
||||
if (productId !== undefined) body.product_id = productId;
|
||||
const { data } = await apiClient.post(`${V1}/points/claim`, body);
|
||||
return {
|
||||
@@ -993,12 +1043,44 @@ export const claimMyReward = async (poolKey: string, productId?: number): Promis
|
||||
}
|
||||
};
|
||||
|
||||
export const submitLivreurRating = async (
|
||||
orderId: number,
|
||||
rating: number,
|
||||
comment: string,
|
||||
): Promise<{ success: boolean; error?: string }> => {
|
||||
try {
|
||||
await apiClient.post(`${V1}/orders/${orderId}/rate`, {
|
||||
rating,
|
||||
comment,
|
||||
});
|
||||
return { success: true };
|
||||
} catch (e: any) {
|
||||
return { success: false, error: e?.response?.data?.error || "Erreur" };
|
||||
}
|
||||
};
|
||||
|
||||
export const getOrderRatingStatus = async (
|
||||
orderId: number,
|
||||
): Promise<{ rated: boolean; rating?: number; comment?: string }> => {
|
||||
try {
|
||||
const { data } = await apiClient.get(`${V1}/orders/${orderId}/rating`);
|
||||
return data;
|
||||
} catch {
|
||||
return { rated: false };
|
||||
}
|
||||
};
|
||||
|
||||
export const calculateOrderTotal = (order: any): number => {
|
||||
if (typeof order.total_prix === "number" && order.total_prix > 0) return order.total_prix;
|
||||
if (typeof order.total_prix === "number" && order.total_prix > 0)
|
||||
return order.total_prix;
|
||||
if (typeof order.total === "number" && order.total > 0) return order.total;
|
||||
if (Array.isArray(order.items) && order.items.length > 0) {
|
||||
return order.items.reduce((sum: number, item: any) => {
|
||||
return sum + (item.prix || item.price || 0) * (item.quantite || item.quantity || 1);
|
||||
return (
|
||||
sum +
|
||||
(item.prix || item.price || 0) *
|
||||
(item.quantite || item.quantity || 1)
|
||||
);
|
||||
}, 0);
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user