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 {
setLoading(true);
setError(null);
const result = await getSubmissionById(id);
let data = null;
if (result?.status === 'success' && result?.data) {
data = result.data;
@ -75,15 +75,18 @@ const ValidationReview = () => {
const handleApprove = async () => {
if (actionLoading) return;
setActionLoading(true);
try {
const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, {
status: 'Approved',
approve_reject_status: 1,
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';
navigate('/admin/validations', {
state: {
@ -96,7 +99,7 @@ const ValidationReview = () => {
}
} catch (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 {
setActionLoading(false);
}
@ -104,7 +107,7 @@ const ValidationReview = () => {
const handleRejectSubmit = async () => {
if (actionLoading) return;
if (!rejectReason.trim()) {
alert('Please provide a reason for rejection.');
return;
@ -113,11 +116,14 @@ const ValidationReview = () => {
setActionLoading(true);
try {
const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, {
status: 'Rejected',
approve_reject_status: 0,
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';
navigate('/admin/validations', {
state: {
@ -130,7 +136,7 @@ const ValidationReview = () => {
}
} catch (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 {
setActionLoading(false);
setIsRejectOpen(false);
@ -183,21 +189,21 @@ const ValidationReview = () => {
const establishment = submissionData?.establishment || {};
const establishmentDetails = [
{
label: 'Establishment Name',
value: establishment.factory_name || '—'
{
label: 'Establishment Name',
value: establishment.factory_name || '—'
},
{
label: 'Establishment ID',
value: establishment.establishment_code || '—'
{
label: 'Establishment ID',
value: establishment.establishment_code || '—'
},
{
label: 'Email',
value: establishment.establishment_contact_email || '—'
{
label: 'Email',
value: establishment.establishment_contact_email || '—'
},
{
label: 'Emirate',
value: establishment.establishment_address || '—'
{
label: 'Emirate',
value: establishment.establishment_address || '—'
},
];
@ -211,25 +217,25 @@ const ValidationReview = () => {
const totalNonEmirati = totalNonEmiratiMale + totalNonEmiratiFemale;
const employmentDetails = [
{
label: 'Total Employees',
value: establishment.total_employees?.toString() || (totalMale + totalFemale).toString() || '—'
{
label: 'Total Employees',
value: establishment.total_employees?.toString() || (totalMale + totalFemale).toString() || '—'
},
{
label: 'Male Employees',
value: totalMale.toString() || '—'
{
label: 'Male Employees',
value: totalMale.toString() || '—'
},
{
label: 'Female Employees',
value: totalFemale.toString() || '—'
{
label: 'Female Employees',
value: totalFemale.toString() || '—'
},
{
label: 'UAE Nationals',
value: totalEmirati.toString() || '—'
{
label: 'UAE Nationals',
value: totalEmirati.toString() || '—'
},
{
label: 'Non-UAE Nationals',
value: totalNonEmirati.toString() || '—'
{
label: 'Non-UAE Nationals',
value: totalNonEmirati.toString() || '—'
},
];
@ -269,29 +275,29 @@ const ValidationReview = () => {
capacity: product.annual_installed_capacity?.toString() || '—',
quarters,
rows: [
{
label: `Quantity (${unit.toLowerCase()})`,
{
label: `Quantity (${unit.toLowerCase()})`,
values: [
previousQuantity.toString(),
currentQuantity.toString(),
forecastQuantity.toString()
]
]
},
{
label: 'Cost (AED)',
{
label: 'Cost (AED)',
values: [
previousCost !== '—' ? Number(previousCost).toLocaleString() : '—',
currentCost !== '—' ? Number(currentCost).toLocaleString() : '—',
forecastCost !== '—' ? Number(forecastCost).toLocaleString() : '—'
]
]
},
{
label: 'Reason',
{
label: 'Reason',
values: [
'—',
variationReason,
zeroTargetReason
]
]
},
],
remarks: product.remarks || 'NA',
@ -535,7 +541,7 @@ const ValidationReview = () => {
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"
onClick={() => setIsRejectOpen(true)}
disabled={actionLoading || actionType === 'approve'}
disabled={actionLoading || actionType === 'approve'}
>
Reject
</button>
@ -543,7 +549,7 @@ const ValidationReview = () => {
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"
onClick={handleApprove}
disabled={actionLoading || actionType === 'reject'}
disabled={actionLoading || actionType === 'reject'}
>
{actionLoading ? 'Processing...' : 'Approve'}
</button>

View File

@ -193,7 +193,7 @@ const ManageSubmissions = () => {
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 = (
<div className="px-6 pt-6 pb-5 space-y-4">