Pass timed activity to App
This commit is contained in:
@@ -22,9 +22,19 @@ import InvalidConfigurationError from "components/Errors/InvalidConfigurationErr
|
||||
import UpgradeRequiredError from "components/Errors/UpgradeRequiredError"
|
||||
import UnknownError from "components/Errors/UnknownError"
|
||||
import Header from "./shared/Header"
|
||||
import { head } from "lodash"
|
||||
import { head, isNil } from "lodash"
|
||||
import TimeInputParser from "utils/TimeInputParser"
|
||||
|
||||
const findTimedActivity = (activities, service) => {
|
||||
if (!service) {
|
||||
return null
|
||||
}
|
||||
|
||||
return activities.find(
|
||||
activity => activity.remote_id === service.id && !isNil(activity.timer_started_at),
|
||||
)
|
||||
}
|
||||
|
||||
@observer
|
||||
class App extends Component {
|
||||
static propTypes = {
|
||||
@@ -41,9 +51,15 @@ class App extends Component {
|
||||
activities: PropTypes.array,
|
||||
schedules: PropTypes.array,
|
||||
projects: PropTypes.array,
|
||||
timedActivity: PropTypes.shape({
|
||||
customer_name: PropTypes.string.isRequired,
|
||||
assignment_name: PropTypes.string.isRequired,
|
||||
task_name: PropTypes.string.isRequired,
|
||||
timer_started_at: PropTypes.string.isRequired,
|
||||
seconds: PropTypes.number.isRequired,
|
||||
}),
|
||||
lastProjectId: PropTypes.number,
|
||||
lastTaskId: PropTypes.number,
|
||||
roundTimeEntries: PropTypes.bool,
|
||||
fromDate: PropTypes.string,
|
||||
toDate: PropTypes.string,
|
||||
errorType: PropTypes.string,
|
||||
@@ -54,7 +70,6 @@ class App extends Component {
|
||||
activities: [],
|
||||
schedules: [],
|
||||
projects: [],
|
||||
roundTimeEntries: false,
|
||||
}
|
||||
|
||||
@observable changeset = {}
|
||||
@@ -161,10 +176,12 @@ class App extends Component {
|
||||
loading,
|
||||
subdomain,
|
||||
projects,
|
||||
timedActivity,
|
||||
activities,
|
||||
schedules,
|
||||
fromDate,
|
||||
toDate,
|
||||
service,
|
||||
errorType,
|
||||
errorMessage,
|
||||
} = this.props
|
||||
@@ -191,25 +208,28 @@ class App extends Component {
|
||||
<animated.div className="moco-bx-app-container" style={props}>
|
||||
<Header subdomain={subdomain} />
|
||||
<Observer>
|
||||
{() => (
|
||||
<>
|
||||
<Calendar
|
||||
fromDate={parseISO(fromDate)}
|
||||
toDate={parseISO(toDate)}
|
||||
activities={activities}
|
||||
schedules={schedules}
|
||||
selectedDate={new Date(this.changesetWithDefaults.date)}
|
||||
onChange={this.handleSelectDate}
|
||||
/>
|
||||
<Form
|
||||
changeset={this.changesetWithDefaults}
|
||||
projects={projects}
|
||||
errors={this.formErrors}
|
||||
onChange={this.handleChange}
|
||||
onSubmit={this.handleSubmit}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{() =>
|
||||
timedActivity ? null : (
|
||||
<>
|
||||
<Calendar
|
||||
fromDate={parseISO(fromDate)}
|
||||
toDate={parseISO(toDate)}
|
||||
activities={activities}
|
||||
schedules={schedules}
|
||||
selectedDate={new Date(this.changesetWithDefaults.date)}
|
||||
onChange={this.handleSelectDate}
|
||||
/>
|
||||
<Form
|
||||
changeset={this.changesetWithDefaults}
|
||||
projects={projects}
|
||||
timedActivity={findTimedActivity(activities, service)}
|
||||
errors={this.formErrors}
|
||||
onChange={this.handleChange}
|
||||
onSubmit={this.handleSubmit}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
</Observer>
|
||||
</animated.div>
|
||||
)}
|
||||
|
||||
@@ -6,8 +6,14 @@ import cn from "classnames"
|
||||
class Form extends Component {
|
||||
static propTypes = {
|
||||
changeset: PropTypes.shape({
|
||||
project: PropTypes.object,
|
||||
task: PropTypes.object,
|
||||
assignment_id: PropTypes.number.isRequired,
|
||||
billable: PropTypes.bool.isRequired,
|
||||
date: PropTypes.string.isRequired,
|
||||
task_id: PropTypes.number.isRequired,
|
||||
remote_id: PropTypes.string,
|
||||
remote_service: PropTypes.string,
|
||||
remote_url: PropTypes.string,
|
||||
seconds: PropTypes.number,
|
||||
hours: PropTypes.string,
|
||||
}).isRequired,
|
||||
errors: PropTypes.object,
|
||||
@@ -35,7 +41,7 @@ class Form extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { projects, changeset, errors, onChange, onSubmit } = this.props
|
||||
const { projects, changeset, timedActivity, errors, onChange, onSubmit } = this.props
|
||||
const project = Select.findOptionByValue(projects, changeset.assignment_id)
|
||||
|
||||
return (
|
||||
|
||||
@@ -48,12 +48,10 @@ class Popup extends Component {
|
||||
"loading",
|
||||
"service",
|
||||
"subdomain",
|
||||
"lastProjectId",
|
||||
"lastTaskId",
|
||||
"roundTimeEntries",
|
||||
"projects",
|
||||
"activities",
|
||||
"schedules",
|
||||
"timedActivity",
|
||||
"lastProjectId",
|
||||
"lastTaskId",
|
||||
"fromDate",
|
||||
|
||||
@@ -12,9 +12,7 @@ const parsedProps = parseProps([
|
||||
"projects",
|
||||
"activities",
|
||||
"schedules",
|
||||
"lastProjectId",
|
||||
"lastTaskId",
|
||||
"roundTimeEntries",
|
||||
"timedActivity",
|
||||
"lastProjectId",
|
||||
"lastTaskId",
|
||||
"fromDate",
|
||||
|
||||
@@ -83,19 +83,26 @@ async function openPopup(tab, { service, messenger }) {
|
||||
const toDate = getEndOfWeek()
|
||||
const settings = await getSettings()
|
||||
const apiClient = new ApiClient(settings)
|
||||
const responses = []
|
||||
try {
|
||||
const responses = await Promise.all([
|
||||
apiClient.login(service),
|
||||
apiClient.projects(),
|
||||
apiClient.activities(fromDate, toDate),
|
||||
apiClient.schedules(fromDate, toDate),
|
||||
])
|
||||
responses.push(await apiClient.login(service))
|
||||
// we can forgo the following calls if a timed activity exists
|
||||
if (!responses[0].data.timed_activity) {
|
||||
responses.push(
|
||||
...(await Promise.all([
|
||||
apiClient.projects(),
|
||||
apiClient.activities(fromDate, toDate),
|
||||
apiClient.schedules(fromDate, toDate),
|
||||
])),
|
||||
)
|
||||
}
|
||||
|
||||
const action = {
|
||||
type: "openPopup",
|
||||
payload: {
|
||||
service,
|
||||
subdomain: settings.subdomain,
|
||||
timedActivity: get("[0].data.timed_activity", responses),
|
||||
lastProjectId: get("[0].data.last_project_id", responses),
|
||||
lastTaskId: get("[0].data.last_task_id", responses),
|
||||
roundTimeEntries: get("[0].data.round_time_entries", responses),
|
||||
|
||||
Reference in New Issue
Block a user