import { utc, duration, ISO_8601 } from "moment";
import React, { Component, Fragment } from "react";
import { connect } from "react-redux";
import { Redirect } from "react-router-dom";
import {
Button,
Container,
Header,
Label,
List,
Loader,
Message,
TextArea,
Form
} from "semantic-ui-react";
import {
setClearPShiftState,
setFormShiftChart
} from "../../../actions/pShift/reducer.actions";
import {
getPShiftRequest,
updatePShiftRequest
} from "../../../actions/pShift/saga.actions";
import Error from "../../Shared/Error";
import {
getEmployerFromPrice,
getWorkTypeFromPrice,
getPriceFromPrice
} from "./ProviderShiftsShared";
import ShiftLabel from "../../Shared/ShiftLabel";
class ProviderShift extends Component {
handleChangePShiftApproval = (uuid, approved) => {
return () => {
this.props.dispatch(
updatePShiftRequest({
uuid,
provider_approved: approved,
action: "",
chart: null,
single: true
})
);
};
};
handleCheckInPShift = () => {
const { pShiftRequestSuccess } = this.props;
this.props.dispatch(
updatePShiftRequest({
uuid: pShiftRequestSuccess.uuid,
provider_approved: true,
action: "checkin",
chart: null,
single: true
})
);
};
handleChangeChart = event => {
this.props.dispatch(setFormShiftChart(event.target.value));
};
handleCheckOutPShift = () => {
const { pShiftRequestSuccess, chart } = this.props;
this.props.dispatch(
updatePShiftRequest({
uuid: pShiftRequestSuccess.uuid,
provider_approved: true,
action: "checkout",
chart,
single: true
})
);
};
render() {
const {
isSendingPShiftRequest,
pShiftRequestError,
pShiftRequestSuccess,
selfUser,
chart
} = this.props;
if (!selfUser.provider) {
return ;
}
return (
);
}
}
const ProviderShiftFormView = ({
isSendingPShiftRequest,
pShiftRequestError,
shift,
chart,
user,
handleChangeChart,
handleChangePShiftApproval,
handleCheckInPShift,
handleCheckOutPShift
}) => {
const OLD_PEOPLE_TIME_FORMAT = "dddd, MMMM Do YYYY, h:mm a";
const employer = getEmployerFromPrice(shift.price, user) || {};
const client = employer.client || {};
const workType = getWorkTypeFromPrice(shift.price, user) || {};
const price = getPriceFromPrice(shift.price, user) || {};
const checkedIn = !!shift.actual_start && utc(shift.actual_start, ISO_8601);
const checkedOut = !!shift.actual_end && utc(shift.actual_end, ISO_8601);
const min = duration(
utc(shift.set_end, ISO_8601) - utc(shift.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 = !!shift.provider_approved;
const rejected = !shift.provider_approved && shift.provider_approved !== null;
// const pending = shift.provider_approved === null;
return (
{" "}
{workType.label}
{"Scheduled for " +
utc(shift.set_start, ISO_8601)
.local(false)
.format(OLD_PEOPLE_TIME_FORMAT)}
{displayDuration}
{`Rate $${price.amount}/hour`}
Employer/Client:{" "}
{`${client.first_name} ${client.last_name}`.trim() || "No Name!"}{" "}
{client.email}
{shift.description && (
Description
{shift.description}
)}
{!checkedIn && (
{!approved && (
)}
{!rejected && (
)}
)}
{shift.approved_start && (
Client
{`Approved time start ${utc(shift.approved_start)
.local(false)
.format(OLD_PEOPLE_TIME_FORMAT)}`}
{`Approved time end ${utc(shift.approved_end)
.local(false)
.format(OLD_PEOPLE_TIME_FORMAT)}`}
)}
Provider
{!checkedIn && Pending Check In}{" "}
{checkedIn && (
Checked In At:{" "}
{checkedIn.local(false).format(OLD_PEOPLE_TIME_FORMAT)}
)}
{checkedOut && (
Checked Out At:{" "}
{checkedOut.local(false).format(OLD_PEOPLE_TIME_FORMAT)}
)}
{shift.chart && (
Chart
{shift.chart}
)}
{!checkedIn && }
{checkedIn &&
!checkedOut && (
)}
);
};
function mapStateToProps(state) {
return { ...state.pShift, selfUser: state.user.selfUser };
}
class ProviderShiftWrapper extends Component {
constructor(props) {
super(props);
this.props.dispatch(setClearPShiftState());
this.props.dispatch(
getPShiftRequest({ uuid: this.props.match.params.shiftUUID })
);
}
render() {
const { pShiftRequestSuccess, pShiftRequestError } = this.props;
if (pShiftRequestSuccess.uuid) {
return ;
} else if (!pShiftRequestError) {
return ;
} else {
return ;
}
}
}
export default connect(mapStateToProps)(ProviderShiftWrapper);