Added worktype menu option, usertype check, deletion confirmation, redirect
This commit is contained in:
parent
0ae0a92187
commit
0486a7fe64
|
@ -7,8 +7,9 @@ import Register from "./Auth/Register";
|
||||||
import ResetPassword from "./Auth/ResetPassword";
|
import ResetPassword from "./Auth/ResetPassword";
|
||||||
import Settings from "./Auth/Settings";
|
import Settings from "./Auth/Settings";
|
||||||
import VerifyEmail from "./Auth/VerifyEmail";
|
import VerifyEmail from "./Auth/VerifyEmail";
|
||||||
import CreateWorkTypeForm from "./User/Client/CreateWorkTypeForm";
|
import CreateWorkTypeForm from "./Worktype/CreateWorkTypeForm";
|
||||||
import UpdateWorkTypeForm from "./User/Client/UpdateWorkTypeForm";
|
import UpdateWorkTypeForm from "./Worktype/UpdateWorkTypeForm";
|
||||||
|
import Worktypes from "./Worktype/Worktypes";
|
||||||
import CompleteRegistration from "./User/CompleteRegistration";
|
import CompleteRegistration from "./User/CompleteRegistration";
|
||||||
import EditProfile from "./User/EditProfile";
|
import EditProfile from "./User/EditProfile";
|
||||||
import Profile from "./User/Profile";
|
import Profile from "./User/Profile";
|
||||||
|
@ -48,6 +49,10 @@ class App extends Component {
|
||||||
path="/auth/reset-password/:uid/:token"
|
path="/auth/reset-password/:uid/:token"
|
||||||
component={ResetPassword}
|
component={ResetPassword}
|
||||||
/>
|
/>
|
||||||
|
<PrivateRoute
|
||||||
|
path="/user/profile/client/worktypes"
|
||||||
|
component={Worktypes}
|
||||||
|
/>
|
||||||
<PrivateRoute
|
<PrivateRoute
|
||||||
path="/user/profile/client/update-worktype/:uuid"
|
path="/user/profile/client/update-worktype/:uuid"
|
||||||
component={UpdateWorkTypeForm}
|
component={UpdateWorkTypeForm}
|
||||||
|
|
|
@ -20,11 +20,12 @@ class Navbar extends Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { userToken } = this.props;
|
const { userToken, selfUser } = this.props;
|
||||||
return (
|
return (
|
||||||
<NavbarView
|
<NavbarView
|
||||||
isAuthenticated={!!userToken}
|
isAuthenticated={!!userToken}
|
||||||
dispatchLogoutRequest={this.dispatchLogoutRequest}
|
dispatchLogoutRequest={this.dispatchLogoutRequest}
|
||||||
|
selfUser={selfUser}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +38,7 @@ function mapStateToProps(state) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const NavbarView = ({ isAuthenticated, dispatchLogoutRequest }) => (
|
const NavbarView = ({ isAuthenticated, dispatchLogoutRequest, selfUser }) => (
|
||||||
<Menu>
|
<Menu>
|
||||||
<Menu.Item as={Link} to="/">
|
<Menu.Item as={Link} to="/">
|
||||||
Caremyway
|
Caremyway
|
||||||
|
@ -61,6 +62,10 @@ const NavbarView = ({ isAuthenticated, dispatchLogoutRequest }) => (
|
||||||
<Dropdown.Item as={Link} to="/user/profile">
|
<Dropdown.Item as={Link} to="/user/profile">
|
||||||
My Profile
|
My Profile
|
||||||
</Dropdown.Item>
|
</Dropdown.Item>
|
||||||
|
{selfUser.client &&
|
||||||
|
<Dropdown.Item as={Link} to="/user/profile/client/worktypes">
|
||||||
|
Work Types
|
||||||
|
</Dropdown.Item>}
|
||||||
<Dropdown.Item as={Link} to="/auth/settings">
|
<Dropdown.Item as={Link} to="/auth/settings">
|
||||||
Settings
|
Settings
|
||||||
</Dropdown.Item>
|
</Dropdown.Item>
|
||||||
|
|
|
@ -1,20 +1,11 @@
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { Link } from "react-router-dom";
|
import { Card } from "semantic-ui-react";
|
||||||
import { Card, Button, Label } from "semantic-ui-react";
|
|
||||||
|
|
||||||
import { deleteWorktypeRequest } from "../../../actions/worktype/saga.actions";
|
|
||||||
|
|
||||||
class ClientProfile extends Component {
|
class ClientProfile extends Component {
|
||||||
deleteWorkType = uuid => {
|
|
||||||
this.props.dispatch(deleteWorktypeRequest(uuid));
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { selfUser } = this.props;
|
const { selfUser } = this.props;
|
||||||
return (
|
return <ClientProfileView user={selfUser} />;
|
||||||
<ClientProfileView user={selfUser} deleteWorkType={this.deleteWorkType} />
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,72 +13,15 @@ function mapStateToProps(state) {
|
||||||
return { ...state.user };
|
return { ...state.user };
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClientProfileView = ({ user, deleteWorkType }) => (
|
const ClientProfileView = ({ user }) => (
|
||||||
<div>
|
|
||||||
<Card fluid={true}>
|
<Card fluid={true}>
|
||||||
<Card.Content>
|
<Card.Content>
|
||||||
<Card.Header>Client Information</Card.Header>
|
<Card.Header>Client Information</Card.Header>
|
||||||
<Card.Meta>Business Number: {user.client.business_number}</Card.Meta>
|
{user.client &&
|
||||||
<Card.Description>
|
user.client.business_number &&
|
||||||
<Button
|
<Card.Meta>Business Number: {user.client.business_number}</Card.Meta>}
|
||||||
basic
|
|
||||||
color="green"
|
|
||||||
size="small"
|
|
||||||
as={Link}
|
|
||||||
to="/user/profile/client/create-worktype"
|
|
||||||
>
|
|
||||||
Create Worktype
|
|
||||||
</Button>
|
|
||||||
</Card.Description>
|
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
</Card>
|
</Card>
|
||||||
{(user.client.work_types || []).filter(worktype => !worktype.deleted)
|
|
||||||
.length > 0 &&
|
|
||||||
<Card.Group>
|
|
||||||
{user.client.work_types
|
|
||||||
.filter(worktype => !worktype.deleted)
|
|
||||||
.map((worktype, index) => (
|
|
||||||
<Card key={index}>
|
|
||||||
<Card.Content>
|
|
||||||
<Card.Header as="h4">
|
|
||||||
<Label
|
|
||||||
circular
|
|
||||||
empty
|
|
||||||
style={{
|
|
||||||
backgroundColor: worktype.color,
|
|
||||||
borderColor: worktype.color
|
|
||||||
}}
|
|
||||||
/>{" " + worktype.label}
|
|
||||||
</Card.Header>
|
|
||||||
<Card.Meta>
|
|
||||||
Worktype
|
|
||||||
</Card.Meta>
|
|
||||||
</Card.Content>
|
|
||||||
<Card.Content extra>
|
|
||||||
<Button.Group>
|
|
||||||
<Button
|
|
||||||
basic
|
|
||||||
color="yellow"
|
|
||||||
size="small"
|
|
||||||
as={Link}
|
|
||||||
to={`/user/profile/client/update-worktype/${worktype.uuid}`}
|
|
||||||
>
|
|
||||||
Edit
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
basic
|
|
||||||
color="red"
|
|
||||||
size="small"
|
|
||||||
onClick={() => deleteWorkType(worktype.uuid)}
|
|
||||||
>
|
|
||||||
Delete
|
|
||||||
</Button>
|
|
||||||
</Button.Group>
|
|
||||||
</Card.Content>
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
</Card.Group>}
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
export default connect(mapStateToProps)(ClientProfile);
|
export default connect(mapStateToProps)(ClientProfile);
|
||||||
|
|
|
@ -38,11 +38,13 @@ const ProfileView = ({ user }) => (
|
||||||
"User Registration Not Completed"}
|
"User Registration Not Completed"}
|
||||||
</span>
|
</span>
|
||||||
{user.first_name} {user.last_name}
|
{user.first_name} {user.last_name}
|
||||||
|
{user.userinfo &&
|
||||||
<List>
|
<List>
|
||||||
|
{user.userinfo.phone_number &&
|
||||||
<List.Item>
|
<List.Item>
|
||||||
Phone Number: {user.userinfo.phone_number}
|
Phone Number: {user.userinfo.phone_number}
|
||||||
</List.Item>
|
</List.Item>}
|
||||||
</List>
|
</List>}
|
||||||
</Card.Description>
|
</Card.Description>
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
<Card.Content extra>
|
<Card.Content extra>
|
||||||
|
|
|
@ -5,9 +5,7 @@ import { Card } from "semantic-ui-react";
|
||||||
class ProviderProfile extends Component {
|
class ProviderProfile extends Component {
|
||||||
render() {
|
render() {
|
||||||
const { selfUser } = this.props;
|
const { selfUser } = this.props;
|
||||||
return (
|
return <ProviderProfileView user={selfUser} />;
|
||||||
<ProviderProfileView user={selfUser} />
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +18,9 @@ const ProviderProfileView = ({ user }) => (
|
||||||
<Card fluid={true}>
|
<Card fluid={true}>
|
||||||
<Card.Content>
|
<Card.Content>
|
||||||
<Card.Header>Provider Information</Card.Header>
|
<Card.Header>Provider Information</Card.Header>
|
||||||
<Card.Meta>Social Insurance Number: {user.provider.sin}</Card.Meta>
|
{user.provider &&
|
||||||
|
user.provider.sin &&
|
||||||
|
<Card.Meta>Social Insurance Number: {user.provider.sin}</Card.Meta>}
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { GithubPicker } from "react-color";
|
import { GithubPicker } from "react-color";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
import { Redirect } from "react-router-dom";
|
||||||
import { Container, Form, Header, Label, Message } from "semantic-ui-react";
|
import { Container, Form, Header, Label, Message } from "semantic-ui-react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -8,12 +9,12 @@ import {
|
||||||
clearWorktypeRequestSuccess,
|
clearWorktypeRequestSuccess,
|
||||||
setFormWorktypeColor,
|
setFormWorktypeColor,
|
||||||
setFormWorktypeLabel
|
setFormWorktypeLabel
|
||||||
} from "../../../actions/worktype/reducer.actions";
|
} from "../../actions/worktype/reducer.actions";
|
||||||
import { createWorktypeRequest } from "../../../actions/worktype/saga.actions";
|
import { createWorktypeRequest } from "../../actions/worktype/saga.actions";
|
||||||
import Error from "../../Shared/Error";
|
import Error from "../Shared/Error";
|
||||||
|
|
||||||
class CreateWorkTypeForm extends Component {
|
class CreateWorkTypeForm extends Component {
|
||||||
componentWillUnmount = () => {
|
componentWillMount = () => {
|
||||||
this.props.dispatch(clearWorktypeRequestError());
|
this.props.dispatch(clearWorktypeRequestError());
|
||||||
this.props.dispatch(clearWorktypeRequestSuccess());
|
this.props.dispatch(clearWorktypeRequestSuccess());
|
||||||
this.props.dispatch(setFormWorktypeColor(""));
|
this.props.dispatch(setFormWorktypeColor(""));
|
||||||
|
@ -40,9 +41,14 @@ class CreateWorkTypeForm extends Component {
|
||||||
worktypeRequestError,
|
worktypeRequestError,
|
||||||
worktypeRequestSuccess,
|
worktypeRequestSuccess,
|
||||||
label,
|
label,
|
||||||
color
|
color,
|
||||||
|
selfUser
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
if (!selfUser.client) {
|
||||||
|
return <Redirect to="/" />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CreateWorkTypeFormView
|
<CreateWorkTypeFormView
|
||||||
isSendingWorktypeRequest={isSendingWorktypeRequest}
|
isSendingWorktypeRequest={isSendingWorktypeRequest}
|
||||||
|
@ -59,7 +65,7 @@ class CreateWorkTypeForm extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
return { ...state.worktype };
|
return { ...state.worktype, selfUser: state.user.selfUser };
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateWorkTypeFormView = ({
|
const CreateWorkTypeFormView = ({
|
||||||
|
@ -105,7 +111,8 @@ const CreateWorkTypeFormView = ({
|
||||||
<Error header="Create Worktype failed!" error={worktypeRequestError} />
|
<Error header="Create Worktype failed!" error={worktypeRequestError} />
|
||||||
<Message success>
|
<Message success>
|
||||||
<Message.Header>Create Worktype successful!</Message.Header>
|
<Message.Header>Create Worktype successful!</Message.Header>
|
||||||
<p>Set worktype successfully.</p>
|
<p>Worktype successfully created.</p>
|
||||||
|
{!!worktypeRequestSuccess && <Redirect to="/user/profile/client/worktypes" />}
|
||||||
</Message>
|
</Message>
|
||||||
<Form.Button>Submit Worktype</Form.Button>
|
<Form.Button>Submit Worktype</Form.Button>
|
||||||
</Form>
|
</Form>
|
|
@ -1,26 +1,26 @@
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { GithubPicker } from "react-color";
|
import { GithubPicker } from "react-color";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
import { Redirect } from "react-router-dom";
|
||||||
import { Container, Form, Header, Label, Message } from "semantic-ui-react";
|
import { Container, Form, Header, Label, Message } from "semantic-ui-react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
clearWorktypeRequestError,
|
|
||||||
clearWorktypeRequestSuccess,
|
|
||||||
setFormWorktypeColor,
|
setFormWorktypeColor,
|
||||||
setFormWorktypeLabel
|
setFormWorktypeLabel
|
||||||
} from "../../../actions/worktype/reducer.actions";
|
} from "../../actions/worktype/reducer.actions";
|
||||||
import { updateWorktypeRequest, readWorktypeRequest } from "../../../actions/worktype/saga.actions";
|
import {
|
||||||
import Error from "../../Shared/Error";
|
updateWorktypeRequest,
|
||||||
|
readWorktypeRequest
|
||||||
|
} from "../../actions/worktype/saga.actions";
|
||||||
|
import Error from "../Shared/Error";
|
||||||
|
|
||||||
class UpdateWorkTypeForm extends Component {
|
class UpdateWorkTypeForm extends Component {
|
||||||
componentWillMount = () => {
|
componentWillMount = () => {
|
||||||
const uuid = this.props.match.params.uuid;
|
const uuid = this.props.match.params.uuid;
|
||||||
this.props.dispatch(readWorktypeRequest(uuid));
|
this.props.dispatch(readWorktypeRequest(uuid));
|
||||||
}
|
};
|
||||||
|
|
||||||
componentWillUnmount = () => {
|
componentWillUnmount = () => {
|
||||||
this.props.dispatch(clearWorktypeRequestError());
|
|
||||||
this.props.dispatch(clearWorktypeRequestSuccess());
|
|
||||||
this.props.dispatch(setFormWorktypeColor(""));
|
this.props.dispatch(setFormWorktypeColor(""));
|
||||||
this.props.dispatch(setFormWorktypeLabel(""));
|
this.props.dispatch(setFormWorktypeLabel(""));
|
||||||
};
|
};
|
||||||
|
@ -42,9 +42,14 @@ class UpdateWorkTypeForm extends Component {
|
||||||
worktypeRequestSuccess,
|
worktypeRequestSuccess,
|
||||||
uuid,
|
uuid,
|
||||||
label,
|
label,
|
||||||
color
|
color,
|
||||||
|
selfUser
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
if (!selfUser.client) {
|
||||||
|
return <Redirect to="/" />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UpdateWorkTypeFormView
|
<UpdateWorkTypeFormView
|
||||||
isSendingWorktypeRequest={isSendingWorktypeRequest}
|
isSendingWorktypeRequest={isSendingWorktypeRequest}
|
||||||
|
@ -61,7 +66,7 @@ class UpdateWorkTypeForm extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
return { ...state.worktype };
|
return { ...state.worktype, selfUser: state.user.selfUser };
|
||||||
}
|
}
|
||||||
|
|
||||||
const UpdateWorkTypeFormView = ({
|
const UpdateWorkTypeFormView = ({
|
||||||
|
@ -101,7 +106,9 @@ const UpdateWorkTypeFormView = ({
|
||||||
<Error header="Update Worktype failed!" error={worktypeRequestError} />
|
<Error header="Update Worktype failed!" error={worktypeRequestError} />
|
||||||
<Message success>
|
<Message success>
|
||||||
<Message.Header>Update Worktype successful!</Message.Header>
|
<Message.Header>Update Worktype successful!</Message.Header>
|
||||||
<p>Update worktype successfully.</p>
|
<p>Worktype successfully updated.</p>
|
||||||
|
{!!worktypeRequestSuccess &&
|
||||||
|
<Redirect to="/user/profile/client/worktypes" />}
|
||||||
</Message>
|
</Message>
|
||||||
<Form.Button>Update Worktype</Form.Button>
|
<Form.Button>Update Worktype</Form.Button>
|
||||||
</Form>
|
</Form>
|
115
src/components/Worktype/Worktypes.jsx
Normal file
115
src/components/Worktype/Worktypes.jsx
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
import React, { Component } from "react";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { Redirect, Link } from "react-router-dom";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Container,
|
||||||
|
Header,
|
||||||
|
Label,
|
||||||
|
Popup,
|
||||||
|
Segment
|
||||||
|
} from "semantic-ui-react";
|
||||||
|
|
||||||
|
import { deleteWorktypeRequest } from "../../actions/worktype/saga.actions";
|
||||||
|
|
||||||
|
class Worktypes extends Component {
|
||||||
|
deleteWorkType = uuid => {
|
||||||
|
this.props.dispatch(deleteWorktypeRequest(uuid));
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { selfUser } = this.props;
|
||||||
|
if (selfUser.client) {
|
||||||
|
return (
|
||||||
|
<WorktypesView
|
||||||
|
user={selfUser}
|
||||||
|
deleteWorkType={this.deleteWorkType}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return <Redirect to="/" />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapStateToProps(state) {
|
||||||
|
return { selfUser: state.user.selfUser };
|
||||||
|
}
|
||||||
|
|
||||||
|
const WorktypesView = ({ user, deleteWorkType, worktypeSuccess }) => (
|
||||||
|
<Container>
|
||||||
|
<Header>Worktypes</Header>
|
||||||
|
<Segment>
|
||||||
|
<Button
|
||||||
|
basic
|
||||||
|
color="green"
|
||||||
|
size="small"
|
||||||
|
as={Link}
|
||||||
|
to="/user/profile/client/create-worktype"
|
||||||
|
>
|
||||||
|
Create Worktype
|
||||||
|
</Button>
|
||||||
|
</Segment>
|
||||||
|
{(user.client.work_types || []).filter(worktype => !worktype.deleted)
|
||||||
|
.length > 0 &&
|
||||||
|
<Card.Group>
|
||||||
|
{user.client.work_types
|
||||||
|
.filter(worktype => !worktype.deleted)
|
||||||
|
.map((worktype, index) => (
|
||||||
|
<Card key={index}>
|
||||||
|
<Card.Content>
|
||||||
|
<Card.Header as="h4">
|
||||||
|
<Label
|
||||||
|
circular
|
||||||
|
empty
|
||||||
|
style={{
|
||||||
|
backgroundColor: worktype.color,
|
||||||
|
borderColor: worktype.color
|
||||||
|
}}
|
||||||
|
/>{" " + worktype.label}
|
||||||
|
</Card.Header>
|
||||||
|
<Card.Meta>
|
||||||
|
Worktype
|
||||||
|
</Card.Meta>
|
||||||
|
</Card.Content>
|
||||||
|
<Card.Content extra>
|
||||||
|
<Button.Group>
|
||||||
|
<Button
|
||||||
|
basic
|
||||||
|
color="yellow"
|
||||||
|
size="small"
|
||||||
|
as={Link}
|
||||||
|
to={`/user/profile/client/update-worktype/${worktype.uuid}`}
|
||||||
|
>
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
<Popup
|
||||||
|
content={
|
||||||
|
<div>
|
||||||
|
Are you sure you want to delete this work type?<br />
|
||||||
|
<Button
|
||||||
|
basic
|
||||||
|
color="red"
|
||||||
|
size="small"
|
||||||
|
onClick={() => deleteWorkType(worktype.uuid)}
|
||||||
|
>
|
||||||
|
Confirm Deletion
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
trigger={
|
||||||
|
<Button basic color="red" size="small">Delete</Button>
|
||||||
|
}
|
||||||
|
on="click"
|
||||||
|
position="top right"
|
||||||
|
/>
|
||||||
|
</Button.Group>
|
||||||
|
</Card.Content>
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</Card.Group>}
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(Worktypes);
|
Loading…
Reference in New Issue
Block a user