Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addWorkItems = async (issueId, serviceId, workType, from, to) => {
- let wstate = this;
- const minutesADay = 8 * 60;
- let dashboardApi = this.props.dashboardApi;
- let workItemDate = this.resetTimeZone(from);
- let toDate = this.resetTimeZone(to);
- toDate.setDate(toDate.getDate() + 1);
- let resultError = '';
- let newAlerts = this.state.alerts;
- let loadingAlert = {
- type: Alert.Type.LOADING,
- key: `${Date.now()}`,
- message: `Идет трек отсутствия...`,
- isClosing: false
- };
- newAlerts.push(loadingAlert);
- this.setState({alerts: newAlerts});
- do {
- /*newAlerts.push({type: Alert.Type.WARNING, key: `${Date.now()}`, message: `${workItemDate}`});
- wstate.setState({alerts: newAlerts});*/
- await dashboardApi.fetch(serviceId, `rest/issue/${issueId}/timetracking/workitem`, {
- method: 'POST',
- body: {
- date: Date.parse(workItemDate),
- duration: minutesADay,
- worktype: {
- name: workType
- }
- }
- }).then(workItem => {
- }).catch(error => {
- resultError += `Error acquired on adding work item:\n${JSON.stringify(error.data.value)}\n`;
- });
- workItemDate.setDate(workItemDate.getDate() + 1);
- } while (workItemDate.toString() !== toDate.toString());
- if (resultError === "") {
- loadingAlert.isClosing = true;
- this.setRange({from: null, to: null});
- this.changeOption(null);
- newAlerts.push({
- type: Alert.Type.SUCCESS,
- key: `${Date.now()}`,
- message: `${'Отсутствие успешно отражено.'}`
- });
- this.setState({alerts: newAlerts});
- } else {
- loadingAlert.isClosing = true;
- newAlerts.push({
- type: Alert.Type.ERROR,
- key: `${Date.now()}`,
- message: `При треке отсутствия произошли следующие ошибки:${resultError}`
- });
- this.setState({alerts: newAlerts})
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement