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, Pagination, Loader, Label } from "semantic-ui-react"; import { getEmployerFromPrice, getPriceFromPrice } from "./ProviderShiftsShared"; import { getPShiftsRequest, updatePShiftRequest } from "../../../actions/pShift/saga.actions"; class ProviderShifts 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( getPShiftsRequest({ page: this.state.page, page_size: this.state.pageSize }) ); }; handlePaginationChange = (event, { activePage }) => { this.props.dispatch( getPShiftsRequest({ page: activePage, page_size: this.state.pageSize }) ); this.setState({ page: activePage }); }; handleChangePShiftApproval = (uuid, approved) => { return () => { this.props.dispatch( updatePShiftRequest({ uuid, approved, action: "", chart: null }) ); }; }; render() { const { isSendingPShiftRequest, pShiftRequestSuccess, selfUser } = this.props; const { page, pageSize } = this.state; if (selfUser.provider) { return ( ); } else { return ; } } } function mapStateToProps(state) { return { ...state.pShift, selfUser: state.user.selfUser }; } const ProviderShiftsView = ({ isSendingPShiftRequest, pShiftRequestSuccess, user, page, pageSize, handlePaginationChange, handleChangePShiftApproval }) => { const { count = 0, results = [] } = pShiftRequestSuccess; return (
Shifts
{!!isSendingPShiftRequest && } {!isSendingPShiftRequest && results.length > 0 && ( {results.map(result => { const employer = getEmployerFromPrice(result.price, user) || {}; const client = employer.client || {}; const price = getPriceFromPrice(result.price, user) || {}; const workType = price.work_type || {}; 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)} */} {`${client.first_name} ${client.last_name}`.trim() || "No Name!"}{" "} {client.email} {!approved && ( )} {!rejected && ( )} ); })} )}
); }; export default connect(mapStateToProps)(ProviderShifts);