Skip to content
Extraits de code Groupes Projets
Valider 9824e48d rédigé par Mohamed Lemine BAILLAHI's avatar Mohamed Lemine BAILLAHI
Parcourir les fichiers

Merge branch 'feature/MS-92' into 'develop'

MS-92 : Fix issue with customer names in order details

Closes MS-92

See merge request !480
parents 5918570e 74129c86
Branches
1 requête de fusion!480MS-92 : Fix issue with customer names in order details
......@@ -266,6 +266,7 @@ export const endpoints = {
addAdresss:"/api/user/address/addAddress",
updateAdress:"/api/user/address/updateAddress",
getUserById: (id: number) => `api/user/${id}`,
findUserById: (id: number) => `api/user/findUserById/${id}`,
getByEmail: (email: string) => `api/user/getByEmail/${email}`,
changingLogingActivity: "api/user/changeLoginActivity",
updateUser: `api/user/updateUser`,
......
......@@ -69,6 +69,14 @@ export const UserByEmail = async (email: string) => {
throw error;
}
};
export const findUserById = async (id: number) => {
try {
const response = await axiosInstance.get(endpoints.user.findUserById(id));
return response;
} catch (error) {
throw error;
}
};
export function useGetUserById(id: number) {
const URL = [endpoints.user.getUserById(id)];
const { data, error } = useSWR<{ client?: IClientItem; user?: IUser }>(
......
......@@ -7,8 +7,8 @@ import Typography from "@mui/material/Typography";
import {CardContent,Chip,Grid,Pagination,Table,TableBody,TableCell,TableContainer,TableRow} from "@mui/material";
import CircularProgress from "@mui/material/CircularProgress";
import {OrderStatusHistoryDTO,getStatusInFrench,OrderStatus} from "../../../types/order";
import { useGetUserById } from "@/shared/api/user";
import { useEffect, useState } from "react";
import { findUserById, useGetUserById } from "@/shared/api/user";
import { useCallback, useEffect, useState } from "react";
import { noteTypeLabels, Order } from "@/contexts/types/main-order";
import { IClientItem } from "@/shared/types/user";
import { ShippingMethodType } from "@/contexts/types/Shipping";
......@@ -47,14 +47,19 @@ export default function OrderDetailsInfo({ order }: Props) {
fetchOrderHistory();
}, [order?.id, currentPage]);
const { userData } = useGetUserById(Number(order?.clientId));
const [clientData, setClientData] = useState<IClientItem | null>(null);
useEffect(() => {
if (userData && userData?.roles?.name === "CLIENT") {
setClientData(userData as IClientItem);
const fetchUser = useCallback(async () => {
try {
const response = await findUserById(Number(order?.clientId));
setClientData(response.data);
} catch (error) {
console.error("Erreur lors de la récupération de l'utilisateur :", error);
}
}, [userData]);
}, [order?.clientId]);
useEffect(() => {
fetchUser();
}, [fetchUser]);
function getShippingMethodNameInFrench(shippingMethod: string): string {
switch (shippingMethod) {
......
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter