diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/package.json b/package.json index ed0c9c2..e3e86d2 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "axios": "^0.16.2", "localStorage": "^1.0.3", "react": "^15.6.1", + "react-color": "^2.13.8", "react-dom": "^15.6.1", "react-redux": "^5.0.6", "react-router": "^4.2.0", diff --git a/src/actions/worktype/reducer.actions.js b/src/actions/worktype/reducer.actions.js new file mode 100644 index 0000000..ff0ef78 --- /dev/null +++ b/src/actions/worktype/reducer.actions.js @@ -0,0 +1,74 @@ +import { + IS_SENDING_WORKTYPE_REQUEST, + SET_WORKTYPE_REQUEST_ERROR, + CLEAR_WORKTYPE_REQUEST_ERROR, + SET_WORKTYPE_REQUEST_SUCCESS, + CLEAR_WORKTYPE_REQUEST_SUCCESS, + SET_WORKTYPE_UUID, + SET_FORM_WORKTYPE_COLOR, + SET_FORM_WORKTYPE_LABEL +} from "../../constants/worktype.constants"; +import { parseError } from "../common.actions"; + +export function isSendingWorktypeRequest(sendingRequest) { + return { + type: IS_SENDING_WORKTYPE_REQUEST, + data: sendingRequest + }; +} + +export function setWorktypeRequestError(exception) { + let error = parseError(exception); + if (error.label) { + error["Label"] = error.label; + delete error["label"]; + } + if (error.color) { + error["Color"] = error.color; + delete error["color"]; + } + return { + type: SET_WORKTYPE_REQUEST_ERROR, + data: error + }; +} + +export function clearWorktypeRequestError() { + return { + type: CLEAR_WORKTYPE_REQUEST_ERROR + }; +} + +export function setWorktypeRequestSuccess(response) { + return { + type: SET_WORKTYPE_REQUEST_SUCCESS, + data: response.detail || response + }; +} + +export function clearWorktypeRequestSuccess() { + return { + type: CLEAR_WORKTYPE_REQUEST_SUCCESS + }; +} + +export function setWorktypeUUID(uuid) { + return { + type: SET_WORKTYPE_UUID, + data: uuid + }; +} + +export function setFormWorktypeColor(color) { + return { + type: SET_FORM_WORKTYPE_COLOR, + data: color + }; +} + +export function setFormWorktypeLabel(label) { + return { + type: SET_FORM_WORKTYPE_LABEL, + data: label + }; +} diff --git a/src/actions/worktype/saga.actions.js b/src/actions/worktype/saga.actions.js new file mode 100644 index 0000000..357415d --- /dev/null +++ b/src/actions/worktype/saga.actions.js @@ -0,0 +1,34 @@ +import { + CREATE_WORKTYPE_REQUEST, + READ_WORKTYPE_REQUEST, + UPDATE_WORKTYPE_REQUEST, + DELETE_WORKTYPE_REQUEST +} from "../../constants/worktype.constants"; + +export function createWorktypeRequest(postBody) { + return { + type: CREATE_WORKTYPE_REQUEST, + data: postBody + }; +} + +export function readWorktypeRequest(payload) { + return { + type: READ_WORKTYPE_REQUEST, + data: payload + }; +} + +export function updateWorktypeRequest(payload) { + return { + type: UPDATE_WORKTYPE_REQUEST, + data: payload + }; +} + +export function deleteWorktypeRequest(payload) { + return { + type: DELETE_WORKTYPE_REQUEST, + data: payload + }; +} diff --git a/src/api/baseApi.js b/src/api/baseApi.js index 88b5a19..4332b11 100644 --- a/src/api/baseApi.js +++ b/src/api/baseApi.js @@ -46,6 +46,13 @@ export function put(url, data) { .catch(error => Promise.reject(error)); } +export function patch(url, data) { + return apiInstance + .patch(url, data, { headers: headers() }) + .then(response => response.data) + .catch(error => Promise.reject(error)); +} + export function del(url) { return apiInstance .delete(url, { headers: headers() }) diff --git a/src/api/worktype.api.js b/src/api/worktype.api.js new file mode 100644 index 0000000..0af2ea0 --- /dev/null +++ b/src/api/worktype.api.js @@ -0,0 +1,39 @@ +import { post, get, patch, del } from "./baseApi"; + +/** + * Function wrapping POST request for creating worktypes + * @param {string} color - color value of worktype + * @param {string} label - label text of worktype + */ +export function createWorktype(color, label) { + return post("/worktype/", { color, label }).then(resp => + Promise.resolve(resp) + ); +} + +/** + * Function wrapping GET request for retreiving worktype data + * @param {string} uuid - worktype unique identifier + */ +export function getWorktype(uuid) { + return get(`/worktype/${uuid}/`).then(resp => Promise.resolve(resp)); +} + +/** + * Function wrapping PATCH request for updating worktype + * @param {string} uuid - worktype unique identifier + * @param {string} color - color value of worktype + */ +export function updateWorktype(uuid, color) { + return patch(`/worktype/${uuid}/`, { color }).then(resp => + Promise.resolve(resp) + ); +} + +/** + * Function wrapping DELETE request for removing worktypes + * @param {string} uuid - worktype unique identifier + */ +export function deleteWorktype(uuid) { + return del(`/worktype/${uuid}`).then(resp => Promise.resolve(resp)); +} diff --git a/src/components/App.jsx b/src/components/App.jsx index 19bc87c..730f654 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -7,6 +7,8 @@ import Register from "./Auth/Register"; import ResetPassword from "./Auth/ResetPassword"; import Settings from "./Auth/Settings"; import VerifyEmail from "./Auth/VerifyEmail"; +import CreateWorkTypeForm from "./User/Client/CreateWorkTypeForm"; +import UpdateWorkTypeForm from "./User/Client/UpdateWorkTypeForm"; import CompleteRegistration from "./User/CompleteRegistration"; import EditProfile from "./User/EditProfile"; import Profile from "./User/Profile"; @@ -46,12 +48,23 @@ class App extends Component { path="/auth/reset-password/:uid/:token" component={ResetPassword} /> + + - + - +