From fb5f71a8816b4e781f60e79efac0b430a53712f0 Mon Sep 17 00:00:00 2001 From: Alexander Wong Date: Mon, 2 Jul 2018 15:03:00 -0600 Subject: [PATCH] added ability for client to adjust shift hours --- src/api/employer.api.js | 2 +- src/components/Shared/ShiftLabel.jsx | 25 +++ .../User/Client/ClientAddShiftForm.jsx | 2 + .../User/Client/ClientEditShiftForm.jsx | 11 +- .../User/Client/ClientShiftFormView.jsx | 9 +- src/components/User/Client/ClientShifts.jsx | 198 +++++++++++++----- .../User/Provider/ProviderShift.jsx | 47 +++-- .../User/Provider/ProviderShifts.jsx | 67 ++++-- 8 files changed, 260 insertions(+), 101 deletions(-) create mode 100644 src/components/Shared/ShiftLabel.jsx diff --git a/src/api/employer.api.js b/src/api/employer.api.js index f6ee023..08b4def 100644 --- a/src/api/employer.api.js +++ b/src/api/employer.api.js @@ -6,7 +6,7 @@ import { put } from "./baseApi"; * @param {boolean} approved - whether or not to approve employment relationship */ export function updateEmployer(uuid, approved) { - return put(`/employer/${uuid}/`, { approved }).then(resp => + return put(`/employer/${uuid}/`, { provider_approved: approved }).then(resp => Promise.resolve(resp) ); } diff --git a/src/components/Shared/ShiftLabel.jsx b/src/components/Shared/ShiftLabel.jsx new file mode 100644 index 0000000..03c1a93 --- /dev/null +++ b/src/components/Shared/ShiftLabel.jsx @@ -0,0 +1,25 @@ +import React from "react"; +import { Label } from "semantic-ui-react"; + +export default ({ + provider_approved, + client_approved_start, + client_approved_end +}) => { + const providerApproved = !!provider_approved; + const clientApproved = !!client_approved_start && providerApproved; + const providerRejected = !provider_approved && provider_approved !== null; + const providerPending = provider_approved === null; + return ( + + ); +}; diff --git a/src/components/User/Client/ClientAddShiftForm.jsx b/src/components/User/Client/ClientAddShiftForm.jsx index 49e8bb6..f5749ac 100644 --- a/src/components/User/Client/ClientAddShiftForm.jsx +++ b/src/components/User/Client/ClientAddShiftForm.jsx @@ -82,6 +82,8 @@ class ClientAddShiftForm extends Component { get_price_uuid: priceUUID, set_start: dynamicStartTime.format(), set_end: dynamicEndTime.format(), + approved_start: null, + approved_end: null, description: note ? note : undefined }); } diff --git a/src/components/User/Client/ClientEditShiftForm.jsx b/src/components/User/Client/ClientEditShiftForm.jsx index 30166c6..f8ecbde 100644 --- a/src/components/User/Client/ClientEditShiftForm.jsx +++ b/src/components/User/Client/ClientEditShiftForm.jsx @@ -87,6 +87,7 @@ class ClientEditShiftForm extends Component { event.preventDefault(); // change this into interable cshift post request bodies const { + cShiftRequestSuccess, cShiftUUID, priceUUID, startTime, @@ -94,6 +95,8 @@ class ClientEditShiftForm extends Component { note, shiftDates } = this.props; + const isProviderCheckedIn = !!cShiftRequestSuccess.actual_start; + const postRequestBodies = []; for (let shiftDateString in shiftDates) { const dynamicStartTime = utc(startTime); @@ -107,8 +110,10 @@ class ClientEditShiftForm extends Component { dynamicEndTime.add(duration, "minutes"); postRequestBodies.push({ get_price_uuid: priceUUID, - set_start: dynamicStartTime.format(), - set_end: dynamicEndTime.format(), + set_start: isProviderCheckedIn ? null : dynamicStartTime.format(), + set_end: isProviderCheckedIn ? null : dynamicEndTime.format(), + approved_start: isProviderCheckedIn ? dynamicStartTime.format() : null, + approved_end: isProviderCheckedIn ? dynamicEndTime.format() : null, description: note ? note : undefined }); } @@ -131,6 +136,7 @@ class ClientEditShiftForm extends Component { shiftDates, cShiftUUID } = this.props; + const isProviderCheckedIn = !!cShiftRequestSuccess.actual_start; if (!selfUser.client) { return ; @@ -206,6 +212,7 @@ class ClientEditShiftForm extends Component { handleSelectDate={this.handleSelectDate} onSubmitShifts={this.onSubmitShifts} isEditing={true} + isProviderCheckedIn={isProviderCheckedIn} /> ); } diff --git a/src/components/User/Client/ClientShiftFormView.jsx b/src/components/User/Client/ClientShiftFormView.jsx index 166309e..b7dbb12 100644 --- a/src/components/User/Client/ClientShiftFormView.jsx +++ b/src/components/User/Client/ClientShiftFormView.jsx @@ -49,12 +49,14 @@ export const ClientShiftFormView = ({ changeShiftNote, handleSelectDate, onSubmitShifts, - isEditing = false + isEditing = false, + isProviderCheckedIn = false }) => (
{!isEditing && "Schedule Shifts"} - {isEditing && "Edit Shift"} + {isEditing && !isProviderCheckedIn && "Edit Shift"} + {isEditing && isProviderCheckedIn && "Adjust and Approve Hours"}
{!isEditing && "Schedule Shifts"} - {isEditing && "Edit Shift"} + {isEditing && !isProviderCheckedIn && "Edit Shift"} + {isEditing && isProviderCheckedIn && "Adjust and Approve Hours"}
diff --git a/src/components/User/Client/ClientShifts.jsx b/src/components/User/Client/ClientShifts.jsx index 8ddba68..f163833 100644 --- a/src/components/User/Client/ClientShifts.jsx +++ b/src/components/User/Client/ClientShifts.jsx @@ -1,5 +1,5 @@ import { utc, ISO_8601, duration } from "moment"; -import React, { Component } from "react"; +import React, { Component, Fragment } from "react"; import { connect } from "react-redux"; import { Redirect, Link } from "react-router-dom"; import { @@ -25,9 +25,11 @@ import { } from "../../../actions/cShift/reducer.actions"; import { getCShiftsRequest, - deleteCShiftRequest + deleteCShiftRequest, + editCShiftRequest } from "../../../actions/cShift/saga.actions"; import { getEmployeeFromPrice, getPriceFromPrice } from "./ClientShiftShared"; +import ShiftLabel from "../../Shared/ShiftLabel"; class ClientShifts extends Component { constructor(props) { @@ -41,7 +43,7 @@ class ClientShifts extends Component { this.props.dispatch( getCShiftsRequest({ page: this.props.page, - approved: this.props.approvalFilter, + provider_approved: this.props.approvalFilter, completed: this.props.completedFilter, manage: this.props.providerFilter, work_type: this.props.workTypeFilter, @@ -54,7 +56,7 @@ class ClientShifts extends Component { this.props.dispatch( getCShiftsRequest({ page: activePage, - approved: this.props.approvalFilter, + provider_approved: this.props.approvalFilter, manage: this.props.providerFilter, work_type: this.props.workTypeFilter, page_size: this.state.pageSize @@ -67,7 +69,7 @@ class ClientShifts extends Component { this.props.dispatch( getCShiftsRequest({ page: 1, - approved: value, + provider_approved: value, completed: this.props.completedFilter, manage: this.props.providerFilter, work_type: this.props.workTypeFilter, @@ -82,7 +84,7 @@ class ClientShifts extends Component { this.props.dispatch( getCShiftsRequest({ page: 1, - approved: this.props.approvalFilter, + provider_approved: this.props.approvalFilter, completed: value, manage: this.props.providerFilter, work_type: this.props.workTypeFilter, @@ -97,7 +99,7 @@ class ClientShifts extends Component { this.props.dispatch( getCShiftsRequest({ page: 1, - approved: this.props.approvalFilter, + provider_approved: this.props.approvalFilter, completed: this.props.completedFilter, manage: value, work_type: this.props.workTypeFilter, @@ -112,7 +114,7 @@ class ClientShifts extends Component { this.props.dispatch( getCShiftsRequest({ page: 1, - approved: this.props.approvalFilter, + provider_approved: this.props.approvalFilter, completed: this.props.completedFilter, manage: this.props.manageFilter, work_type: value, @@ -127,6 +129,34 @@ class ClientShifts extends Component { this.props.dispatch(deleteCShiftRequest(uuid)); }; + approveHoursCShift = cshift => { + const { + set_start: approved_start, + set_end: approved_end, + price: get_price_uuid + } = cshift; + this.props.dispatch( + editCShiftRequest({ + uuid: cshift.uuid, + get_price_uuid, + approved_start, + approved_end, + set_start: null, + set_end: null + }) + ); + this.props.dispatch( + getCShiftsRequest({ + page: this.props.page, + provider_approved: this.props.approvalFilter, + completed: this.props.completedFilter, + manage: this.props.providerFilter, + work_type: this.props.workTypeFilter, + page_size: this.state.pageSize + }) + ); + }; + render() { const { isSendingCShiftRequest, @@ -157,6 +187,7 @@ class ClientShifts extends Component { handleChangeProviderFilter={this.handleChangeProviderFilter} handleChangeWorkTypeFilter={this.handleChangeWorkTypeFilter} deleteCShift={this.deleteCShift} + approveHoursCShift={this.approveHoursCShift} /> ); } else { @@ -184,7 +215,8 @@ const ClientShiftsView = ({ handleChangeCompletedFilter, handleChangeProviderFilter, handleChangeWorkTypeFilter, - deleteCShift + deleteCShift, + approveHoursCShift }) => { const { count = 0, results = [] } = cShiftRequestSuccess; const approvedOptions = [ @@ -240,7 +272,7 @@ const ClientShiftsView = ({ Schedule Shift - {"Filter by Approval "} + {"Filter by Provider Approval "} @@ -320,18 +350,14 @@ const ClientShiftsView = ({ {workType.label} - + - {"At " + + {"Scheduled for " + utc(result.set_start, ISO_8601) .local(false) .format(OLD_PEOPLE_TIME_FORMAT)} @@ -348,14 +374,6 @@ const ClientShiftsView = ({ {!checkedIn && ( - @@ -378,39 +396,109 @@ const ClientShiftsView = ({ on="click" position="top right" /> + )} {checkedIn && ( - - - {result.description && ( - {result.description} - )} - Provider - - - {"Checked in at " + - checkedIn - .local(false) - .format(OLD_PEOPLE_TIME_FORMAT)} - - {checkedOut && ( + + + + {result.description && ( + {result.description} + )} + {result.approved_start && ( + + Client + + + {`Approved time start ${utc( + result.approved_start + ) + .local(false) + .format(OLD_PEOPLE_TIME_FORMAT)}`} + + {`Approved time end ${utc( + result.approved_end + ) + .local(false) + .format(OLD_PEOPLE_TIME_FORMAT)}`} + + + )} + Provider + - {"Checked out at " + - checkedOut + {"Checked in at " + + checkedIn .local(false) .format(OLD_PEOPLE_TIME_FORMAT)} + {checkedOut && ( + + {"Checked out at " + + checkedOut + .local(false) + .format(OLD_PEOPLE_TIME_FORMAT)} + + )} + + {result.chart && ( + + Chart + {result.chart} + )} - - {result.chart && ( - - Chart - {result.chart} - + + + + + Are you sure you want to delete this shift?
+ + + } + trigger={ + + } + on="click" + position="top right" + /> + + {!result.approved_start && ( + )} - - +
+ )} ); diff --git a/src/components/User/Provider/ProviderShift.jsx b/src/components/User/Provider/ProviderShift.jsx index 1ecca96..504c32a 100644 --- a/src/components/User/Provider/ProviderShift.jsx +++ b/src/components/User/Provider/ProviderShift.jsx @@ -1,5 +1,5 @@ import { utc, duration, ISO_8601 } from "moment"; -import React, { Component } from "react"; +import React, { Component, Fragment } from "react"; import { connect } from "react-redux"; import { Redirect } from "react-router-dom"; import { @@ -27,6 +27,7 @@ import { getWorkTypeFromPrice, getPriceFromPrice } from "./ProviderShiftsShared"; +import ShiftLabel from "../../Shared/ShiftLabel"; class ProviderShift extends Component { handleChangePShiftApproval = (uuid, approved) => { @@ -34,7 +35,7 @@ class ProviderShift extends Component { this.props.dispatch( updatePShiftRequest({ uuid, - approved, + provider_approved: approved, action: "", chart: null, single: true @@ -48,7 +49,7 @@ class ProviderShift extends Component { this.props.dispatch( updatePShiftRequest({ uuid: pShiftRequestSuccess.uuid, - approved: true, + provider_approved: true, action: "checkin", chart: null, single: true @@ -65,7 +66,7 @@ class ProviderShift extends Component { this.props.dispatch( updatePShiftRequest({ uuid: pShiftRequestSuccess.uuid, - approved: true, + provider_approved: true, action: "checkout", chart, single: true @@ -128,22 +129,18 @@ const ProviderShiftFormView = ({ displayDuration = duration(Math.floor(min / 60), "hours").humanize(); displayDuration += ` and ${duration(min % 60, "minutes").humanize()}`; } - const approved = !!shift.approved; - const rejected = !shift.approved && shift.approved !== null; - const pending = shift.approved === null; + const approved = !!shift.provider_approved; + const rejected = !shift.provider_approved && shift.provider_approved !== null; + // const pending = shift.provider_approved === null; return (
Shift Details
- +