Skip to content

Commit

Permalink
Merge pull request #1023 from Giveth/f_1015_add_qf_round_to_project_e…
Browse files Browse the repository at this point in the history
…dit_page

F 1015 add qf round to project edit page
  • Loading branch information
mohammadranjbarz authored Jun 13, 2023
2 parents 1293e28 + 44af39d commit 9e34baa
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
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

0 comments on commit 9e34baa

Please sign in to comment.