import { utc, ISO_8601, duration } from "moment"; import React, { Component } from "react"; import { connect } from "react-redux"; import { Redirect, Link } from "react-router-dom"; import { Button, Container, Dropdown, Header, Item, Segment, Pagination, Popup, Loader, Label, List, Message } from "semantic-ui-react"; import { setCShiftPage, setCShiftApprovalFilter, setCShiftCompletedFilter, setCShiftProviderFilter, setCShiftWorkTypeFilter } from "../../../actions/cShift/reducer.actions"; import { getCShiftsRequest, deleteCShiftRequest } from "../../../actions/cShift/saga.actions"; import { getEmployeeFromPrice, getPriceFromPrice } from "./ClientShiftShared"; class ClientShifts extends Component { constructor(props) { super(props); this.state = { pageSize: 10 // client can't control this, but set here just in case }; } componentWillMount = () => { this.props.dispatch( getCShiftsRequest({ page: this.props.page, approved: this.props.approvalFilter, completed: this.props.completedFilter, manage: this.props.providerFilter, work_type: this.props.workTypeFilter, page_size: this.state.pageSize }) ); }; handlePaginationChange = (event, { activePage }) => { this.props.dispatch( getCShiftsRequest({ page: activePage, approved: this.props.approvalFilter, manage: this.props.providerFilter, work_type: this.props.workTypeFilter, page_size: this.state.pageSize }) ); this.props.dispatch(setCShiftPage(activePage)); }; handleChangeApprovalFilter = (event, { value }) => { this.props.dispatch( getCShiftsRequest({ page: 1, approved: value, completed: this.props.completedFilter, manage: this.props.providerFilter, work_type: this.props.workTypeFilter, page_size: this.state.pageSize }) ); this.props.dispatch(setCShiftApprovalFilter(value)); this.props.dispatch(setCShiftPage(1)); }; handleChangeCompletedFilter = (event, { value }) => { this.props.dispatch( getCShiftsRequest({ page: 1, approved: this.props.approvalFilter, completed: value, manage: this.props.providerFilter, work_type: this.props.workTypeFilter, page_size: this.state.pageSize }) ); this.props.dispatch(setCShiftCompletedFilter(value)); this.props.dispatch(setCShiftPage(1)); }; handleChangeProviderFilter = (event, { value }) => { this.props.dispatch( getCShiftsRequest({ page: 1, approved: this.props.approvalFilter, completed: this.props.completedFilter, manage: value, work_type: this.props.workTypeFilter, page_size: this.state.pageSize }) ); this.props.dispatch(setCShiftProviderFilter(value)); this.props.dispatch(setCShiftPage(1)); }; handleChangeWorkTypeFilter = (event, { value }) => { this.props.dispatch( getCShiftsRequest({ page: 1, approved: this.props.approvalFilter, completed: this.props.completedFilter, manage: this.props.manageFilter, work_type: value, page_size: this.state.pageSize }) ); this.props.dispatch(setCShiftWorkTypeFilter(value)); this.props.dispatch(setCShiftPage(1)); }; deleteCShift = uuid => { this.props.dispatch(deleteCShiftRequest(uuid)); }; render() { const { isSendingCShiftRequest, cShiftRequestSuccess, selfUser, page, approvalFilter, completedFilter, providerFilter, workTypeFilter } = this.props; const { pageSize } = this.state; if (selfUser.client) { return ( ); } else { return ; } } } function mapStateToProps(state) { return { ...state.cShift, selfUser: state.user.selfUser }; } const ClientShiftsView = ({ isSendingCShiftRequest, cShiftRequestSuccess, user, page, approvalFilter, completedFilter, providerFilter, workTypeFilter, pageSize, handlePaginationChange, handleChangeApprovalFilter, handleChangeCompletedFilter, handleChangeProviderFilter, handleChangeWorkTypeFilter, deleteCShift }) => { const { count = 0, results = [] } = cShiftRequestSuccess; const approvedOptions = [ { text: "Approved", value: true }, { text: "Rejected", value: false }, { text: "Pending", value: "" }, { text: "All", value: null } ]; const completedOptions = [ { text: "Completed", value: true }, { text: "Incomplete", value: false }, { text: "All", value: null } ]; const manageOptions = (user.client.employees || []).map(employee => { const name = `${employee.provider.first_name} ${employee.provider.last_name}`.trim() || "No Name"; return { text: `${name} <${employee.provider.email}>`, value: employee.uuid }; }); manageOptions.push({ text: `All`, value: null }); const workTypeOptions = (user.client.work_types || []).map(workType => { return { text: `${workType.label}`, value: workType.uuid, label: (