Added vehicle and owner pages/routes.

This commit is contained in:
Patrick Fic
2020-02-07 10:54:08 -08:00
parent b86586241a
commit b070b0918c
20 changed files with 316 additions and 35 deletions

View File

@@ -1,6 +1,34 @@
import React from "react";
import React, { useEffect } from "react";
import ManagePage from "./manage.page";
import { useQuery } from "react-apollo";
import { QUERY_BODYSHOP } from "../../graphql/bodyshop.queries";
import { setBodyshop } from "../../redux/user/user.actions";
import { connect } from "react-redux";
import { notification } from "antd";
import { useTranslation } from "react-i18next";
export default function ManagePageContainer() {
return <ManagePage />;
}
const mapDispatchToProps = dispatch => ({
setBodyshop: bs => dispatch(setBodyshop(bs))
});
export default connect(
null,
mapDispatchToProps
)(function ManagePageContainer({ match, setBodyshop }) {
const { error, data } = useQuery(QUERY_BODYSHOP, {
fetchPolicy: "network-only"
});
const { t } = useTranslation();
if (error) {
notification["error"]({ message: t("bodyshop.errors.loading") });
}
useEffect(() => {
if (data) setBodyshop(data.bodyshops[0]);
return () => {
//
};
}, [data]);
return <ManagePage match={match} />;
});

View File

@@ -1,6 +1,6 @@
import { BackTop, Layout, notification } from "antd";
import React, { lazy, Suspense, useEffect } from "react";
import { useQuery } from "react-apollo";
import { useTranslation } from "react-i18next";
//This page will handle all routing for the entire application.
import { connect } from "react-redux";
@@ -10,7 +10,6 @@ import FooterComponent from "../../components/footer/footer.component";
//Component Imports
import HeaderContainer from "../../components/header/header.container";
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
import { QUERY_BODYSHOP } from "../../graphql/bodyshop.queries";
//const WhiteBoardPage = lazy(() => import("../white-board/white-board.page"));
import { setBodyshop } from "../../redux/user/user.actions";
import "./manage.page.styles.scss";
@@ -35,29 +34,21 @@ const ChatWindowContainer = lazy(() =>
const ScheduleContainer = lazy(() =>
import("../schedule/schedule.page.container")
);
const VehiclesContainer = lazy(() =>
import("../vehicles/vehicles.page.container")
);
const VehiclesDetailContainer = lazy(() =>
import("../vehicles-detail/vehicles-detail.page.container")
);
const OwnersContainer = lazy(() => import("../owners/owners.page.container"));
const OwnersDetailContainer = lazy(() =>
import("../owners-detail/owners-detail.page.container")
);
const { Header, Content, Footer } = Layout;
const mapDispatchToProps = dispatch => ({
setBodyshop: bs => dispatch(setBodyshop(bs))
});
export default connect(
null,
mapDispatchToProps
)(function Manage({ match, setBodyshop }) {
export default function Manage({ match }) {
const { t } = useTranslation();
const { error, data } = useQuery(QUERY_BODYSHOP, {
fetchPolicy: "network-only"
});
if (error) {
notification["error"]({ message: t("bodyshop.errors.loading") });
}
if (data) {
setBodyshop(data.bodyshops[0]);
}
useEffect(() => {
document.title = t("titles.app");
}, [t]);
@@ -96,7 +87,26 @@ export default connect(
path={`${match.path}/profile`}
component={ProfilePage}
/>
<Route
exact
path={`${match.path}/vehicles`}
component={VehiclesContainer}
/>
<Route
exact
path={`${match.path}/vehicles/:vehId`}
component={VehiclesDetailContainer}
/>
<Route
exact
path={`${match.path}/owners`}
component={OwnersContainer}
/>
<Route
exact
path={`${match.path}/owners/:ownerId`}
component={OwnersDetailContainer}
/>
<Route
exact
path={`${match.path}/schedule`}
@@ -118,4 +128,4 @@ export default connect(
<BackTop />
</Layout>
);
});
}

View File

@@ -0,0 +1,5 @@
import React from "react";
export default function OwnersDetailComponent() {
return <div>Owner Detail</div>;
}

View File

@@ -0,0 +1,8 @@
import React from "react";
import OwnersDetailComponent from "./owners-detail.page.component";
export default function OwnersDetailContainer({ match }) {
const { ownerId } = match.params;
console.log("ownerId", ownerId);
return <OwnersDetailComponent />;
}

View File

@@ -0,0 +1,9 @@
import React from 'react'
export default function OwnersPageComponent() {
return (
<div>
Owners Page
</div>
)
}

View File

@@ -0,0 +1,8 @@
import React from 'react'
import OwnersPageComponent from './owners.page.component'
export default function OwnersPageContainer() {
return (
<OwnersPageComponent />
)
}

View File

@@ -0,0 +1,9 @@
import React from "react";
export default function VehicleDetailComponent({ vehicle }) {
return (
<div>
Veh detail <span>{vehicle.v_vin}</span>
</div>
);
}

View File

@@ -0,0 +1,28 @@
import React from "react";
import VehicleDetailComponent from "./vehicles-detail.page.component";
import { useQuery } from "react-apollo";
import { QUERY_VEHICLE_BY_ID } from "../../graphql/vehicles.queries";
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
import AlertComponent from "../../components/alert/alert.component";
import { useTranslation } from "react-i18next";
export default function VehicleDetailContainer({ match }) {
const { vehId } = match.params;
const { t } = useTranslation();
const { loading, data, error, refetch } = useQuery(QUERY_VEHICLE_BY_ID, {
variables: { id: vehId },
fetchPolicy: "network-only"
});
if (loading) return <LoadingSpinner />;
if (error) return <AlertComponent message={error.message} type="error" />;
console.log("vehId", vehId);
if (data.vehicles[0])
return <VehicleDetailComponent vehicle={data.vehicles[0]} />;
else
return (
<AlertComponent message={t("vehicles.errors.noaccess")} type="error" />
);
}

View File

@@ -0,0 +1,9 @@
import React from 'react'
export default function VehiclesPageComponent() {
return (
<div>
Vehiculos
</div>
)
}

View File

@@ -0,0 +1,6 @@
import React from "react";
import VehiclesPageComponent from "./vehicles.page.component";
export default function VehiclesPageContainer() {
return <VehiclesPageComponent />;
}