Skip to content

Commit

Permalink
fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Sep 19, 2024
1 parent 3d10bbf commit 4b8d308
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ const RecordInput = ({ index, record, updateRecord, removeRecord }) => (
<Label>Matching Fund Display Value</Label>
<Input
value={record.matchingFund}
onChange={e =>
updateRecord(index, 'matchingFund', e.target.value)
}
onChange={e => updateRecord(index, 'matchingFund', e.target.value)}
required
/>
</FormGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/server/adminJs/tabs/components/ProjectCategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const ProjectUpdates = props => {
<br />
<Section>
<Label>Name</Label>
<h1>{category.name || ''} - Id: {category.id}</h1>
<h1>
{category.name || ''} - Id: {category.id}
</h1>
</Section>
</div>
);
Expand Down
63 changes: 34 additions & 29 deletions src/server/adminJs/tabs/projectsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,12 @@ export const addProjectsToQfRound = async (
};
};

export const extractCategoryIds = (payload: any) => {
if (!payload) return;
return Object.keys(payload)
.filter(key => key.startsWith('categoryIds.'))
.map(key => payload[key]);
}
export const extractCategoryIds = (payload: any) => {
if (!payload) return;
return Object.keys(payload)
.filter(key => key.startsWith('categoryIds.'))
.map(key => payload[key]);
};

export const addSingleProjectToQfRound = async (
context: AdminJsContextInterface,
Expand Down Expand Up @@ -496,12 +496,11 @@ export const fillSocialProfileAndQfRounds: After<
const adminJsBaseUrl = process.env.SERVER_URL;
let categories;
if (project) {
categories = await Category
.createQueryBuilder('category')
.innerJoin('category.projects', 'projects')
.where('projects.id = :id', { id: project.id })
.orderBy('category.name', 'ASC')
.getMany();
categories = await Category.createQueryBuilder('category')
.innerJoin('category.projects', 'projects')
.where('projects.id = :id', { id: project.id })
.orderBy('category.name', 'ASC')
.getMany();
}
response.record = {
...record,
Expand Down Expand Up @@ -866,12 +865,11 @@ export const projectsTab = {
components: {
show: adminJs.bundle('./components/ProjectCategories'),
},
availableValues: async (_record) => {
const categories = await Category
.createQueryBuilder('category')
availableValues: async _record => {
const categories = await Category.createQueryBuilder('category')
.where('category.isActive = :isActive', { isActive: true })
.orderBy('category.name', 'ASC')
.getMany();
.getMany();
return categories.map(category => ({
value: category.id,
label: `${category.id} - ${category.name}`,
Expand Down Expand Up @@ -971,18 +969,20 @@ export const projectsTab = {
isVisible: false,
isAccessible: ({ currentAdmin }) =>
canAccessProjectAction({ currentAdmin }, ResourceActions.NEW),
before: async (request) => {
before: async request => {
if (request.payload.categories) {
request.payload.categories = (request.payload.categories as string[]).map(id => ({ id: parseInt(id, 10) }));
request.payload.categories = (
request.payload.categories as string[]
).map(id => ({ id: parseInt(id, 10) }));
}
return request;
},
after: async (response) => {
const { record, request } = response;
after: async response => {
const { request } = response;
const project = await Project.findOne({
where: { id: request?.record?.id },
});
const categoryIds = extractCategoryIds(request.record.params);
const categoryIds = extractCategoryIds(request.record.params);
await saveCategories(project!, categoryIds || []);

return response;
Expand Down Expand Up @@ -1016,10 +1016,13 @@ export const projectsTab = {

const project = await findProjectById(Number(request.payload.id));
if (project) {
await Category.query(`
await Category.query(
`
DELETE FROM project_categories_category
WHERE "projectId" = $1
`, [project.id]);
`,
[project.id],
);
}

if (
Expand Down Expand Up @@ -1084,7 +1087,7 @@ export const projectsTab = {
// We put these status changes in payload, so in after hook we would know to send notification for users
request.payload.statusChanges = statusChanges.join(',');
}

return request;
},
after: async (
Expand Down Expand Up @@ -1222,7 +1225,7 @@ export const projectsTab = {
});
}
}
const categoryIds = extractCategoryIds(request.record.params);
const categoryIds = extractCategoryIds(request.record.params);

await Promise.all([
refreshUserProjectPowerView(),
Expand Down Expand Up @@ -1429,13 +1432,15 @@ async function saveCategories(project: Project, categoryIds?: string[]) {
if (!project) return;
if (!categoryIds || categoryIds?.length === 0) return;

await Category.query(`
await Category.query(
`
DELETE FROM project_categories_category
WHERE "projectId" = $1
`, [project.id]);
`,
[project.id],
);

const categories = await Category
.createQueryBuilder('category')
const categories = await Category.createQueryBuilder('category')
.where('category.id IN (:...ids)', { ids: categoryIds })
.getMany();

Expand Down

0 comments on commit 4b8d308

Please sign in to comment.