0% found this document useful (0 votes)
3 views14 pages

Last Env Chnage File

The document contains JavaScript code for configuring API endpoints and functions related to vendor management, including adding, editing, and deleting suppliers, as well as managing their details like addresses and payment terms. It utilizes Axios for making HTTP requests and handles authorization using JWT tokens. The code is structured to support various operations such as fetching supplier information, managing SKUs, and handling errors appropriately.

Uploaded by

HYPER Rishabh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views14 pages

Last Env Chnage File

The document contains JavaScript code for configuring API endpoints and functions related to vendor management, including adding, editing, and deleting suppliers, as well as managing their details like addresses and payment terms. It utilizes Axios for making HTTP requests and handles authorization using JWT tokens. The code is structured to support various operations such as fetching supplier information, managing SKUs, and handling errors appropriately.

Uploaded by

HYPER Rishabh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 14

his si the config fie

const base_url = "http://localhost:5003/api";


const aws_url = "http://13.202.111.174:3001/api";

export const VENDOR_MANAGEMENT_ENDPOINTS =


{

ADD_VENDOR_DETAILS: `${base_url}/add-edit-supplier`,
SUPPLIER_ORDER_INFORMATION :`${base_url}/supplier-order-information`,
ADD_ITEMS_SUPPLIER_DATA : `${base_url}/supplier-sku-mapping`,
GET_ALL_SKUS : `${aws_url}/Inventory/v1/GetAllSkuID`,
ADD_VENDOR_DELETED:`${base_url}/delete-supplier`,

};

this si the api file

import axios from "axios";

import { VENDOR_MANAGEMENT_ENDPOINTS } from "../../../../ApiConfig";

const TOKEN =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJrYXJhbiIsInVzZXJfcm9sZSI6I
kFETUlOIiwiZW1haWwiOiJrbkBnbWFpbC5jb20iLCJpYXQiOjE3MTg5NzY5NDd9.emjcfrEuxyNttcJlwRB
EDsRPs6S6swvpAgCANN3TA-I';
const TOKEN_1 =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJrYXJhbiIsInVzZXJfcm9sZSI6I
kFETUlOIiwiZW1haWwiOiJrbkBnbWFpbC5jb20iLCJpYXQiOjE3MTg5NzY5NDd9.emjcfrEuxyNttcJlwRB
EDsRPs6S6swvpAgCANN3TA-I';
/// This function posts the vendor information via form

export const getsupplierInformation = async (companyName) => {


const payload = { company_name: companyName };

try {
const response = await axios.get( VENDOR_MANAGEMENT_ENDPOINTS.GET_SUPPLIER,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});

return response;
} catch (error) {

throw error;
}
};

// This is the function to add a new supplier


export const addSupplier = async (formData) => {

// Configuration for the request including the token in headers


const config = {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',

}
};

try {
// Sending the request
const response = await axios.post(
VENDOR_MANAGEMENT_ENDPOINTS.ADD_VENDOR_DETAILS,
formData,
config
);

return response;
} catch (error) {
// Handling any errors

return {
success: false,
error: error.response ? error.response.data : error.message
};
}
};

// This funtion is for the order history


export const getSupplierOrderInformation = async (supplier_name) => {
const config = {
headers: {
Authorization: `Bearer ${TOKEN_1}`,
'Content-Type': 'application/json'
}
};

const body = {
order_history: {
supplier_name: supplier_name
}
};

try {
const response = await
axios.get(VENDOR_MANAGEMENT_ENDPOINTS.SUPPLIER_ORDER_INFORMATION, body, config);
return response;
} catch (error) {

throw error;
}
};
// Function to save SKU data
export const saveSKUDataTest = async (payload) => {
try {
// Simulating a successful API response
return new Promise((resolve) => {
setTimeout(() => {

resolve({ message: 'Data saved successfully (mock response)' });


}, 1000); // Simulate a 1-second delay
});

} catch (error) {

throw error;
}
};

// Function to save SKU data


