const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, 'frontend/src/components/Appeal_drafts/configureAppeal_draftsCols.tsx');
let content = fs.readFileSync(filePath, 'utf8');
// The original buggy code from line 28 is:
// if (!hasPermission(user, 'READ_' + entityName.toUpperCase())) return [
// params.row.status !== 'submitted' ? }
// label="Submit"
// onClick={async () => {
// if (window.confirm('Submit this draft?')) {
// await axios.put('/appeal_drafts/' + params.row.id, { id: params.row.id, data: { status: 'submitted' } });
// window.location.reload();
// }
// }}
// showInMenu
// /> :
,];
const searchStr = `if (!hasPermission(user, 'READ_' + entityName.toUpperCase())) return [
params.row.status !== 'submitted' ? }
label="Submit"
onClick={async () => {
if (window.confirm('Submit this draft?')) {
await axios.put('/appeal_drafts/' + params.row.id, { id: params.row.id, data: { status: 'submitted' } });
window.location.reload();
}
}}
showInMenu
/> : ,];`;
content = content.replace(searchStr, "if (!hasPermission(user, 'READ_' + entityName.toUpperCase())) return [];");
const actionsRegex = /return [\s]*[\s]*
[\s]*<\/div>,[\s]*]/;
const newActions = `
const actions = [
,
];
if (params.row.status !== 'submitted') {
actions.push(
}
label="Submit"
onClick={async () => {
const conf = window.confirm('Submit this draft?');
if (conf) {
try {
await axios.put('/appeal_drafts/' + params.row.id + '/submit');
window.location.reload();
} catch (e) {
alert('Error submitting: ' + (e.response?.data?.message || e.message));
}
}
}}
showInMenu
/>
);
}
return actions;
`;
content = content.replace(actionsRegex, newActions);
fs.writeFileSync(filePath, content);
console.log('Fixed configureAppeal_draftsCols.tsx');