Added additional precuations for users that do not exist and verified auth access.

This commit is contained in:
Patrick Fic
2020-10-19 16:26:51 -07:00
parent 64f6d549d1
commit 0749404d59
10 changed files with 124 additions and 32 deletions

View File

@@ -0,0 +1,46 @@
import { DeleteFilled } from "@ant-design/icons";
import { useMutation } from "@apollo/client";
import { Button, message, Popconfirm } from "antd";
import React, { useState } from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { DELETE_JOB } from "../../../graphql/jobs.queries";
import { setSelectedJobId } from "../../../redux/application/application.actions";
const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser
});
const mapDispatchToProps = (dispatch) => ({
setSelectedJobId: (id) => dispatch(setSelectedJobId(id)),
});
export function DeleteJobAtom({ setSelectedJobId, jobId }) {
const [deleteJob] = useMutation(DELETE_JOB);
const [loading, setLoading] = useState(false);
const handleDelete = async () => {
setLoading(true);
const result = await deleteJob({
variables: { jobId: jobId },
});
if (result.errors) {
message.error(result.errors.toString());
} else {
message.success("Job deleted.");
setSelectedJobId(null);
}
setLoading(false);
};
return (
<div>
<Popconfirm
title="Are you sure you want to delete this job? This cannot be undone."
onConfirm={handleDelete}
>
<Button loading={loading}>
<DeleteFilled />
</Button>
</Popconfirm>
</div>
);
}
export default connect(mapStateToProps, mapDispatchToProps)(DeleteJobAtom);

View File

@@ -6,6 +6,7 @@ import { createStructuredSelector } from "reselect";
import { QUERY_JOB_BY_PK } from "../../../graphql/jobs.queries";
import { setSelectedJobTargetPc } from "../../../redux/application/application.actions";
import { selectSelectedJobId } from "../../../redux/application/application.selectors";
import { DeleteJobAtom } from "../../atoms/delete-job/delete-job.atom";
import ErrorResultAtom from "../../atoms/error-result/error-result.atom";
import JobsPartsGraphAtom from "../../atoms/jobs-parts-graph/jobs-parts-graph.atom";
import JobsDetailDescriptionMolecule from "../../molecules/jobs-detail-description/jobs-detail-description.molecule";
@@ -77,6 +78,7 @@ export function JobsDetailOrganism({ selectedJobId, setSelectedJobTargetPc }) {
loading={loading}
/>
</div>
<DeleteJobAtom jobId={data ? data.jobs_by_pk.id : null} />
</div>
);
}

View File

@@ -1,4 +1,4 @@
import { Col, Row, Tabs } from "antd";
import { Col, Row, Tabs, Grid } from "antd";
import React from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
@@ -10,10 +10,27 @@ const mapStateToProps = createStructuredSelector({});
const mapDispatchToProps = (dispatch) => ({});
export function JobsPage() {
const selectedBreakpoint = Object.entries(Grid.useBreakpoint())
.filter((screen) => !!screen[1])
.slice(-1)[0];
const bpoints = {
xs: { l: 12, r: 12 },
sm: { l: 10, r: 14 },
md: { l: 10, r: 14 },
lg: { l: 8, r: 16 },
xl: { l: 6, r: 18 },
xxl: { l: 5, r: 19 },
};
const selectedSpans = selectedBreakpoint
? bpoints[selectedBreakpoint[0]]
: { l: 18, r: 6 };
return (
<div style={{ height: "100%" }}>
<Row gutter={[16, 16]} style={{ height: "100%" }}>
<Col span={6} style={{ height: "100%" }}>
<Col span={selectedSpans.l} style={{ height: "100%" }}>
<Tabs defaultActiveKey="latest" style={{ height: "100%" }}>
<Tabs.TabPane key="latest" tab="Latest" style={{ height: "100%" }}>
<JobsListOrganism />
@@ -23,7 +40,7 @@ export function JobsPage() {
</Tabs.TabPane>
</Tabs>
</Col>
<Col span={18} style={{ height: "100%" }}>
<Col span={selectedSpans.r} style={{ height: "100%" }}>
<JobsDetailOrganism />
</Col>
</Row>

View File

@@ -6,14 +6,26 @@ import { createStructuredSelector } from "reselect";
import SiderMenuOrganism from "../../organisms/sider-menu/sider-menu.organism";
import Jobs from "../jobs/jobs.page";
import SettingsPage from "../settings/settings.page";
const mapStateToProps = createStructuredSelector({});
import { selectBodyshop } from "../../../redux/user/user.selectors";
import ErrorResultAtom from "../../atoms/error-result/error-result.atom";
const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop });
const mapDispatchToProps = (dispatch) => ({});
export function RoutesPage() {
export function RoutesPage({ bodyshop }) {
if (bodyshop === false)
return (
<ErrorResultAtom
title="No shop access"
errorMessage="You do not currently have access to any shop. Please reach out to technical support."
/>
);
return (
<Layout style={{ background: "#fff", height: "100vh" }} hasSider>
<Layout.Sider style={{ background: "#fff" }} collapsible>
<Layout.Sider
style={{ background: "#fff" }}
collapsible
defaultCollapsed="true"
>
<SiderMenuOrganism />
</Layout.Sider>
<Layout style={{ background: "#fff" }}>

View File

@@ -2,7 +2,6 @@ import { LockOutlined, UserOutlined } from "@ant-design/icons";
import { Alert, Button, Form, Input, Typography } from "antd";
import React from "react";
import { connect } from "react-redux";
import { Link } from "react-router-dom";
import { createStructuredSelector } from "reselect";
import ImEXOnlineLogo from "../../../assets/logo192.png";
import { emailSignInStart } from "../../../redux/user/user.actions";
@@ -58,9 +57,6 @@ export function SignInPage({ emailSignInStart, signInError, loginLoading }) {
Login
</Button>
</Form>
<Link to={"/resetpassword"}>
<Button>Reset Password</Button>
</Link>
</div>
);
}