parent
bc0628bcb7
commit
e6ee51f481
14 changed files with 356 additions and 11 deletions
@ -0,0 +1,42 @@ |
||||
import { |
||||
IS_SENDING_EMPLOYER_REQUEST, |
||||
SET_EMPLOYER_REQUEST_ERROR, |
||||
CLEAR_EMPLOYER_REQUEST_ERROR, |
||||
SET_EMPLOYER_REQUEST_SUCCESS, |
||||
CLEAR_EMPLOYER_REQUEST_SUCCESS |
||||
} from "../../constants/employer.constants"; |
||||
import { parseError } from "../common.actions"; |
||||
|
||||
export function isSendingEmployerRequest(sendingRequest) { |
||||
return { |
||||
type: IS_SENDING_EMPLOYER_REQUEST, |
||||
data: sendingRequest |
||||
}; |
||||
} |
||||
|
||||
export function setEmployerRequestError(exception) { |
||||
let error = parseError(exception); |
||||
return { |
||||
type: SET_EMPLOYER_REQUEST_ERROR, |
||||
data: error |
||||
}; |
||||
} |
||||
|
||||
export function clearEmployerRequestError() { |
||||
return { |
||||
type: CLEAR_EMPLOYER_REQUEST_ERROR |
||||
}; |
||||
} |
||||
|
||||
export function setEmployerRequestSuccess(response) { |
||||
return { |
||||
type: SET_EMPLOYER_REQUEST_SUCCESS, |
||||
data: response.detail || response |
||||
}; |
||||
} |
||||
|
||||
export function clearEmployerRequestSuccess() { |
||||
return { |
||||
type: CLEAR_EMPLOYER_REQUEST_SUCCESS |
||||
}; |
||||
} |
@ -0,0 +1,8 @@ |
||||
import { UPDATE_EMPLOYER_REQUEST } from "../../constants/employer.constants"; |
||||
|
||||
export function updateEmployerRequest(payload) { |
||||
return { |
||||
type: UPDATE_EMPLOYER_REQUEST, |
||||
data: payload |
||||
}; |
||||
} |
@ -0,0 +1,12 @@ |
||||
import { put } from "./baseApi"; |
||||
|
||||
/** |
||||
* Function wrapping PATCH request for updating employer information |
||||
* @param {string} uuid - employer UUID |
||||
* @param {boolean} approved - whether or not to approve employment relationship |
||||
*/ |
||||
export function updateEmployer(uuid, approved) { |
||||
return put(`/employer/${uuid}/`, { approved }).then(resp => |
||||
Promise.resolve(resp) |
||||
); |
||||
} |
@ -0,0 +1,133 @@ |
||||
import React, { Component } from "react"; |
||||
import { connect } from "react-redux"; |
||||
import { Redirect } from "react-router-dom"; |
||||
import { |
||||
Button, |
||||
Card, |
||||
Container, |
||||
Header, |
||||
Label, |
||||
List |
||||
} from "semantic-ui-react"; |
||||
import { updateEmployerRequest } from "../../../actions/employer/saga.actions"; |
||||
|
||||
class ProviderClients extends Component { |
||||
updateEmployer = (uuid, approved) => { |
||||
this.props.dispatch(updateEmployerRequest({ uuid, approved })); |
||||
}; |
||||
|
||||
render() { |
||||
const { selfUser } = this.props; |
||||
if (selfUser.provider) { |
||||
return ( |
||||
<ProviderClientsView |
||||
user={selfUser} |
||||
updateEmployer={this.updateEmployer} |
||||
/> |
||||
); |
||||
} else { |
||||
return <Redirect to="/" />; |
||||
} |
||||
} |
||||
} |
||||
|
||||
function mapStateToProps(state) { |
||||
return { selfUser: state.user.selfUser }; |
||||
} |
||||
|
||||
const ProviderClientsView = ({ user, updateEmployer }) => ( |
||||
<Container> |
||||
<Header>Clients</Header> |
||||
{(user.provider.employers || []).filter(employer => !employer.deleted) |
||||
.length > 0 && ( |
||||
<Card.Group> |
||||
{user.provider.employers |
||||
.filter(employer => !employer.deleted) |
||||
.map((employer, index) => ( |
||||
<Card key={index}> |
||||
<Card.Content> |
||||
{(employer.approved === null || |
||||
employer.approved === false) && ( |
||||
<div> |
||||
<Card.Header as="h4"> |
||||
{employer.client.trim() || "No Name!"} |
||||
</Card.Header> |
||||
<Card.Description>{employer.note}</Card.Description> |
||||
</div> |
||||
)} |
||||
{employer.approved && ( |
||||
<div> |
||||
<Card.Header as="h4"> |
||||
{`${employer.client.first_name} ${ |
||||
employer.client.last_name |
||||
}`.trim() || "No Name!"} |
||||
</Card.Header> |
||||
<Card.Description> |
||||
{employer.client.userinfo && ( |
||||
<List> |
||||
{employer.client.userinfo.phone_number && ( |
||||
<List.Item> |
||||
Phone Number:{" "} |
||||
{employer.client.userinfo.phone_number} |
||||
</List.Item> |
||||
)} |
||||
</List> |
||||
)} |
||||
</Card.Description> |
||||
</div> |
||||
)} |
||||
<Label |
||||
attached="bottom right" |
||||
color={ |
||||
employer.approved === null |
||||
? "grey" |
||||
: !!employer.approved ? "green" : "red" |
||||
} |
||||
> |
||||
{employer.approved === null |
||||
? "Pending" |
||||
: !!employer.approved ? "Approved" : "Ended"} |
||||
</Label> |
||||
</Card.Content> |
||||
<Card.Content extra> |
||||
<Button.Group> |
||||
{!employer.approved && ( |
||||
<Button |
||||
basic |
||||
color="green" |
||||
size="small" |
||||
onClick={() => updateEmployer(employer.uuid, true)} |
||||
> |
||||
Approve |
||||
</Button> |
||||
)} |
||||
{employer.approved === null && ( |
||||
<Button |
||||
basic |
||||
color="red" |
||||
size="small" |
||||
onClick={() => updateEmployer(employer.uuid, false)} |
||||
> |
||||
Reject |
||||
</Button> |
||||
)} |
||||
{employer.approved && ( |
||||
<Button |
||||
basic |
||||
color="red" |
||||
size="small" |
||||
onClick={() => updateEmployer(employer.uuid, false)} |
||||
> |
||||
End |
||||
</Button> |
||||
)} |
||||
</Button.Group> |
||||
</Card.Content> |
||||
</Card> |
||||
))} |
||||
</Card.Group> |
||||
)} |
||||
</Container> |
||||
); |
||||
|
||||
export default connect(mapStateToProps)(ProviderClients); |
@ -0,0 +1,9 @@ |
||||
// Reducer Employer Action Constants
|
||||
export const IS_SENDING_EMPLOYER_REQUEST = "IS_SENDING_EMPLOYER_REQUEST"; |
||||
export const SET_EMPLOYER_REQUEST_ERROR = "SET_EMPLOYER_REQUEST_ERROR"; |
||||
export const CLEAR_EMPLOYER_REQUEST_ERROR = "CLEAR_EMPLOYER_REQUEST_ERROR"; |
||||
export const SET_EMPLOYER_REQUEST_SUCCESS = "SET_EMPLOYER_REQUEST_SUCCESS"; |
||||
export const CLEAR_EMPLOYER_REQUEST_SUCCESS = "CLEAR_EMPLOYER_REQUEST_SUCCESS"; |
||||
|
||||
// Saga Employer Action Constants
|
||||
export const UPDATE_EMPLOYER_REQUEST = "UPDATE_EMPLOYER_REQUEST"; |
@ -0,0 +1,47 @@ |
||||
import { |
||||
IS_SENDING_EMPLOYER_REQUEST, |
||||
SET_EMPLOYER_REQUEST_ERROR, |
||||
CLEAR_EMPLOYER_REQUEST_ERROR, |
||||
SET_EMPLOYER_REQUEST_SUCCESS, |
||||
CLEAR_EMPLOYER_REQUEST_SUCCESS |
||||
} from "../constants/employer.constants"; |
||||
|
||||
const initialState = { |
||||
isSendingEmployerRequest: false, |
||||
employerRequestError: "", |
||||
employerRequestSuccess: "" |
||||
}; |
||||
|
||||
function employerReducer(state = initialState, action) { |
||||
switch (action.type) { |
||||
case IS_SENDING_EMPLOYER_REQUEST: |
||||
return { |
||||
...state, |
||||
isSendingEmployerRequest: action.data |
||||
}; |
||||
case SET_EMPLOYER_REQUEST_ERROR: |
||||
return { |
||||
...state, |
||||
employerRequestError: action.data |
||||
}; |
||||
case CLEAR_EMPLOYER_REQUEST_ERROR: |
||||
return { |
||||
...state, |
||||
employerRequestError: "" |
||||
}; |
||||
case SET_EMPLOYER_REQUEST_SUCCESS: |
||||
return { |
||||
...state, |
||||
employerRequestSuccess: action.data |
||||
}; |
||||
case CLEAR_EMPLOYER_REQUEST_SUCCESS: |
||||
return { |
||||
...state, |
||||
employerRequestSuccess: "" |
||||
}; |
||||
default: |
||||
return state; |
||||
} |
||||
} |
||||
|
||||
export default employerReducer; |
@ -0,0 +1,34 @@ |
||||
import { effects } from "redux-saga"; |
||||
import { |
||||
isSendingEmployerRequest, |
||||
setEmployerRequestError, |
||||
setEmployerRequestSuccess, |
||||
clearEmployerRequestError, |
||||
clearEmployerRequestSuccess |
||||
} from "../actions/employer/reducer.actions"; |
||||
import { getSelfUserRequest } from "../actions/user/saga.actions"; |
||||
import { updateEmployer } from "../api/employer.api"; |
||||
|
||||
function* updateEmployerCall(payload) { |
||||
yield effects.put(isSendingEmployerRequest(true)); |
||||
const { uuid, approved } = payload; |
||||
try { |
||||
return yield effects.call(updateEmployer, uuid, approved); |
||||
} catch (exception) { |
||||
yield effects.put(setEmployerRequestError(exception)); |
||||
return false; |
||||
} finally { |
||||
yield effects.put(isSendingEmployerRequest(false)); |
||||
} |
||||
} |
||||
|
||||
export function* updateEmployerFlow(request) { |
||||
yield effects.put(clearEmployerRequestSuccess()); |
||||
yield effects.put(clearEmployerRequestError()); |
||||
const wasSuccessful = yield effects.call(updateEmployerCall, request.data); |
||||
if (wasSuccessful) { |
||||
yield effects.put(getSelfUserRequest()); |
||||
yield effects.put(setEmployerRequestSuccess(wasSuccessful)); |
||||
yield effects.put(clearEmployerRequestError()); |
||||
} |
||||
} |
Loading…
Reference in new issue