This commit is contained in:
Malini 2025-11-06 10:16:08 +05:30
commit fca7cbbcac
2 changed files with 55 additions and 49 deletions

View File

@ -45,9 +45,9 @@ const ValidationReview = () => {
try { try {
setLoading(true); setLoading(true);
setError(null); setError(null);
const result = await getSubmissionById(id); const result = await getSubmissionById(id);
let data = null; let data = null;
if (result?.status === 'success' && result?.data) { if (result?.status === 'success' && result?.data) {
data = result.data; data = result.data;
@ -75,15 +75,18 @@ const ValidationReview = () => {
const handleApprove = async () => { const handleApprove = async () => {
if (actionLoading) return; if (actionLoading) return;
setActionLoading(true); setActionLoading(true);
try { try {
const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, { const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, {
status: 'Approved', approve_reject_status: 1,
remarks: '' remarks: ''
}); });
if (response?.data || response?.status === 'success') { const ok =
(response && response.data) || response?.status === 200 || response?.status === 'success';
if (ok) {
const establishmentName = submissionData?.establishment?.factory_name || 'Establishment'; const establishmentName = submissionData?.establishment?.factory_name || 'Establishment';
navigate('/admin/validations', { navigate('/admin/validations', {
state: { state: {
@ -96,7 +99,7 @@ const ValidationReview = () => {
} }
} catch (err) { } catch (err) {
console.error('Approval failed:', err); console.error('Approval failed:', err);
alert(err.response?.data?.message || err.message || 'Failed to approve submission. Please try again.'); alert(err?.response?.data?.message || err?.message || 'Failed to approve submission. Please try again.');
} finally { } finally {
setActionLoading(false); setActionLoading(false);
} }
@ -104,7 +107,7 @@ const ValidationReview = () => {
const handleRejectSubmit = async () => { const handleRejectSubmit = async () => {
if (actionLoading) return; if (actionLoading) return;
if (!rejectReason.trim()) { if (!rejectReason.trim()) {
alert('Please provide a reason for rejection.'); alert('Please provide a reason for rejection.');
return; return;
@ -113,11 +116,14 @@ const ValidationReview = () => {
setActionLoading(true); setActionLoading(true);
try { try {
const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, { const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, {
status: 'Rejected', approve_reject_status: 0,
remarks: rejectReason.trim() remarks: rejectReason.trim()
}); });
if (response?.data || response?.status === 'success') { const ok =
(response && response.data) || response?.status === 200 || response?.status === 'success';
if (ok) {
const establishmentName = submissionData?.establishment?.factory_name || 'Establishment'; const establishmentName = submissionData?.establishment?.factory_name || 'Establishment';
navigate('/admin/validations', { navigate('/admin/validations', {
state: { state: {
@ -130,7 +136,7 @@ const ValidationReview = () => {
} }
} catch (err) { } catch (err) {
console.error('Rejection failed:', err); console.error('Rejection failed:', err);
alert(err.response?.data?.message || err.message || 'Failed to reject submission. Please try again.'); alert(err?.response?.data?.message || err?.message || 'Failed to reject submission. Please try again.');
} finally { } finally {
setActionLoading(false); setActionLoading(false);
setIsRejectOpen(false); setIsRejectOpen(false);
@ -183,21 +189,21 @@ const ValidationReview = () => {
const establishment = submissionData?.establishment || {}; const establishment = submissionData?.establishment || {};
const establishmentDetails = [ const establishmentDetails = [
{ {
label: 'Establishment Name', label: 'Establishment Name',
value: establishment.factory_name || '—' value: establishment.factory_name || '—'
}, },
{ {
label: 'Establishment ID', label: 'Establishment ID',
value: establishment.establishment_code || '—' value: establishment.establishment_code || '—'
}, },
{ {
label: 'Email', label: 'Email',
value: establishment.establishment_contact_email || '—' value: establishment.establishment_contact_email || '—'
}, },
{ {
label: 'Emirate', label: 'Emirate',
value: establishment.establishment_address || '—' value: establishment.establishment_address || '—'
}, },
]; ];
@ -211,25 +217,25 @@ const ValidationReview = () => {
const totalNonEmirati = totalNonEmiratiMale + totalNonEmiratiFemale; const totalNonEmirati = totalNonEmiratiMale + totalNonEmiratiFemale;
const employmentDetails = [ const employmentDetails = [
{ {
label: 'Total Employees', label: 'Total Employees',
value: establishment.total_employees?.toString() || (totalMale + totalFemale).toString() || '—' value: establishment.total_employees?.toString() || (totalMale + totalFemale).toString() || '—'
}, },
{ {
label: 'Male Employees', label: 'Male Employees',
value: totalMale.toString() || '—' value: totalMale.toString() || '—'
}, },
{ {
label: 'Female Employees', label: 'Female Employees',
value: totalFemale.toString() || '—' value: totalFemale.toString() || '—'
}, },
{ {
label: 'UAE Nationals', label: 'UAE Nationals',
value: totalEmirati.toString() || '—' value: totalEmirati.toString() || '—'
}, },
{ {
label: 'Non-UAE Nationals', label: 'Non-UAE Nationals',
value: totalNonEmirati.toString() || '—' value: totalNonEmirati.toString() || '—'
}, },
]; ];
@ -269,29 +275,29 @@ const ValidationReview = () => {
capacity: product.annual_installed_capacity?.toString() || '—', capacity: product.annual_installed_capacity?.toString() || '—',
quarters, quarters,
rows: [ rows: [
{ {
label: `Quantity (${unit.toLowerCase()})`, label: `Quantity (${unit.toLowerCase()})`,
values: [ values: [
previousQuantity.toString(), previousQuantity.toString(),
currentQuantity.toString(), currentQuantity.toString(),
forecastQuantity.toString() forecastQuantity.toString()
] ]
}, },
{ {
label: 'Cost (AED)', label: 'Cost (AED)',
values: [ values: [
previousCost !== '—' ? Number(previousCost).toLocaleString() : '—', previousCost !== '—' ? Number(previousCost).toLocaleString() : '—',
currentCost !== '—' ? Number(currentCost).toLocaleString() : '—', currentCost !== '—' ? Number(currentCost).toLocaleString() : '—',
forecastCost !== '—' ? Number(forecastCost).toLocaleString() : '—' forecastCost !== '—' ? Number(forecastCost).toLocaleString() : '—'
] ]
}, },
{ {
label: 'Reason', label: 'Reason',
values: [ values: [
'—', '—',
variationReason, variationReason,
zeroTargetReason zeroTargetReason
] ]
}, },
], ],
remarks: product.remarks || 'NA', remarks: product.remarks || 'NA',
@ -535,7 +541,7 @@ const ValidationReview = () => {
type="button" type="button"
className="inline-flex h-11 w-full items-center justify-center rounded-[10px] border border-[#B52520] text-sm font-semibold text-[#B52520] transition-colors hover:bg-[#FEE2E2] md:w-[132px] disabled:opacity-50 disabled:cursor-not-allowed" className="inline-flex h-11 w-full items-center justify-center rounded-[10px] border border-[#B52520] text-sm font-semibold text-[#B52520] transition-colors hover:bg-[#FEE2E2] md:w-[132px] disabled:opacity-50 disabled:cursor-not-allowed"
onClick={() => setIsRejectOpen(true)} onClick={() => setIsRejectOpen(true)}
disabled={actionLoading || actionType === 'approve'} disabled={actionLoading || actionType === 'approve'}
> >
Reject Reject
</button> </button>
@ -543,7 +549,7 @@ const ValidationReview = () => {
type="button" type="button"
className="inline-flex h-11 w-full items-center justify-center rounded-[10px] bg-[#92722A] text-sm font-semibold text-white transition-colors hover:bg-[#B68A35] md:w-[132px] disabled:opacity-50 disabled:cursor-not-allowed" className="inline-flex h-11 w-full items-center justify-center rounded-[10px] bg-[#92722A] text-sm font-semibold text-white transition-colors hover:bg-[#B68A35] md:w-[132px] disabled:opacity-50 disabled:cursor-not-allowed"
onClick={handleApprove} onClick={handleApprove}
disabled={actionLoading || actionType === 'reject'} disabled={actionLoading || actionType === 'reject'}
> >
{actionLoading ? 'Processing...' : 'Approve'} {actionLoading ? 'Processing...' : 'Approve'}
</button> </button>

View File

@ -193,7 +193,7 @@ const ManageSubmissions = () => {
item, item,
]); ]);
const columnWidths = [302, 105, 83, 91, 100, 152, 208, 120, 120, 208, 130]; const columnWidths = [220, 150, 83, 91, 100, 152, 208, 120, 120, 208, 130];
const toolbar = ( const toolbar = (
<div className="px-6 pt-6 pb-5 space-y-4"> <div className="px-6 pt-6 pb-5 space-y-4">