Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F 1015 add qf round to project edit page #1023

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/server/adminJs/adminJs-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface AdminJsContextInterface {
h: any;
resource: any;
records: any[];
record?: any;
currentAdmin: User;
payload?: any;
}
Expand Down
69 changes: 66 additions & 3 deletions src/server/adminJs/tabs/projectsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export const updateStatusOfProjects = async (
};
};

export const addProjectToQfRound = async (
export const addProjectsToQfRound = async (
context: AdminJsContextInterface,
request: AdminJsRequestInterface,
add: boolean = true,
Expand Down Expand Up @@ -416,6 +416,37 @@ export const addProjectToQfRound = async (
};
};

export const addSingleProjectToQfRound = async (
context: AdminJsContextInterface,
request: AdminJsRequestInterface,
add: boolean = true,
) => {
const { record, currentAdmin } = context;
let message = messages.PROJECTS_RELATED_TO_ACTIVE_QF_ROUND_SUCCESSFULLY;
try {
const projectId = Number(request?.params?.recordId);
const activeQfRound = await findActiveQfRound();
if (activeQfRound) {
await relateManyProjectsToQfRound({
projectIds: [projectId],
qfRoundId: activeQfRound.id,
add,
});
} else {
message = messages.THERE_IS_NOT_ANY_ACTIVE_QF_ROUND;
}
} catch (error) {
throw error;
}
return {
record: record.toJSON(currentAdmin),
notice: {
message,
type: 'success',
},
};
};

export const fillSocialProfileAndQfRounds: After<ActionResponse> = async (
response,
request,
Expand Down Expand Up @@ -1167,6 +1198,38 @@ export const projectsTab = {
component: false,
},

addProjectToQfRound: {
// https://docs.adminjs.co/basics/action#record-type-actions
actionType: 'record',
isVisible: true,
isAccessible: ({ currentAdmin }) =>
canAccessQfRoundAction(
{ currentAdmin },
ResourceActions.ADD_PROJECT_TO_QF_ROUND,
),
guard: 'Do you want to add this project to current active qf round?',
handler: async (request, response, context) => {
return addSingleProjectToQfRound(context, request, true);
},
component: false,
},
removeProjectFromQfRound: {
// https://docs.adminjs.co/basics/action#record-type-actions
actionType: 'record',
isVisible: true,
isAccessible: ({ currentAdmin }) =>
canAccessQfRoundAction(
{ currentAdmin },
ResourceActions.ADD_PROJECT_TO_QF_ROUND,
),
guard:
'Do you want to remove this project from current active qf round?',
handler: async (request, response, context) => {
return addSingleProjectToQfRound(context, request, false);
},
component: false,
},

addToQfRound: {
actionType: 'bulk',
isVisible: true,
Expand All @@ -1176,7 +1239,7 @@ export const projectsTab = {
ResourceActions.ADD_PROJECT_TO_QF_ROUND,
),
handler: async (request, response, context) => {
return addProjectToQfRound(context, request, true);
return addProjectsToQfRound(context, request, true);
},
component: false,
},
Expand All @@ -1189,7 +1252,7 @@ export const projectsTab = {
ResourceActions.ADD_PROJECT_TO_QF_ROUND,
),
handler: async (request, response, context) => {
return addProjectToQfRound(context, request, false);
return addProjectsToQfRound(context, request, false);
},
component: false,
},
Expand Down