diff --git a/src/components/ProjectContents.jsx b/src/components/ProjectContents.jsx index a93179da..ead8d0b6 100644 --- a/src/components/ProjectContents.jsx +++ b/src/components/ProjectContents.jsx @@ -14,7 +14,7 @@ class ProjectContents extends Component { render() { const { contents } = this.props; - const project_contents = contents.data.length ? contents.data[0] : {}; + const project_contents = contents.original.length ? contents.original[0] : {}; return (
{key} {step.content}
); diff --git a/src/components/WorkflowContents.jsx b/src/components/WorkflowContents.jsx index b89d6695..9027a0ce 100644 --- a/src/components/WorkflowContents.jsx +++ b/src/components/WorkflowContents.jsx @@ -14,7 +14,7 @@ class WorkflowContents extends Component { render() { const { contents } = this.props; - const workflow_contents = contents.data.length ? contents.data[0] : {strings: []}; + const workflow_contents = contents.original.length ? contents.original[0] : {strings: []}; console.log(workflow_contents) const strings = []; for (const key in workflow_contents.strings) { diff --git a/src/ducks/resource.js b/src/ducks/resource.js index b826e2a6..78e5c444 100644 --- a/src/ducks/resource.js +++ b/src/ducks/resource.js @@ -4,10 +4,12 @@ import apiClient from 'panoptes-client/lib/api-client'; export const FETCH_RESOURCE = 'FETCH_RESOURCE'; export const FETCH_RESOURCE_SUCCESS = 'FETCH_RESOURCE_SUCCESS'; export const FETCH_RESOURCE_ERROR = 'FETCH_RESOURCE_ERROR'; +export const CREATE_TRANSLATION_SUCCESS = 'CREATE_TRANSLATION_SUCCESS'; // Reducer const initialState = { - data: [], + original: [], + translation: null, error: false, loading: false, }; @@ -17,9 +19,11 @@ const resourceReducer = (state = initialState, action) => { case FETCH_RESOURCE: return Object.assign({}, initialState, { loading: true }); case FETCH_RESOURCE_SUCCESS: - return Object.assign({}, state, { data: action.payload, loading: false }); + return Object.assign({}, state, { original: action.payload, loading: false }); case FETCH_RESOURCE_ERROR: return Object.assign({}, state, { error: action.payload, loading: false }); + case CREATE_TRANSLATION_SUCCESS: + return Object.assign({}, state, { translation: action.payload, loading: false }); default: return state; } @@ -77,18 +81,20 @@ function fetchResourceContents(id, type) { }; } -const createNewTranslation = (type) => +const createTranslation = (type, lang) => (dispatch, getState) => { - const { contents } = getState(); - const translation = apiClient.type(type).create({ - title: contents.title, - description: contents.description, - introduction: contents.introduction, - language: 'nz', - 'links.project': contents.links.project, - }); - translation.save() - .then(res => console.info('Saved! ', res)) + const { original } = getState(); + const newResource = Object.assign({}, original); + newResource.lang = lang; + apiClient.type(type) + .create(newResource) + .save() + .then((translation) => { + dispatch({ + type: CREATE_TRANSLATION_SUCCESS, + payload: translation, + }); + }) .catch(error => console.error(error)); }; @@ -96,6 +102,6 @@ const createNewTranslation = (type) => export default resourceReducer; export { - createNewTranslation, + createTranslation, fetchResource, };