Create activity
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"date-fns": "^1.30.1",
|
||||
"lodash": "^4.17.11",
|
||||
"mobx": "^5.5.0",
|
||||
"mobx-react": "^5.2.8",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import axios from "axios"
|
||||
|
||||
export default class Client {
|
||||
#client
|
||||
#apiKey
|
||||
#client;
|
||||
#apiKey;
|
||||
|
||||
constructor({ subdomain, apiKey, clientVersion }) {
|
||||
this.#apiKey = apiKey
|
||||
@@ -20,7 +20,9 @@ export default class Client {
|
||||
})
|
||||
}
|
||||
|
||||
login = () => this.#client.post("session", { api_key: this.#apiKey })
|
||||
login = () => this.#client.post("session", { api_key: this.#apiKey });
|
||||
|
||||
projects = () => this.#client.get("projects")
|
||||
projects = () => this.#client.get("projects");
|
||||
|
||||
createActivity = activity => this.#client.post("activities", { activity });
|
||||
}
|
||||
|
||||
@@ -6,7 +6,12 @@ import Form from "components/Form"
|
||||
import { observable, computed } from "mobx"
|
||||
import { observer } from "mobx-react"
|
||||
import logoUrl from "images/logo.png"
|
||||
import { findLastProject, findLastTask, groupedProjectOptions } from "utils"
|
||||
import {
|
||||
findLastProject,
|
||||
findLastTask,
|
||||
groupedProjectOptions,
|
||||
currentDate
|
||||
} from "utils"
|
||||
|
||||
@observer
|
||||
class Bubble extends Component {
|
||||
@@ -26,6 +31,8 @@ class Bubble extends Component {
|
||||
})
|
||||
};
|
||||
|
||||
#apiClient;
|
||||
|
||||
@observable isLoading = true;
|
||||
@observable isOpen = false;
|
||||
@observable projects;
|
||||
@@ -36,9 +43,9 @@ class Bubble extends Component {
|
||||
@computed get changesetWithDefaults() {
|
||||
const { service } = this.props
|
||||
|
||||
const project = findLastProject(service.projectId || this.lastProjectId)(
|
||||
this.projects
|
||||
) || this.projects[0]
|
||||
const project =
|
||||
findLastProject(service.projectId || this.lastProjectId)(this.projects) ||
|
||||
this.projects[0]
|
||||
|
||||
const defaults = {
|
||||
id: service.id,
|
||||
@@ -55,9 +62,32 @@ class Bubble extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
@computed get activityParams() {
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
hours,
|
||||
description,
|
||||
project,
|
||||
task
|
||||
} = this.changesetWithDefaults
|
||||
|
||||
return {
|
||||
date: currentDate(),
|
||||
hours,
|
||||
description,
|
||||
assignment_id: project.value,
|
||||
task_id: task.value,
|
||||
billable: task.billable,
|
||||
remote_service: name,
|
||||
remote_id: id,
|
||||
remote_url: window.location.href
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { settings } = this.props
|
||||
this.apiClient = new ApiClient(settings)
|
||||
this.#apiClient = new ApiClient(settings)
|
||||
this.fetchData()
|
||||
window.addEventListener("keydown", this.handleKeyDown)
|
||||
}
|
||||
@@ -75,7 +105,7 @@ class Bubble extends Component {
|
||||
};
|
||||
|
||||
fetchData = () => {
|
||||
this.apiClient
|
||||
this.#apiClient
|
||||
.projects()
|
||||
.then(({ data }) => {
|
||||
this.projects = groupedProjectOptions(data.projects)
|
||||
@@ -108,7 +138,10 @@ class Bubble extends Component {
|
||||
|
||||
handleSubmit = event => {
|
||||
event.preventDefault()
|
||||
this.close()
|
||||
this.#apiClient
|
||||
.createActivity(this.activityParams)
|
||||
.then(() => this.close())
|
||||
.catch(error => console.log(error))
|
||||
};
|
||||
|
||||
// RENDER -------------------------------------------------------------------
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
find,
|
||||
curry
|
||||
} from "lodash/fp"
|
||||
import { format } from "date-fns"
|
||||
|
||||
const nilToArray = input => input || []
|
||||
|
||||
@@ -25,9 +26,10 @@ export const findLastTask = id =>
|
||||
)
|
||||
|
||||
function taskOptions(tasks) {
|
||||
return tasks.map(({ id, name }) => ({
|
||||
return tasks.map(({ id, name, billable }) => ({
|
||||
label: name,
|
||||
value: id
|
||||
value: id,
|
||||
billable
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -55,3 +57,6 @@ export const trace = curry((tag, value) => {
|
||||
console.log(tag, value)
|
||||
return value
|
||||
})
|
||||
|
||||
export const currentDate = (locale = "de") =>
|
||||
format(new Date(), "YYYY-MM-DD", { locale })
|
||||
|
||||
@@ -34,7 +34,7 @@ export const createEnhancer = document => services => (key, url) => {
|
||||
...service,
|
||||
key,
|
||||
url,
|
||||
id: evaluate(service.id),
|
||||
id: evaluate(service.id) || match.id,
|
||||
description: evaluate(service.description),
|
||||
projectId: evaluate(service.projectId),
|
||||
taskId: evaluate(service.taskId),
|
||||
|
||||
@@ -2116,6 +2116,11 @@ data-urls@^1.0.0:
|
||||
whatwg-mimetype "^2.2.0"
|
||||
whatwg-url "^7.0.0"
|
||||
|
||||
date-fns@^1.30.1:
|
||||
version "1.30.1"
|
||||
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
|
||||
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==
|
||||
|
||||
date-now@^0.1.4:
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"
|
||||
|
||||
Reference in New Issue
Block a user