bug fixed of address of pd and rd

This commit is contained in:
Sibunnayak 2024-10-16 14:19:35 +05:30
parent e2a2b02ff5
commit c1b2e00ff8
2 changed files with 15 additions and 18 deletions

View File

@ -143,12 +143,6 @@ const SinglePrincipalDistributorAllDetails = () => {
// Save address logic for adding or updating
const handleSaveAddress = async () => {
try {
const updatedAddress = {
...currentAddress,
gstNumber: gstNumber,
panNumber: panNumber,
tradeName: tradeName,
};
const apiUrl = isEditMode
? `/api/shipping/address/update/${currentAddress._id}`
: `/api/shipping/address/admin/new/${_id}`;
@ -163,7 +157,7 @@ const SinglePrincipalDistributorAllDetails = () => {
};
// Make the API call with the headers
await axios[method](apiUrl, updatedAddress, { headers });
await axios[method](apiUrl, currentAddress, { headers });
swal(
"Success!",
@ -211,9 +205,18 @@ const SinglePrincipalDistributorAllDetails = () => {
);
// console.log(response.data);
setUserAllAddress(response.data?.UserShippingAddress || []);
setGstNumber(response.data?.UserShippingAddress[0]?.gstNumber || "");
setPanNumber(response.data?.UserShippingAddress[0]?.panNumber || "");
setTradeName(response.data?.UserShippingAddress[0]?.tradeName || "");
const defaultAddress =
response.data?.UserShippingAddress.find(
(address) => address.isDefault
) ||
response.data?.UserShippingAddress[0] ||
{};
// Set the values based on the found default address or the first one
setGstNumber(defaultAddress.gstNumber || "");
setPanNumber(defaultAddress.panNumber || "");
setTradeName(defaultAddress.tradeName || "");
} catch (error) {
swal({
title: "Warning",
@ -476,9 +479,7 @@ const SinglePrincipalDistributorAllDetails = () => {
</strong>
</td>
<td className="text-center">
<strong>
{address.isDefault ? "Yes" : "No"}
</strong>
<strong>{address.isDefault ? "Yes" : "No"}</strong>
</td>
<td className="text-start">
<Button

View File

@ -149,10 +149,6 @@ const SingleRetailDistributor = () => {
// Save address logic for adding or updating
const handleSaveAddress = async () => {
try {
const updatedAddress = {
...currentAddress,
tradeName: tradeName,
};
const apiUrl = isEditMode
? `/api/rd/shipping/address/update/${currentAddress._id}`
: `/api/rd/shipping/address/admin/new/${id}`;
@ -167,7 +163,7 @@ const SingleRetailDistributor = () => {
};
// Make the API call with the headers
await axios[method](apiUrl, updatedAddress, { headers });
await axios[method](apiUrl, currentAddress, { headers });
swal(
"Success!",