diff --git a/services/web/src/actions/userActions.ts b/services/web/src/actions/userActions.ts
index 7403dc77..94c413fb 100644
--- a/services/web/src/actions/userActions.ts
+++ b/services/web/src/actions/userActions.ts
@@ -156,6 +156,13 @@ export const getVehicleServicesAction = ({ accessToken, VIN, callback, ...data }
};
};
+export const getServiceReportAction = ({ accessToken, reportId, callback, ...data }: ActionPayload & AccessTokenPayload) => {
+ return {
+ type: actionTypes.GET_SERVICE_REPORT,
+ payload: { accessToken, reportId, callback, ...data },
+ };
+};
+
export const changeEmailAction = ({ accessToken, callback, ...data }: ActionPayload & AccessTokenPayload) => {
return {
type: actionTypes.CHANGE_EMAIL,
diff --git a/services/web/src/components/layout/layout.tsx b/services/web/src/components/layout/layout.tsx
index 2df885a2..afc7c62f 100644
--- a/services/web/src/components/layout/layout.tsx
+++ b/services/web/src/components/layout/layout.tsx
@@ -40,11 +40,11 @@ import UnlockContainer from "../../containers/unlock/unlock";
import NewPostContainer from "../../containers/newPost/newPost";
import PostContainer from "../../containers/post/post";
import VehicleServiceDashboardContainer from "../../containers/vehicleServiceDashboard/vehicleServiceDashboard";
+import ServiceReportContiner from "../../containers/serviceReport/serviceReport";
import {
logOutUserAction,
validateAccessTokenAction,
} from "../../actions/userActions";
-import { validateAccessToken } from "../../sagas/userSaga";
import { isAccessTokenValid } from "../../utils";
const { Content } = Layout;
@@ -158,12 +158,19 @@ const StyledComp: React.FC = (props) => {
setWindowHeight(window.innerHeight);
}
+ const isLoggedIn = props.isLoggedIn;
+ const accessToken = props.accessToken;
+ const validateAccessToken = props.validateAccessToken;
+
useEffect(() => {
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
+ if (isLoggedIn) {
+ validateAccessToken({ accessToken: accessToken });
+ }
};
- }, []);
+ }, [isLoggedIn, validateAccessToken, accessToken]);
return (
@@ -295,6 +302,19 @@ const StyledComp: React.FC = (props) => {
/>
}
/>
+
+ }
+ />
= ({ services }) => {
return (
- <>
+
{services.map((service) => (
@@ -63,7 +63,7 @@ const MechanicDashboard: React.FC = ({ services }) => {
))}
- >
+
);
};
diff --git a/services/web/src/components/order/order.tsx b/services/web/src/components/order/order.tsx
index b2e27ae2..161faa8f 100644
--- a/services/web/src/components/order/order.tsx
+++ b/services/web/src/components/order/order.tsx
@@ -65,7 +65,7 @@ const Order: React.FC = ({ order }) => {
);
return (
-
+
= (props) => {
{/* If status is completed, show report link */}
- View Report
+ View Report
))}
- >
+
);
};
diff --git a/services/web/src/constants/APIConstant.ts b/services/web/src/constants/APIConstant.ts
index 507c1e0d..e30ee196 100644
--- a/services/web/src/constants/APIConstant.ts
+++ b/services/web/src/constants/APIConstant.ts
@@ -56,6 +56,7 @@ export const requestURLS: RequestURLSType = {
GET_PRODUCTS: "api/shop/products",
GET_MECHANIC_SERVICES: "api/mechanic/service_requests",
GET_VEHICLE_SERVICES: "api/merchant/service_requests/",
+ GET_SERVICE_REPORT: "api/mechanic/mechanic_report",
BUY_PRODUCT: "api/shop/orders",
GET_ORDERS: "api/shop/orders/all",
GET_ORDER_BY_ID: "api/shop/orders/",
diff --git a/services/web/src/constants/actionTypes.ts b/services/web/src/constants/actionTypes.ts
index a78353d1..10ea0434 100644
--- a/services/web/src/constants/actionTypes.ts
+++ b/services/web/src/constants/actionTypes.ts
@@ -34,6 +34,7 @@ const actionTypes = {
INVALID_SESSION: "INVALID_SESSION",
GET_MECHANIC_SERVICES: "GET_MECHANIC_SERVICES",
GET_VEHICLE_SERVICES: "GET_VEHICLE_SERVICES",
+ GET_SERVICE_REPORT: "GET_SERVICE_REPORT",
RESEND_MAIL: "RESEND_MAIL",
VERIFY_VEHICLE: "VERIFY_VEHICLE",
GET_VEHICLES: "GET_VEHICLES",
diff --git a/services/web/src/containers/mechanicDashboard/mechanicDashboard.tsx b/services/web/src/containers/mechanicDashboard/mechanicDashboard.tsx
index bcfbf87a..b31bf5c2 100644
--- a/services/web/src/containers/mechanicDashboard/mechanicDashboard.tsx
+++ b/services/web/src/containers/mechanicDashboard/mechanicDashboard.tsx
@@ -68,7 +68,6 @@ const MechanicDashboardContainer: React.FC = ({ accessToken, get
};
getServices({ accessToken, callback });
}, [accessToken, getServices]);
- const typedServices: Service[] = services;
return ;
};
diff --git a/services/web/src/containers/serviceReport/serviceReport.tsx b/services/web/src/containers/serviceReport/serviceReport.tsx
new file mode 100644
index 00000000..03656ff0
--- /dev/null
+++ b/services/web/src/containers/serviceReport/serviceReport.tsx
@@ -0,0 +1,92 @@
+/*
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import React, { useState, useEffect } from "react";
+
+import { connect, ConnectedProps } from "react-redux";
+import { Modal } from "antd";
+import { getServiceReportAction } from "../../actions/userActions";
+import ServiceReport from "../../components/serviceReport/serviceReport";
+import responseTypes from "../../constants/responseTypes";
+import { FAILURE_MESSAGE } from "../../constants/messages";
+
+interface RootState {
+ userReducer: {
+ accessToken: string;
+ };
+}
+
+interface Service {
+ id: string;
+ problem_details: string;
+ created_on: string;
+ vehicle: {
+ owner: {
+ email: string;
+ number: string;
+ };
+ id: string;
+ vin: string;
+ };
+ status: string;
+ mechanic: {
+ mechanic_code: string;
+ user: {
+ email: string;
+ number: string;
+ };
+ };
+}
+
+const mapStateToProps = (state: RootState) => ({
+ accessToken: state.userReducer.accessToken,
+});
+
+const mapDispatchToProps = {
+ getServiceReport: getServiceReportAction,
+};
+
+const connector = connect(mapStateToProps, mapDispatchToProps);
+
+type PropsFromRedux = ConnectedProps;
+
+const ServiceReportContainer: React.FC = ({ accessToken, getServiceReport }) => {
+ const [service, setService] = useState();
+ const urlParams = new URLSearchParams(window.location.search);
+ const reportId = urlParams.get("id");
+ console.log("reportId", reportId);
+
+ useEffect(() => {
+ const callback = (res: string, data: Service | string) => {
+ console.log("Callback", res, data);
+ if (res === responseTypes.SUCCESS) {
+ setService(data as Service);
+ } else {
+ Modal.error({
+ title: FAILURE_MESSAGE,
+ content: data as string,
+ });
+ }
+ };
+ getServiceReport({ accessToken, reportId, callback});
+ }, [accessToken, getServiceReport, reportId]);
+
+ // Ensure that the Service type in the component matches the one from the API
+ // Ensure that the Service type in the component matches the one from the API
+ // Ensure that the Service type in the component matches the one from the API
+ return ;
+};
+
+export default connector(ServiceReportContainer);
diff --git a/services/web/src/containers/vehicleServiceDashboard/vehicleServiceDashboard.tsx b/services/web/src/containers/vehicleServiceDashboard/vehicleServiceDashboard.tsx
index c77253fd..7cee18d6 100644
--- a/services/web/src/containers/vehicleServiceDashboard/vehicleServiceDashboard.tsx
+++ b/services/web/src/containers/vehicleServiceDashboard/vehicleServiceDashboard.tsx
@@ -21,7 +21,6 @@ import { getVehicleServicesAction } from "../../actions/userActions";
import VehicleServiceDashboard from "../../components/vehicleServiceDashboard/vehicleServiceDashboard";
import responseTypes from "../../constants/responseTypes";
import { FAILURE_MESSAGE } from "../../constants/messages";
-import { useParams } from "react-router-dom";
interface RootState {
userReducer: {
diff --git a/services/web/src/sagas/userSaga.ts b/services/web/src/sagas/userSaga.ts
index aaae00ea..3f23d818 100644
--- a/services/web/src/sagas/userSaga.ts
+++ b/services/web/src/sagas/userSaga.ts
@@ -30,10 +30,8 @@ import {
TOKEN_NOT_SENT,
EMAIL_CHANGED,
EMAIL_NOT_CHANGED,
- NO_SERVICES,
} from "../constants/messages";
import MyAction from "../types/action";
-import { getMechanicServices, getVehicleServices } from "./vehicleSaga";
interface Response {
ok: boolean;
@@ -465,6 +463,4 @@ export function* userActionWatcher() {
yield takeLatest(actionTypes.RESET_PASSWORD, resetPassword);
yield takeLatest(actionTypes.CHANGE_EMAIL, changeEmail);
yield takeLatest(actionTypes.VERIFY_TOKEN, verifyToken);
- yield takeLatest(actionTypes.GET_MECHANIC_SERVICES, getMechanicServices);
- yield takeLatest(actionTypes.GET_VEHICLE_SERVICES, getVehicleServices);
}
diff --git a/services/web/src/sagas/vehicleSaga.ts b/services/web/src/sagas/vehicleSaga.ts
index 887b7658..29a2c472 100644
--- a/services/web/src/sagas/vehicleSaga.ts
+++ b/services/web/src/sagas/vehicleSaga.ts
@@ -349,6 +349,7 @@ export function* getVehicleServices(action: MyAction): Generator
try {
yield put({ type: actionTypes.FETCHING_DATA });
const getUrl = APIService.WORKSHOP_SERVICE + requestURLS.GET_VEHICLE_SERVICES.replace("", VIN);
+ console.log("Get URL", getUrl);
const headers = {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
@@ -379,6 +380,45 @@ export function* getVehicleServices(action: MyAction): Generator
}
}
+/**
+ * Request for getting service report
+
+ * @payload {string} payload.accessToken - Access token of the user
+ * @payload {string} payload.reportId - Report id of the service
+ * @payload {Function} payload.callback - Callback method
+ */
+export function* getServiceReport(action: MyAction): Generator {
+ const { accessToken, reportId, callback } = action.payload;
+ let receivedResponse: Partial = {};
+ try {
+ yield put({ type: actionTypes.FETCHING_DATA });
+ const getUrl = APIService.WORKSHOP_SERVICE + requestURLS.GET_SERVICE_REPORT + "?report_id=" + reportId;
+ console.log("Get URL", getUrl);
+ const headers = {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${accessToken}`,
+ };
+
+ const responseJSON = yield fetch(getUrl, {
+ headers,
+ method: "GET",
+ }).then((response: Response) => {
+ receivedResponse = response;
+ return response.json();
+ });
+
+ if (!receivedResponse.ok) {
+ throw responseJSON;
+ }
+
+ yield put({ type: actionTypes.FETCHED_DATA, payload: responseJSON });
+ callback(responseTypes.SUCCESS, responseJSON);
+ } catch (e) {
+ yield put({ type: actionTypes.FETCHED_DATA, payload: receivedResponse });
+ callback(responseTypes.FAILURE, e);
+ }
+}
+
export function* vehicleActionWatcher(): Generator {
yield takeLatest(actionTypes.RESEND_MAIL, resendMail);
yield takeLatest(actionTypes.VERIFY_VEHICLE, verifyVehicle);
@@ -388,4 +428,5 @@ export function* vehicleActionWatcher(): Generator {
yield takeLatest(actionTypes.REFRESH_LOCATION, refreshLocation);
yield takeLatest(actionTypes.GET_MECHANIC_SERVICES, getMechanicServices);
yield takeLatest(actionTypes.GET_VEHICLE_SERVICES, getVehicleServices);
+ yield takeLatest(actionTypes.GET_SERVICE_REPORT, getServiceReport);
}