diff --git a/src/components/App.jsx b/src/components/App.jsx index 730f654..6c624e9 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -7,8 +7,9 @@ import Register from "./Auth/Register"; import ResetPassword from "./Auth/ResetPassword"; import Settings from "./Auth/Settings"; import VerifyEmail from "./Auth/VerifyEmail"; -import CreateWorkTypeForm from "./User/Client/CreateWorkTypeForm"; -import UpdateWorkTypeForm from "./User/Client/UpdateWorkTypeForm"; +import CreateWorkTypeForm from "./Worktype/CreateWorkTypeForm"; +import UpdateWorkTypeForm from "./Worktype/UpdateWorkTypeForm"; +import Worktypes from "./Worktype/Worktypes"; import CompleteRegistration from "./User/CompleteRegistration"; import EditProfile from "./User/EditProfile"; import Profile from "./User/Profile"; @@ -48,6 +49,10 @@ class App extends Component { path="/auth/reset-password/:uid/:token" component={ResetPassword} /> + ); } @@ -37,7 +38,7 @@ function mapStateToProps(state) { }; } -const NavbarView = ({ isAuthenticated, dispatchLogoutRequest }) => ( +const NavbarView = ({ isAuthenticated, dispatchLogoutRequest, selfUser }) => ( Caremyway @@ -61,6 +62,10 @@ const NavbarView = ({ isAuthenticated, dispatchLogoutRequest }) => ( My Profile + {selfUser.client && + + Work Types + } Settings diff --git a/src/components/User/Client/ClientProfile.jsx b/src/components/User/Client/ClientProfile.jsx index b1cdddc..fa4b7d0 100644 --- a/src/components/User/Client/ClientProfile.jsx +++ b/src/components/User/Client/ClientProfile.jsx @@ -1,20 +1,11 @@ import React, { Component } from "react"; import { connect } from "react-redux"; -import { Link } from "react-router-dom"; -import { Card, Button, Label } from "semantic-ui-react"; - -import { deleteWorktypeRequest } from "../../../actions/worktype/saga.actions"; +import { Card } from "semantic-ui-react"; class ClientProfile extends Component { - deleteWorkType = uuid => { - this.props.dispatch(deleteWorktypeRequest(uuid)); - }; - render() { const { selfUser } = this.props; - return ( - - ); + return ; } } @@ -22,72 +13,15 @@ function mapStateToProps(state) { return { ...state.user }; } -const ClientProfileView = ({ user, deleteWorkType }) => ( -
- - - Client Information - Business Number: {user.client.business_number} - - - - - - {(user.client.work_types || []).filter(worktype => !worktype.deleted) - .length > 0 && - - {user.client.work_types - .filter(worktype => !worktype.deleted) - .map((worktype, index) => ( - - - - - - Worktype - - - - - - - - - - ))} - } -
+const ClientProfileView = ({ user }) => ( + + + Client Information + {user.client && + user.client.business_number && + Business Number: {user.client.business_number}} + + ); export default connect(mapStateToProps)(ClientProfile); diff --git a/src/components/User/Profile.jsx b/src/components/User/Profile.jsx index 5bd0b39..23e8088 100644 --- a/src/components/User/Profile.jsx +++ b/src/components/User/Profile.jsx @@ -38,11 +38,13 @@ const ProfileView = ({ user }) => ( "User Registration Not Completed"} {user.first_name} {user.last_name} - - - Phone Number: {user.userinfo.phone_number} - - + {user.userinfo && + + {user.userinfo.phone_number && + + Phone Number: {user.userinfo.phone_number} + } + } diff --git a/src/components/User/Provider/ProviderProfile.jsx b/src/components/User/Provider/ProviderProfile.jsx index 318361d..146fac2 100644 --- a/src/components/User/Provider/ProviderProfile.jsx +++ b/src/components/User/Provider/ProviderProfile.jsx @@ -5,9 +5,7 @@ import { Card } from "semantic-ui-react"; class ProviderProfile extends Component { render() { const { selfUser } = this.props; - return ( - - ); + return ; } } @@ -20,7 +18,9 @@ const ProviderProfileView = ({ user }) => ( Provider Information - Social Insurance Number: {user.provider.sin} + {user.provider && + user.provider.sin && + Social Insurance Number: {user.provider.sin}} diff --git a/src/components/User/Client/CreateWorkTypeForm.jsx b/src/components/Worktype/CreateWorkTypeForm.jsx similarity index 84% rename from src/components/User/Client/CreateWorkTypeForm.jsx rename to src/components/Worktype/CreateWorkTypeForm.jsx index 281cece..c14c7af 100644 --- a/src/components/User/Client/CreateWorkTypeForm.jsx +++ b/src/components/Worktype/CreateWorkTypeForm.jsx @@ -1,6 +1,7 @@ import React, { Component } from "react"; import { GithubPicker } from "react-color"; import { connect } from "react-redux"; +import { Redirect } from "react-router-dom"; import { Container, Form, Header, Label, Message } from "semantic-ui-react"; import { @@ -8,12 +9,12 @@ import { clearWorktypeRequestSuccess, setFormWorktypeColor, setFormWorktypeLabel -} from "../../../actions/worktype/reducer.actions"; -import { createWorktypeRequest } from "../../../actions/worktype/saga.actions"; -import Error from "../../Shared/Error"; +} from "../../actions/worktype/reducer.actions"; +import { createWorktypeRequest } from "../../actions/worktype/saga.actions"; +import Error from "../Shared/Error"; class CreateWorkTypeForm extends Component { - componentWillUnmount = () => { + componentWillMount = () => { this.props.dispatch(clearWorktypeRequestError()); this.props.dispatch(clearWorktypeRequestSuccess()); this.props.dispatch(setFormWorktypeColor("")); @@ -40,9 +41,14 @@ class CreateWorkTypeForm extends Component { worktypeRequestError, worktypeRequestSuccess, label, - color + color, + selfUser } = this.props; + if (!selfUser.client) { + return ; + } + return ( Create Worktype successful! -

Set worktype successfully.

+

Worktype successfully created.

+ {!!worktypeRequestSuccess && }
Submit Worktype diff --git a/src/components/User/Client/UpdateWorkTypeForm.jsx b/src/components/Worktype/UpdateWorkTypeForm.jsx similarity index 81% rename from src/components/User/Client/UpdateWorkTypeForm.jsx rename to src/components/Worktype/UpdateWorkTypeForm.jsx index c4122bc..aa37352 100644 --- a/src/components/User/Client/UpdateWorkTypeForm.jsx +++ b/src/components/Worktype/UpdateWorkTypeForm.jsx @@ -1,26 +1,26 @@ import React, { Component } from "react"; import { GithubPicker } from "react-color"; import { connect } from "react-redux"; +import { Redirect } from "react-router-dom"; import { Container, Form, Header, Label, Message } from "semantic-ui-react"; import { - clearWorktypeRequestError, - clearWorktypeRequestSuccess, setFormWorktypeColor, setFormWorktypeLabel -} from "../../../actions/worktype/reducer.actions"; -import { updateWorktypeRequest, readWorktypeRequest } from "../../../actions/worktype/saga.actions"; -import Error from "../../Shared/Error"; +} from "../../actions/worktype/reducer.actions"; +import { + updateWorktypeRequest, + readWorktypeRequest +} from "../../actions/worktype/saga.actions"; +import Error from "../Shared/Error"; class UpdateWorkTypeForm extends Component { componentWillMount = () => { const uuid = this.props.match.params.uuid; this.props.dispatch(readWorktypeRequest(uuid)); - } + }; componentWillUnmount = () => { - this.props.dispatch(clearWorktypeRequestError()); - this.props.dispatch(clearWorktypeRequestSuccess()); this.props.dispatch(setFormWorktypeColor("")); this.props.dispatch(setFormWorktypeLabel("")); }; @@ -42,9 +42,14 @@ class UpdateWorkTypeForm extends Component { worktypeRequestSuccess, uuid, label, - color + color, + selfUser } = this.props; + if (!selfUser.client) { + return ; + } + return ( - + @@ -101,7 +106,9 @@ const UpdateWorkTypeFormView = ({ Update Worktype successful! -

Update worktype successfully.

+

Worktype successfully updated.

+ {!!worktypeRequestSuccess && + }
Update Worktype diff --git a/src/components/Worktype/Worktypes.jsx b/src/components/Worktype/Worktypes.jsx new file mode 100644 index 0000000..4fb0279 --- /dev/null +++ b/src/components/Worktype/Worktypes.jsx @@ -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 ( + + ); + } else { + return ; + } + } +} + +function mapStateToProps(state) { + return { selfUser: state.user.selfUser }; +} + +const WorktypesView = ({ user, deleteWorkType, worktypeSuccess }) => ( + +
Worktypes
+ + + + {(user.client.work_types || []).filter(worktype => !worktype.deleted) + .length > 0 && + + {user.client.work_types + .filter(worktype => !worktype.deleted) + .map((worktype, index) => ( + + + + + + Worktype + + + + + + + Are you sure you want to delete this work type?
+ + + } + trigger={ + + } + on="click" + position="top right" + /> +
+
+
+ ))} +
} +
+); + +export default connect(mapStateToProps)(Worktypes);