added validations for product

This commit is contained in:
Malini 2026-02-20 08:48:53 +05:30
parent 639d5f0d76
commit 399672bb57

View File

@ -76,6 +76,7 @@ const PASSWORD_POLICY = {
}; };
const MAX_PASSWORD_HISTORY = 5; const MAX_PASSWORD_HISTORY = 5;
const MAX_PRODUCTS = 15;
const validatePasswordComplexity = (password) => { const validatePasswordComplexity = (password) => {
if (!password) return ''; if (!password) return '';
@ -1356,7 +1357,12 @@ const CompanyProfile = () => {
<button <button
type="button" type="button"
onClick={() => handleAddProduct(product)} onClick={() => handleAddProduct(product)}
className="text-[#92722A] hover:text-[#7A5F1E] text-sm font-medium" disabled={selectedProducts.length >= MAX_PRODUCTS}
className={`text-sm font-medium ${
selectedProducts.length >= MAX_PRODUCTS
? 'text-gray-400 cursor-not-allowed'
: 'text-[#92722A] hover:text-[#7A5F1E]'
}`}
> >
Add Add
</button> </button>
@ -1386,13 +1392,24 @@ const CompanyProfile = () => {
<h5 className="text-sm font-medium text-[#111827]">Selected Products</h5> <h5 className="text-sm font-medium text-[#111827]">Selected Products</h5>
{selectedProducts.length > 0 && ( {selectedProducts.length > 0 && (
<span className="bg-[#FEF3C7] text-[#92400E] text-xs font-medium px-2 py-0.5 rounded-full"> <span className={`text-xs font-medium px-2 py-0.5 rounded-full ${
{selectedProducts.length} selected selectedProducts.length >= MAX_PRODUCTS
? 'bg-red-100 text-red-800'
: 'bg-[#FEF3C7] text-[#92400E]'
}`}>
{selectedProducts.length}/{MAX_PRODUCTS} selected
</span> </span>
)} )}
</div> </div>
<div className="p-4"> <div className="p-4">
{selectedProducts.length >= MAX_PRODUCTS && (
<div className="mb-3 p-2 bg-red-50 border border-red-200 rounded-md">
<p className="text-xs text-red-800">
Maximum limit of {MAX_PRODUCTS} products reached. Remove a product to add another.
</p>
</div>
)}
{selectedProducts.length > 0 ? ( {selectedProducts.length > 0 ? (
<ul className="divide-y divide-[#E5E7EB] max-h-96 overflow-y-auto"> <ul className="divide-y divide-[#E5E7EB] max-h-96 overflow-y-auto">
@ -1551,12 +1568,19 @@ const CompanyProfile = () => {
setProductError(''); setProductError('');
setSaveError(''); setSaveError('');
// Check if adding this product would exceed the maximum limit
if (selectedProducts.length >= MAX_PRODUCTS) {
setProductError(`You can only select up to ${MAX_PRODUCTS} products. Please remove a product before adding another.`);
showToast('error', `Maximum ${MAX_PRODUCTS} products allowed`);
return;
}
// Enhanced product formatting to ensure all required fields // Enhanced product formatting to ensure all required fields
const enhancedProduct = { const enhancedProduct = {
id: product.id || product.product_id || 0, id: product.id || product.product_id || 0,
product_id: product.product_id || product.id || 0, product_id: product.product_id || product.id || 0,
hs_code: product.hs_code || product.hsCode || '', hs_code: product.hs_code || product.hsCode || '',
hsCode: product.hsCode || product.hs_code || '', hsCode: product.productName || product.hs_code || '',
product_name: product.product_name || product.productName || product.label || '', product_name: product.product_name || product.productName || product.label || '',
productName: product.productName || product.product_name || product.label || '', productName: product.productName || product.product_name || product.label || '',
label: product.label || `${product.product_name || product.productName || 'Unnamed Product'}${(product.hs_code || product.hsCode) ? ` (${product.hs_code || product.hsCode})` : ''}`, label: product.label || `${product.product_name || product.productName || 'Unnamed Product'}${(product.hs_code || product.hsCode) ? ` (${product.hs_code || product.hsCode})` : ''}`,