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, Header, Item, Segment, Pagination, Popup, Loader, Label, List, Message } from "semantic-ui-react"; import { getCShiftsRequest, deleteCShiftRequest } from "../../../actions/cShift/saga.actions"; import { getEmployeeFromPrice, getPriceFromPrice } from "./ClientShiftShared"; class ClientShifts extends Component { constructor(props) { super(props); this.state = { page: 1, pageSize: 10 // client can't control this, but set here just in case }; } componentWillMount = () => { this.props.dispatch( getCShiftsRequest({ page: this.state.page, page_size: this.state.pageSize }) ); }; handlePaginationChange = (event, { activePage }) => { this.props.dispatch( getCShiftsRequest({ page: activePage, page_size: this.state.pageSize }) ); this.setState({ page: activePage }); }; deleteCShift = uuid => { this.props.dispatch(deleteCShiftRequest(uuid)); }; render() { const { isSendingCShiftRequest, cShiftRequestSuccess, selfUser } = this.props; const { page, 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, pageSize, handlePaginationChange, deleteCShift }) => { const { count = 0, results = [] } = cShiftRequestSuccess; return (
Shifts
{!!isSendingCShiftRequest && } {!isSendingCShiftRequest && results.length > 0 && ( {results.map(result => { const employee = getEmployeeFromPrice(result.price, user) || {}; const provider = employee.provider || {}; const price = getPriceFromPrice(result.price, user) || {}; const workType = price.work_type; const checkedIn = !!result.actual_start && utc(result.actual_start, ISO_8601); const checkedOut = !!result.actual_end && utc(result.actual_end, ISO_8601); const min = duration( utc(result.set_end, ISO_8601) - utc(result.set_start, ISO_8601), "milliseconds" ).as("minutes"); let displayDuration = duration(min, "minutes").humanize(); if (min % 60) { displayDuration = duration( Math.floor(min / 60), "hours" ).humanize(); displayDuration += ` and ${duration( min % 60, "minutes" ).humanize()}`; } const approved = !!result.approved; const rejected = !result.approved && result.approved !== null; const pending = result.approved === null; return ( {"At " + utc(result.set_start, ISO_8601) .local(false) .format("dddd, MMMM Do YYYY, h:mm a Z")} {displayDuration} {`Rate $${price.amount}/hour`} {/* {result.description} */} {/* {JSON.stringify(result, null, 2)} */} {`${provider.first_name} ${provider.last_name}`.trim() || "No Name!"}{" "} {provider.email} {!checkedIn && ( Are you sure you want to delete this shift?
} trigger={ } on="click" position="top right" />
)} {checkedIn && ( {result.description && ( {result.description} )} Provider {"Checked in at " + checkedIn .local(false) .format("dddd, MMMM Do YYYY, h:mm a Z")} {checkedOut && ( {"Checked out at " + checkedOut .local(false) .format("dddd, MMMM Do YYYY, h:mm a Z")} )} {result.chart && ( Chart {result.chart} )} )}
); })}
)}
); }; export default connect(mapStateToProps)(ClientShifts);