Fetch and show booked hours for service

This commit is contained in:
Manuel Bouza
2019-02-14 14:26:48 +01:00
parent 4d77ddb2aa
commit 533be5a417
3 changed files with 36 additions and 7 deletions

View File

@@ -14,8 +14,10 @@
border-radius: 50%; border-radius: 50%;
box-shadow: -1px -1px 15px 4px rgba(0, 0, 0, 0.05), box-shadow: -1px -1px 15px 4px rgba(0, 0, 0, 0.05),
2px 2px 15px 4px rgba(0, 0, 0, 0.05); 2px 2px 15px 4px rgba(0, 0, 0, 0.05);
padding: 5px;
display: flex; display: flex;
flex-direction: column;
justify-content: space-around; justify-content: space-around;
align-items: center; align-items: center;

View File

@@ -24,5 +24,10 @@ export default class Client {
projects = () => this.#client.get("projects"); projects = () => this.#client.get("projects");
bookedHours = service =>
this.#client.get("activities/tags", {
params: { selection: [service.id], remote_service: service.name }
});
createActivity = activity => this.#client.post("activities", { activity }); createActivity = activity => this.#client.post("activities", { activity });
} }

View File

@@ -40,6 +40,7 @@ class Bubble extends Component {
@observable projects; @observable projects;
@observable lastProjectId; @observable lastProjectId;
@observable lastTaskId; @observable lastTaskId;
@observable bookedHours;
@observable changeset = {}; @observable changeset = {};
@observable formErrors = {}; @observable formErrors = {};
@@ -70,18 +71,28 @@ class Bubble extends Component {
} }
} }
constructor(props) {
super(props)
this.#apiClient = new ApiClient(props.settings)
}
componentDidMount() { componentDidMount() {
disposeOnUnmount( disposeOnUnmount(
this, this,
reaction( reaction(
() => () => (this.hasMissingConfiguration() ? null : this.props.settings),
this.hasMissingConfiguration() ? null : this.props.settings, this.fetchProjects,
this.fetchData,
{ {
fireImmediately: true fireImmediately: true
} }
) )
) )
disposeOnUnmount(
this,
reaction(() => this.props.service, this.fetchBookedHours, {
fireImmediately: true
})
)
window.addEventListener("keydown", this.handleKeyDown) window.addEventListener("keydown", this.handleKeyDown)
} }
@@ -102,7 +113,7 @@ class Bubble extends Component {
return ["subdomain", "apiKey", "version"].some(key => !settings[key]) return ["subdomain", "apiKey", "version"].some(key => !settings[key])
}; };
fetchData = settings => { fetchProjects = settings => {
if (!settings) { if (!settings) {
return return
} }
@@ -121,6 +132,16 @@ class Bubble extends Component {
.finally(() => (this.isLoading = false)) .finally(() => (this.isLoading = false))
}; };
fetchBookedHours = service => {
this.isLoading = true
this.#apiClient
.bookedHours(service)
.then(({ data }) => (this.bookedHours = data[0]?.hours))
.catch(console.error)
.finally(() => (this.isLoading = false))
};
// EVENT HANDLERS ----------------------------------------------------------- // EVENT HANDLERS -----------------------------------------------------------
handleKeyDown = event => { handleKeyDown = event => {
@@ -157,13 +178,13 @@ class Bubble extends Component {
if (error.response?.status === 422) { if (error.response?.status === 422) {
this.formErrors = error.response.data this.formErrors = error.response.data
} }
} };
// RENDER ------------------------------------------------------------------- // RENDER -------------------------------------------------------------------
render() { render() {
if (this.isLoading) { if (this.isLoading) {
return null return "Loading..."
} }
let content let content
@@ -191,6 +212,7 @@ class Bubble extends Component {
src={chrome.extension.getURL(logoUrl)} src={chrome.extension.getURL(logoUrl)}
width="50%" width="50%"
/> />
{this.bookedHours && <span className="booked-hours"><small>{this.bookedHours}</small></span>}
{this.isOpen && ( {this.isOpen && (
<Modal> <Modal>
<Content>{content}</Content> <Content>{content}</Content>