export const saveSKUData = async (payload) => {
try {
const token = localStorage.getItem('authToken'); // Retrieve the token for
authorization
const response = await
axios.post(VENDOR_MANAGEMENT_ENDPOINTS.ADD_ITEMS_SUPPLIER_DATA, payload, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${TOKEN}`, // Add the token to the request
headers
},
});

return response.data; // Return the response data on success


} catch (error) {

throw error; // Throw the error to be handled in the calling component


}
};

/*
This function fetches all the sku's
*/
// Function to get SKUs with headers (like Authorization)
export const getAllSkuIDs = async () => {
try {
// Retrieve the auth token (if stored in localStorage or wherever you store
it)

// Make the GET request with headers


const response = await axios.get(VENDOR_MANAGEMENT_ENDPOINTS.GET_ALL_SKUS,
{
headers: {
Authorization: `Bearer ${TOKEN}`, // Add token here for
Authorization
'Content-Type': 'application/json', // You can also add other
headers if required
}
});
console.log("you have reached the Sku fetch function");

// Check the status code and return the sku_id array


if (response.data.status_code === 200) {
return response.data.sku_id; // Return the array of SKUs

} else {
throw new Error('Failed to fetch SKUs');
}
// Assuming the API returns the SKU data

} catch (error) {

throw error; // Rethrow the error for the calling function to handle
}
};

// Delete the supplier


export const Delete_vendor = async (suppliermasterid) => {

const config = {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json'
},
data: {
delete_supplier: {
supplier_Id: suppliermasterid
}
}
};
try {

const response = await


axios.delete(VENDOR_MANAGEMENT_ENDPOINTS.ADD_VENDOR_DELETED, config);

return response.data;
} catch (error) {

throw error; // Throw the error to handle it in the calling function


}
};

// Add delivery address Function


export const addDeliveryAddress = async (newAddress) => {
const response = await fetch('http://localhost:5003/add-edit-delivery-address', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(newAddress),
});

if (!response.ok) {
throw new Error('Failed to add delivery address');
}

const data = await response.json();

return data;
};

// Add or edit supplier


export const addEditSupplier = async (supplierData) => {
const response = await fetch('http://localhost:5003/add-edit-supplier-details', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(supplierData),
});

if (!response.ok) {
throw new Error('Failed to add or edit supplier');
}

const data = await response.json();


return data;
};

export const getsupplierDetails = async (supplierId) => {


const payload = { supplier_id: supplierId };

try {
const response = await axios.get(`${API_ENDPOINT}/get-supplier-details`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});

return response;

} catch (error) {

throw error;
}
};
// Add or edit supplier
export const add_edit_SupplierDetailsMethod = async (supplierDetailsData) => {
const payload = {
oldsupplierName:supplierDetailsData.oldsupplierName||null,
supplier_Id:supplierDetailsData.supplierId,
add_edit_supplier_details: {
created_by: supplierDetailsData.user_name,
is_supplier: supplierDetailsData.supplierType || null,
company_name: supplierDetailsData.supplierName || null,
company_email: supplierDetailsData.supplierEmail || null,
company_mobile_phone: supplierDetailsData.supplierPhone || null,
gstin: supplierDetailsData.gstNumber || null,
gst_type: supplierDetailsData.gstType || null,
},
};

try {
const response = await axios.post(`${API_ENDPOINT}/add-edit-supplier-details`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response;
} catch (error) {
throw error;
}
};
// Get Billing address details for the supplier
export const getBillingAddressDetails = async (supplierId) => {
const payload = { supplier_id: supplierId };
try {
const response = await axios.get(`${API_ENDPOINT}/get-billing-address-details`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});

return response;

} catch (error) {

throw error;
}
};
// Get Orders of the supplier
export const fetchOrders = async (supplier_id) => {
const payload = { supplier_Id: supplier_id };

try {
const response = await axios.post(`${API_ENDPOINT}/get-supplier-orders`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});

return response;

} catch (error) {
throw error;
}
};

// Get Due payments of the supplier


export const fetchDuePayments = async (company,suppliermasterid) => {
const payload = {
payment_details:{
supplier_Id: suppliermasterid,
company_name: company
}
};

try {
const response = await axios.post(`${API_ENDPOINT}/get-due-payments-details`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});

return response;

} catch (error) {

throw error;
}
};

// Get Contact person details


export const getContactPersonDetails = async (supplierId) => {
const payload = { supplier_id: supplierId };
try {
const response = await axios.get(`${API_ENDPOINT}/get-contact-person-details`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});

return response;

} catch (error) {

throw error;
}
};

// Get Delivery address details


export const getDeliveryAddressDetails = async (supplierId) => {
const payload = { supplier_id: supplierId };
try {
const response = await axios.get(`${API_ENDPOINT}/get-delivery-address-
details`, payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});

return response;

} catch (error) {

throw error;
}
};

// Add or edit supplier details


export const add_edit_supplierDetailsMethod = async (supplierDetailsData) => {
const payload = {
oldSupplierName:supplierDetailsData.oldsupplierName||null,
supplier_Id:supplierDetailsData.supplierId,
add_edit_supplier_details: {
created_by: supplierDetailsData.user_name,
is_supplier: supplierDetailsData.supplierType || null,
company_name: supplierDetailsData.supplierName || null,
company_email: supplierDetailsData.supplierEmail || null,
company_mobile_phone: supplierDetailsData.supplierPhone || null,
gstin: supplierDetailsData.gstNumber || null,
gst_type: supplierDetailsData.gstType || null,

},
};

try {
const response = await axios.post(`${API_ENDPOINT}/add-edit-supplier-details`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response;
} catch (error) {
throw error;
}
};

// Add or edit billing address

export const add_edit_BillingAddressMethod = async (billingAddressData) => {


const payload = {
oldAddressName: billingAddressData.oldAddressName || null,
supplier_Id: billingAddressData.supplierId, // Assuming you have a supplier for
the billing address
add_edit_billing_address: {
created_by: billingAddressData.user_name,
is_delivery: billingAddressData.isDelivery,
address_name: billingAddressData.billingAddressName,
address_lane1: billingAddressData.billingAddressLane1,
address_lane2: billingAddressData.billingAddressLane2,
pincode: billingAddressData.billingPincode,
city: billingAddressData.billingCity,
country: billingAddressData.billingCountry,
state: billingAddressData.billingState,
},
};

try {
const response = await axios.post(`${API_ENDPOINT}/add-edit-billing-address`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response;
} catch (error) {
throw error;
}
};

export const add_edit_ContactDetailsMethod = async (contactDetailsData) => {


const payload = {
oldSalutation: contactDetailsData.oldSalutation,
oldFirstName: contactDetailsData.oldFirstName,
oldLastName: contactDetailsData.oldLastName,
supplier_Id: contactDetailsData.supplierId, // Assuming you have a supplierId
for the contact address
add_edit_contact_details: {
created_by: contactDetailsData.user_name,
salutation: contactDetailsData.salutation,
first_name: contactDetailsData.firstName,
last_name: contactDetailsData.lastName,
phone: contactDetailsData.phone,
email: contactDetailsData.email,
designation: contactDetailsData.designation,
},
};

try {
const response = await axios.post(`${API_ENDPOINT}/add-edit-contact-details`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response;
} catch (error) {
throw error;
}
};

// Add or edit delivery address

export const add_edit_DeliveryAddressMethod = async (deliveryAddressData) => {


const payload = {
oldAddressName : deliveryAddressData.oldAddressName,
supplier_Id: deliveryAddressData.supplierId,
add_edit_delivery_address: {
created_by: deliveryAddressData.user_name || '',
address_name: deliveryAddressData.deliveryAddressName,
address_lane1: deliveryAddressData.deliveryAddressLane1,
address_lane2: deliveryAddressData.deliveryAddressLane2,
pincode: deliveryAddressData.deliveryPincode,
city: deliveryAddressData.deliveryCity,
country: deliveryAddressData.deliveryCountry,
state: deliveryAddressData.deliveryState,
},
};

try {
const response = await axios.post(`${API_ENDPOINT}/add-edit-delivery-address`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response;
} catch (error) {
throw error;
}
};

// Delete
export const deleteToDetails = async (dataToDelete) => {
const payload = {
delete_details: {
supplier_Id: dataToDelete.supplierId,
name: dataToDelete.itemDetails,
type: dataToDelete.itemType
}
};

try {

const response = await axios.delete(`${API_ENDPOINT}/delete-details`, {


data: payload,
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response;
} catch (error) {
throw error;
}
};

// Delete contact details


export const deleteContactDetails = async (dataToDelete) => {
const payload = {
delete_contact_details: {
supplier_Id: dataToDelete.supplier_id,
salutation:dataToDelete.salutation,
firstName: dataToDelete.firstName,
lastName: dataToDelete.lastName
},
};

try {
const response = await axios.delete(`${API_ENDPOINT}/delete-contact-details`, {
data: payload,
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response;
} catch (error) {
throw error;
}
};

// function for the GET payment terms

export const getPaymentTerms = async () => {


try {
const response = await axios.get(`${API_ENDPOINT}/get-payment-terms`, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response.data;
} catch (error) {

throw error;
}
};

// function for the save payment terms


export const savePaymentTerm = async (newTerm) => {
try {
const response = await axios.post(`${API_ENDPOINT}/add-payment-terms`, newTerm,
{
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response.data;
} catch (error) {

throw error;
}
};

// Deactivate the supplier


export const setDeactivatesupplier = async (suppliermasterid) => {
const payload = {
deactivate_details: {
supplierId: suppliermasterid
}
};
try {
const response = await axios.post(`${API_ENDPOINT}/set-deactivate-supplier`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response;
} catch (error) {
throw error;
}
};

// set default Addresses


export const setDefaultMethod = async (dataToDefault) => {
const payload = {
default_details: {
address_name: dataToDefault.addressName,
supplier_Id: dataToDefault.supplier_id,
address_type: dataToDefault.address_type
}
};

try {
const response = await axios.post(`${API_ENDPOINT}/set-default-address`,
payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
});
return response;
} catch (error) {
throw error;
}
};

this is ther wepack config file

const HtmlWebpackPlugin = require('html-webpack-plugin');


const { ModuleFederationPlugin } = require('webpack').container;
const path = require('path');
module.exports = {
resolve: {
extensions: ['.js', '.jsx', '.json'], // Add .jsx here
},
entry: './src/index',
mode: 'development',
devServer: {
static: path.join(__dirname, 'dist'),
port: 3002,
historyApiFallback: true, // Important for SPA routing
},
output: {
publicPath: 'http://localhost:3002/',
},
module: {
rules: [
{
test: /\.jsx?$/, // Rule for JavaScript/JSX files
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
},
},
{
test: /\.css$/, // Rule for CSS files
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader', // Ensures PostCSS is used
options: {
postcssOptions: {
plugins: [
require('tailwindcss'), // Add Tailwind CSS
require('autoprefixer'), // Add Autoprefixer
],
},
},
},
],
},
{
test: /\.(png|jpe?g|gif|svg)$/, // Use Webpack's asset/resource instead of
file-loader
type: 'asset/resource',
generator: {
filename: 'assets/images/[name].[hash][ext]',
},
},
],
},
plugins: [
new ModuleFederationPlugin({
name: 'app2',
filename: 'remoteEntry.js',
exposes: {
'./App': './src/App.js',
'./add-supplier': './src/pages/vendorManagement/AddVendors/AddVendors.jsx',
'./view-supplier':
'./src/pages/vendorManagement/ViewVendors/components/VendorList.jsx',
},
shared: {
react: { singleton: true, eager: false, requiredVersion: '18.2.0' },
'react-dom': { singleton: true, eager: false, requiredVersion: '18.2.0' },
'@mui/material': { singleton: true, eager: false, requiredVersion: '^6.1.1'
},
'@mui/icons-material': { singleton: true, eager: false, requiredVersion:
'^6.1.1' },
},
}),
new HtmlWebpackPlugin({
template: './public/index.html',
}),
],
};

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy