-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from we3x/feature/add-service
Feature/add service
- Loading branch information
Showing
7 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { createAction } from 'redux-actions'; | ||
import { fetch } from '../../../../utils'; | ||
import { API_URL } from '../../../../backend_url'; | ||
import { ADD_SERVICE } from '../constants'; | ||
|
||
export const reset = createAction(ADD_SERVICE, () => ({ | ||
status: 'initial', | ||
})); | ||
|
||
export const begin = createAction(ADD_SERVICE, () => ({ | ||
status: 'pending', | ||
})); | ||
|
||
export const success = createAction(ADD_SERVICE, service => ({ | ||
service, | ||
status: 'success', | ||
})); | ||
|
||
export const fail = createAction(ADD_SERVICE, error => ({ | ||
status: 'error', | ||
error, | ||
})); | ||
|
||
export const add = (clusterId, itemId) => | ||
dispatch => { | ||
dispatch(begin()); | ||
fetch({ | ||
url: `${API_URL}/clusters/${clusterId}/services`, | ||
method: 'POST', | ||
body: { | ||
service_id: itemId, | ||
}, | ||
}) | ||
.then(cluster => { | ||
dispatch(success(cluster)); | ||
return cluster; | ||
}) | ||
.catch(error => { | ||
dispatch(fail(error.message)); | ||
}); | ||
}; | ||
|
||
const actions = { | ||
reset, | ||
begin, | ||
success, | ||
fail, | ||
add, | ||
}; | ||
|
||
export default actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ADD_SERVICE = 'ADD_SERVICE'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ADD_SERVICE } from '../constants'; | ||
|
||
export default function applicationList( | ||
state = { status: 'initial' }, | ||
action | ||
) { | ||
switch (action.type) { | ||
case ADD_SERVICE: | ||
return action.payload; | ||
default: | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import addService from './add'; | ||
|
||
|
||
const reducers = [ | ||
addService, | ||
]; | ||
|
||
|
||
export default reducers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters