Skip to content

Commit

Permalink
Added api wrapper, used to send request to update order of hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff.nielsen committed Apr 23, 2021
1 parent 17a2b41 commit 5615a7c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,31 @@ class ProjectActionPage extends React.Component<any, any> {
result.destination
);

console.log(results);
let beforeItems = results.before.map((result, index) => ({
id: result.id,
position: 1,
order: index,
}))
.reduce((hooks, hook) => (hooks[hook.id] = hook, hooks), {});

let afterItems = results.after.map((result, index) => ({
id: result.id,
position: 2,
order: index,
}))
.reduce((hooks, hook) => (hooks[hook.id] = hook, hooks), {});

const { project_id, action_id } = this.props.match.params;
const projectActionHookService = new ProjectActionService;

projectActionHookService
.updateHookOrder(project_id, action_id, {
hooks: {...beforeItems,...afterItems},
})
.then(
(response) => {},
(error) => {}
);

this.setState({ hooks: results });
}
Expand Down
8 changes: 6 additions & 2 deletions resources/assets/js/services/ProjectAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import '../bootstrap';
import BaseApi from './Api/BaseApi';

class ProjectAction extends BaseApi {
index(project_id) {
index(project_id: string) {
return this.getRequest('/api/projects/' + project_id + '/actions');
}

get(project_id, action_id) {
get(project_id: string, action_id: string) {
return this.getRequest('/api/projects/' + project_id + '/actions/' + action_id);
}

updateHookOrder(project_id: string, action_id: string, data: object) {
return this.putRequest('/api/projects/' + project_id + '/actions/' + action_id + '/hook-order', data);
}
}

export default ProjectAction;

0 comments on commit 5615a7c

Please sign in to comment.